sorry for bad english..
i have php file like this:
<?php
exec(`sh /tmp/script.sh`);
echo "Work!";
?>
and this is the script:
#!/bin/bash
url="http://someweb.com/get.php?user=user&pass=pass";
wget -O /tmp/file.txt $url
sed -i 's/#Test_file/Ok_Test_file/' /tmp/file.txt
cp /tmp/file.txt /var/www/_client/personale/file.txt
Now when load file.php to the browser, the script works ,but only commands
wget and sed are performed , except cp which doesn't work..does not copy the file!
If i run the script to terminal manually (Debian 8) all cmd are executed...
Where is the problem?
Thanks.
Joele
PHP likely does not have permission to execute the command. Try using sudo to execute the command.
Related
I am trying to write a script in php to run the following bash script using apache2+php7
#!/bin/bash
#cd /home/cwc/http/www/html/admin/web/
nowfile=$(date +"%Y%m%d-%H%M%S")
nohup tcpdump -w $nowfile.pcap -i enp2s0 >> /dev/null 2>&1 &
Now I understand I might have to use full paths
The above code works with a non sudo user using bash because I added a user the the pcap group.
I'm trying to figure out why this will not work with php
<?php
$command = "/pathtoscript/tcpdmp.sh
shell_exec($command); //not working?
?>
Firstly, we wanna move the changes from one system to another system and for this, we have a shell script in synchfolders.sh file as follows
rsync -av --delete -e 'sshpass -p Wordpress#123 ssh -p 22' root#192.168.2.94:/var/www/html/prosync/wp-content/plugins/ /var/www/html/devsync/wp-content/plugins >> /var/www/html/devsync/wp-content/mysynclog.txt
and we want to execute this shell script in PHP file by shell_exec()
and while executing this PHP file from a browser other than rsync command, all are executing but the rsync is not executing. We have searched the stuff in SO and we got the link php exec() rsync ssh to remote server not working
as said here, we have tried the PHP file execution from the command line and works perfect but not through the browser. Why, Please let us know where we did a mistake. Thanks in advance
Enter the full path of rsync command:
/usr/bin/rsync -av --delete -e 'sshpass -p Wordpress#123 ssh -p 22' root#192.168.2.94:/var/www/html/prosync/wp-content/plugins/ /var/www/html/devsync/wp-content/plugins >> /var/www/html/devsync/wp-content/mysynclog.txt
I am trying to integrate a wget command I have written into a php script. The command recursively downloads every html/php file on a website (which is required functionality that I haven't found in file_get_contents()). I have tested the wget command in a terminal window, but when executing it using either exec() or shell_exec() nothing happens. I don't get any errors, or warnings.
Here is the command in question,
wget --recursive -m --domains oooff.com --page-requisites --html-extension --convert-links -R gif,jpg,pdf http://www.oooff.com/
I have tried simple wget commands (not as many parameters) from exec(), and shell_exec(), but they also don't work.
If wget isn't an option, I am open to using some other method of downloading a website in it's entirety.
My code that I have now is,
exec("wget google.com", $array);
Then when printing the array it is empty
I had to specify a path to wget. New command:
exec("/usr/local/bin/wget google.com", $array);
invoke wget with proper options
-q to remove it s information output
-O - to output the request response on stdout
php -r 'exec("wget -q -O - google.com", $array);var_dump($array);'
In our case wget didn't have enough permission to save wget'ed file in current dir. Solution:
$dir = __DIR__.'/777folder/';
exec("/usr/bin/wget -P ".$dir." --other-options");
where
-P, --directory-prefix=PREFIX save files to PREFIX/...
ps. we also added /usr/bin found with whereis wget but in our system it works fine without it
i'm really beginner with SH Scripts.
I found a small sh script that convert a php file with wget to html. I would like to do a small cronjob with it. But everytime i run that script i get the message (Translated) "Defect Interpreter" > File or folder not Found".
My script is only
#!/bin/bash
rm -rf header-wrapper.html && wget http://master.gnetwork.eu/header-wrapper.php -O header-wrapper.html -q
The error message tells you that your shebang is wrong (bash executable is not found at /bin/bash when cron job starts).
From your cron job, use bash explicitly when calling the script:
bash myscript.sh
instead of:
./myscript.sh
Also, do not make any assumptions on the working directory of the cron job. Change the directory in your bash script before doing anything else
#!/bin/bash
cd /my/desired/path && \
rm -rf header-wrapper.html && \
wget http://master.gnetwork.eu/header-wrapper.php -O header-wrapper.html -q
Try typing Bash in before the filename.
bash [File Name Here]
instead of
.[File Name Here]
Sorry if someone else already answered this.
when I run this command :
php -q /var/www/project/test.php
But it doesn't work unless I run this command :
cd /var/www/project/
Can you help me run this command witout executing CD ?
Fully qualify your mail.txt file. Change your php file to read:
<?php $fh=fopen('/var/www/project/mail.txt','w'); fwrite($fh,'Success'); fclose($fh); ?>