Executing rsync shell command from php file on web browser - php

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

Related

shell script on server falis when run from web page

If I ssh to server and cd public_html and run the shell script (below) it works fine.
One second thought, it would be easier to just setup a crontab on the server and have it run every day.
But if I run it from the web page outlined below, the zip file 'chessclub.zip' is not created or synced. The bash script is located on the server at 'home/user/public_html/ but it won't be found and executed. How can I get the bash script to execute on the server, not locally?
HTML
<button onclick = 'getZIP.php;'>ZIP IT</button>
PHP 'getZIP.php'
<?php
shell_exec("/home/user/public_html/backup_cccr");
?>
SHELL SCRIPT ON SERVER ("backup_cccr")
#!/bin/bash
zip -r -9 -FS chessclub.zip * -x chessclub.zip
Best idea was to scrap the php zip functions for bash zip functions because bash function are better: (backup_cccr)
#!/bin/bash
zip -r -9 -FS chessclub.zip public_html/* -x 'public_html/chessclub.zip'
cp chessclub.zip public_html/
Copying the updated chessclub.zip to public_html means the file is accessible from a web browser
I used a daily cron job to automatically create a backup. Easy to do.

Magallanes deploy unable to connect via ssh key

I am trying to deploy a Symfony2 PHP project on Ubuntu 15.10 with MagePHP, but it always asks me for the SSH users password when executing:
sudo php vendor/andres-montanez/magallanes/bin/mage deploy to:staging
When checking the log I can see it stops at this command:
ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ssh-user#my-domain.com "sh -c \"mkdir -p /customers/489176_10999/websites/my_company/symfony/staging/releases/20160902094526\""
Executing this command by itself works fine (so the server accepts the ssh key), but from within the context of the deployment script it doesn't.
I am quite puzzled by this, since both commands are run from the same directory. Any ideas how I can make this work?
try running the deploy with sudo.
Regards!
Since the file has been located under /var/www the ssh-agent had no access to the key files, since they were stored under the user directory. Moving the entire project inside the user directory fixed this issue.

Running SQLCMD from bat file loops infinitely

I have the following SQLCMD which connects to a remote database executes a query ands saves it as a csv file.
sqlcmd -S tcp:0.0.0.0,1433 -U user -P pass -d mydb -W -w 999 -s "," -Q "SELECT * FROM dbo.CSVData" -o "C:\wamp\sqlcmd.csv"
This works fine when i run it manually from command prompt.
I need to run the sqlcmd command from php and i have tried several execution commands in php but none works. The only option is using .bat files and call them through php but when i do so the sqlcmd command runs continuously (for several hundred times) and quits. I have tried using /wait and exit but this makes it worse by opening hundreds and hundreds of command prompt windows and it freezes the system. Below is the code i tried. Please let me know what i am doing wrong. Thanks.
#echo off
echo Running sqlcmd
start /wait sqlcmd -S tcp:0.0.0.0,1433 -U user -P pass -d mydb -W -w 999 -s "," -Q "SELECT * FROM dbo.CSVData" -o "C:\wamp\sqlcmd.csv"
:exit
I found what the issue was. I named the .bat file as sqlcmd.bat and that caused the program to run infinitely. I renamed the .bat file and it is working perfectly. A stupid mistake. My bad.

IIS blocking LFTP command

I'm trying to execute a LFTP command using the system() PHP method in a IIS 7.0 site.
$command = 'cmd /c lftp -c "open -u name,password -p 22 sftp://server.mylife.com ; cd test/portal/template ; put /cygdrive/c/inetpub/uploads/cata/exports/tpl_1421946484/cata.csv;"';
system($command);
I put it in a PHP file.
If if run it directly by the command line php sendFile.php it works fine.
But if I access this same php file throught a IIS 7.0 website, I got nothing and no error.
I can't understand where it comes from...!
Any help ?
Have you checked whether this is a permissions problem? Is it that the account under which IIS hosts the website might not have access to the /cygdrive/c/inetpub/uploads/cata/exports/tpl_1421946484/cata.csv file?

Running a bash file through php doesn't work but running it in PuTTY does

I have this php code:
$output = shell_exec("sh /backups/turnon.sh");
echo "<pre>$output</pre>";
It is in a file that is 0777 file permissions.
This is the contents of the .sh file. It also has 0777:
#!/bin/bash
sudo -u root screen -S ftb -X stuff 'java -Xms2048m -Xmx2048m -jar mcpc.jar
'
The screen ftb already exists and running the bash file through putty using /backups/turnon.sh. What am I doing wrong?
I assume sudo requires you to type in a password to launch the screen command, unless you've configured it to do otherwise.
There is no interactive terminal (tty), for you to type your password, when running PHP's shell_exec() function.

Categories