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.
Related
I am trying to implement simple backup feature of some directories (mainly directories in /etc) which is handled by laravel. Basically I store .tar archives containing specific directory files.
This is a command used to create a backup archive of a single directory:
shell_exec("cd {$backupPath} && tar -cf {$dirName}.tar -P {$fullPathToDir}")
This is a command to restore directory from a backup archive:
shell_exec("cd / && sudo tar -xf {$backupPath . $dirName} --recursive-unlink --unlink-first")
For test reasons I let http user run sudo tar, however my initial idea was to create a bash script that will handle that, and add it to sudoers. Running command or shell script gives same errors.
The problem is if I run it through php I get errors like this:
Cannot unlink: Read-only file system
But, if i run it from command line, it works:
su http -s /bin/bash -c "cd / && sudo tar -xf {$backupPath . $dirName} --recursive-unlink --unlink-first"
Running this both on full archlinux system and archlinux docker container gives me same results. I would appreciate any kind of help.
So issue was with systemd unit for php-fpm 7.4, where ProtectSystem was set to true, after commenting it out, everything worked as expected.
sed -i 's:ProtectSystem=full:#ProtectSystem=full:' /usr/lib/systemd/system/php-fpm7.service
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 run a php file from shell script file or terminal in open-wrt platform. I have executed php files in crontab and those are running perfectly. i need to run a php file without putting it into crontab.I am trying it with the following command
chmod 777 /www/api/*
cd /www/api
php myphp.php
but it showing -ash: php: not found
I have also try it putting the following command on top of the script
#!/usr/bin/php
but it is not working. i could not figure out the problem!!!
You must install php-cli package, after you can run the script by
php-cli script.php
I would like to perform some grunt task by running command from php exec function.
I've already:
Install grunt globally: npm -g install grunt-cli
Setup apache and windows to allow running CLI from php (I use
wampserver)
I ran this script from php:
<?php
exec('grunt --gruntfile Gruntfile.js');`
And I found in apache log that grunt command is not found whereas I can run this command from CLI and grunt is in my env path.
So I've decided to create a batch file that contains that script and launch the batch instead of the grunt command directly.
<?php
exec ('gruntTask.bat'); // I know that it can execute script because I can
// create folder if I put mkdir command in gruntTask.bat`
gruntTask.bat contains:
grunt --gruntfile Gruntfile.js
But why it couldn't execute this script? Have I missed something?
Need helps guys,
Regards,
I have a website that needs to build a debian package and move it into a different directory for people to download. I have been able to do this using Linux and bash files to compress and build a Packages file with dpkg. Here's the bash script
#!/bin/bash
echo Enter app name
read NAME
cd /home/stumpx/cydia/apps
dpkg -b $NAME
cp /home/stumpx/cydia/apps/$NAME.deb /home/stumpx/cydia/upload/deb/$NAME.deb
cd /home/stumpx/cydia/upload
dpkg-scanpackages -m . /dev/null >Packages
bzip2 /home/stumpx/cydia/upload/Packages -f -k
It would be nice I guess to make .bz2 files.
You forgot your question. But I'll answer it regardless. Use exec() to invoke your bash script.
Basically you need to execute system commands. This is done via exec() in php. So you will have to write a bash script that does it all ( build package, compress and move it ) and execute it using php