Coming from the solution on this post I have made a few changes to the original script but output is not like it should be. Below is the script as I have right now:
#!/bin/bash
add=$1
php=/usr/bin/php
hour=0
minute=0
update_time () {
(( minute += add ))
if (( minute >= 60 )) ; then
(( hour += minute / 60 ))
(( minute %= 60 ))
fi
if (( hour > 23 )) ; then
echo "Can't fit into a day!"
exit 1
fi
}
cd /var/sync
echo -e 'Display current crontabn---------------------------------------------------n'
(crontab -l)
echo -e 'Erasing current crontabn---------------------------------------------------n'
(crontab -r)
echo -e 'Generating new crontabn---------------------------------------------------n'
for dir in sync*/ ; do
if [[ -f "$dir"/sync.php ]] ; then
echo -e $minute $hour * * * "$php" /var/sync/run.sh "$dir" sync.php 'n'
(crontab -l ; echo "$minute $hour * * * "$php" /var/sync/run.sh "$dir" sync.php") | sort - | uniq - | crontab -
update_time
if [[ -f "$dir"/replicator/Replicator.php ]] ; then
echo -e $minute $hour * * * "$php" /var/sync/run.sh "$dir" Replicator.php 'n'
(crontab -l ; echo "$minute $hour * * * "$php" /var/sync/run.sh "$dir" Replicator.php") | sort - | uniq - | crontab -
fi
update_time
fi
done
echo -e 'Display current crontabn---------------------------------------------------n'
(crontab -l)
The current output for the script is:
0 0 * * * /usr/bin/php /var/sync/run.sh sync_bi/ sync.php
0 1 * * * /usr/bin/php /var/sync/run.sh sync_pfizer/ Replicator.php
20 0 * * * /usr/bin/php /var/sync/run.sh sync_bi/ Replicator.php
20 1 * * * /usr/bin/php /var/sync/run.sh sync_sandbox/ sync.php
40 0 * * * /usr/bin/php /var/sync/run.sh sync_pfizer/ sync.php
40 1 * * * /usr/bin/php /var/sync/run.sh sync_sandbox/ Replicator.php
When it should be:
0 0 * * * /usr/bin/php /var/sync/run.sh sync_bi/ Replicator.php
20 0 * * * /usr/bin/php /var/sync/run.sh sync_bi/ sync.php
40 1 * * * /usr/bin/php /var/sync/run.sh sync_pfizer/ Replicator.php
1 0 * * * /usr/bin/php /var/sync/run.sh sync_pfizer/ sync.php
20 1 * * * /usr/bin/php /var/sync/run.sh sync_sandbox/ Replicator.php
40 1 * * * /usr/bin/php /var/sync/run.sh sync_sandbox/ sync.php
Meaning first run the Replicator.php
script and after run the sync.php
script each one between 20 min starting at 00:00AM and the same should be repeat at 12:00PM, what is wrong on the code?
The idea behind that code is to write directly in crontab also show the result as output in the console some lines to run each task in the hour/minutes. That script above allow to do that but in some point if failing. As I said I took this from a previous answer I get in the post I told at the beginning of this post.