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
My Answer:
To run the shell script on the server from a web page, you need to provide the full path to the shell script in the shell_exec function. Additionally, you need to make sure that the web server has the necessary permissions to execute the shell script.
Here's an updated version of your PHP code:
php
shell_exec("/home/user/public_html/backup_cccr.sh");
?>
Make sure to replace "backup_cccr.sh" with the actual name of your shell script file.
Also, make sure that the shell script file has the executable permission set. You can set the executable permission using the following command:
bash
chmod +x /home/user/public_html/backup_cccr.sh
After making these changes, try running the PHP script from the web page again. This should execute the shell script on the server and create the zip file as expected.
Rate this post
5 of 5 based on 9576 votesComments