shell-exec

How to set $PATH for php exec or shell_exec

一个人想着一个人 提交于 2019-12-23 10:01:27
问题 I have set the PATH to run ant and it is working on putty but on php exec it is returning sh ant command not found i have tried to set PATH by export PATH=/usr/ant/bin 回答1: Call putenv before exec: putenv('PATH=/usr/ant/bin'); 回答2: Environment variables are set in the context of a user session. If you want to set the variable for the PHP user you should check what user apache runs under (typically apache), and add export PATH=/usr/ant/bin to /home/apache/.bashrc So that the path is set for

No access to /dev/mem. Try running as root on Raspberry Pi

冷暖自知 提交于 2019-12-22 17:48:56
问题 I am a Noob with the raspberry pi. I have it all setup and I am trying to run a file via the browser using shell_exec . Here is the content of the python file: #! /usr/bin/python import time import RPi.GPIO as GPIO PIN_17 = 17 # Define LED colour and their GPIO pin GPIO.setmode(GPIO.BCM) GPIO.setup(PIN_17, GPIO.OUT) # Setup GPIO pin GPIO.output(PIN_17, True) #Turn on time.sleep (1) #Wait GPIO.output(PIN_17, False) #Turn off GPIO.cleanup() #Useful to clear the board I have the file in the

execute shell script from ruby on rails with passing variable

放肆的年华 提交于 2019-12-22 01:05:03
问题 Im trying to integrate prosody xmpp server with my rails application. I need to create some users in a database upon registration so I can lateron use them inside the prosody server. What would be the best way to run shell commands in rails and output any info logs ? prosodyctl adduser User.username 回答1: i usually run with system(command) ,or with backtick command ,other way you can refer here 来源: https://stackoverflow.com/questions/12299231/execute-shell-script-from-ruby-on-rails-with

PHP running multiple scripts concurrently

五迷三道 提交于 2019-12-21 17:25:57
问题 I have an array with object server like this: Array ( [0]( ( [id] => 1 [version] => 1 [server_addr] => 192.168.5.210 [server_name] => server1 ) ) [1]( ( [id] => 2 [server_addr] => 192.168.5.211 [server_name] => server2 ) ) ) By running the code below, I'm able to get the desired output foreach ($model as $server) { $cpu_usage = shell_exec('sudo path/to/total_cpu_usage.sh '.$server->server_addr); $memory_usage = shell_exec('sudo path/to/total_memory_usage.sh '.$server->server_addr); $disk

I have two files, how should i compare these files using shell and awk script

≯℡__Kan透↙ 提交于 2019-12-20 07:28:54
问题 I have two files Content of file A paybackFile_537214-760887_000_20120801.xml paybackFile_354472-544899_000_20120801.xml paybackFile_62-11033_000_20120801.xml paybackFile_831669-837544_000_20120801.xml =========================================== Total file(s) - 4 =========================================== Content of file B 14/08/2012 12:36:01: MSG: File paybackFile_537214-760887_000_20120801.xml.gpg decrypted successfully. 13/08/2012 11:36:01: MSG: File paybackFile_62-11033_000_20120801.xml

php shell_exec touch redirect and adduser

僤鯓⒐⒋嵵緔 提交于 2019-12-20 03:21:28
问题 I am trying to ultimately use php's shell_exec function to create new Linux users. I am, however, running into problems even with the debugging. Here is my code <?PHP function adduser($username,$password,$server){ try{ //3 debug statements $output=shell_exec("pwd"); echo $output; shell_exec("touch test.txt"); //3 debug statements are requested by Christian echo '<pre>'; print_r(execute('pwd')); print_r(execute('touch test.txt')); //actuall code $output=shell_exec("ssh root@$server \"adduser

Using PHP to execute cmd commands

拟墨画扇 提交于 2019-12-17 19:36:11
问题 How do I properly execute commands in the command line using php? For example I'm using the command below in the command line to convert a docx file into a pdf file: pdfcreator.exe /PF"D:\Documents\sample.docx Now using PHP code I want to be able to execute the same command but nothing seems to be happening: <?php shell_exec('pdfcreator.exe /PF"D:\Documents\sample.docx"'); ?> Is this possible in PHP?If yes, how do I do it? 回答1: system("c:\\path\\to\\pdfcreator.exe /PF\"D:\\Documents\\sample

PHP - How to know if server allows shell_exec

旧巷老猫 提交于 2019-12-17 16:47:11
问题 On some servers, PHP is not allowed to run shell commands via shell_exec. How can I detect if current server allows running shell commands via PHP or not? How can I enable shell commands execution via PHP? 回答1: First check that it's callable and then that it's not disabled: is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec'); This general approach works for any built in function, so you can genericize it: function isEnabled($func) { return is_callable(

Security vulnerability with exec(), shell_exec(), curl_exec()

China☆狼群 提交于 2019-12-14 03:05:34
问题 Occasionally, I use exec(), shell_exec(), and curl_exec(). Below are typical uses. Assume that where ever I have a PHP variable in them (i.e. $html in the first one), there is a chance that the user has the ability to modify its content. What should I be concerned about from a security vulnerability perspective? Is escapeshellcmd() and escapeshellarg() the answer, and if so where should it be used? $cmd='echo "html + '.$html.'" | htmldoc --format pdf > '.$filename; $cmd='/usr/bin/convert '.

Calling gcc with shell_exec in php

不羁的心 提交于 2019-12-14 02:52:44
问题 <?php $output=shell_exec('gcc prog.c'); echo "$output"; ?> I'm trying execute a c program using php and have used shell_exec to call gcc to execute the program but it is giving no output but there is no error being showed . Can please someone correct the mistake Thank you in advance. 回答1: gcc is used to compile the c file. It doesn't 'run' the .c file. Try it from your command line. You will notice after running gcc prog.c you have a file named 'a.out'. a.out is the executable that is created