I have 2 commands I want to run one after another and would like to create a script and add it to cron. My commands are:
wget http://browscap.org/stream?q=Full_PHP_BrowsCapINI -O /etc/php/7.2/mods-available/browscap.ini
service php7.2-fpm restart
Is it possible to have it download the file, wait till it completes then run the restart script?
Thanks for the help.
CodePudding user response:
To run the second command after your wget download completes, separate the two commands with the double ampersand &&
As a one-liner:
wget http://browscap.org/stream?q=Full_PHP_BrowsCapINI -O /etc/php/7.2/mods-available/browscap.ini && service php7.2-fpm restart
The command after the double ampersand &&
should only run if the first command (the wget download) successfully completes.
CodePudding user response:
Per the wget manual use the wait option when passing your download command (type man wget
from CLI to see more information):
wget -w seconds http://browscap.org/stream?q=Full_PHP_BrowsCapINI -O /etc/php/7.2/mods-available/browscap.ini
service php7.2-fpm restart
or
wget --wait=seconds http://browscap.org/stream?q=Full_PHP_BrowsCapINI -O /etc/php/7.2/mods-available/browscap.ini
service php7.2-fpm restart
This will force the script to wait the specified number of seconds before proceeding with the service restart command.