I am using the SSH2 library in my PHP to execute a SH script on a remote server. When I run it manually on SSH, it works just fine. However, when I try to run it through PHP, the script starts, but never completes. (The script echos the size of two directories, and runs in a for loop echoing out the size until the two folders are the same size.). I have tried putting it in a screen, running with an ampersand to run in the background, disowned it, and more.
Here is the whole script:
echo "starting" > /var/www/html/$2.log
rep=`du -sk /home/repository_$1 | awk '{print $1}'`
dirsize=`du -sk /home/$2 | awk '{print $1}'`
while [ "$dirsize" -lt "$rep" ]; do
dirsize=`du -sk /home/$2 | awk '{print $1}'`
echo "New directory size: $dirsize."
echo "$dirsize\\$rep" > /var/www/html/$2.log
sleep 2;
done
echo "Loop Complete"
echo "done" > /var/www/html/$2.log
I have narrowed down the crash to the while loop. For some reason, that causes it to lock up. All code before it executes just fine. The script is being executed as root, and I have tried echoing out the variables from the while loop out to text files, so I know they are set and working properly.