justin33234
asked on
cron script generating errors. possibly taking down the site.
Im not sure where this falls under so I hope I assigned it to the correct zone, heres the issue:
We have a dedicated server running a fully custom site that relies on several scripts that are used to update the site and deliver content (the site is fully automated) lately we've run into an issue where at a specific time every night, it seems to go down (system becomes unresponsive, etc)
the only error we can find is from one of the cron jobs that run:
this is the error:
/root/servrs/freezerestart .sh: line 5: ((: 059: value too great for base (error token is "059")
/root/servrs/freezerestart .sh: line 5: ((: 059: value too great for base (error token is "059")
it goes up from 009 up to that last one, then seems to crash.
here is the script: (the site has been omitted with ------)
can someone look at the script and let me know, if anything would be generating the error ?
the purpose of the script is if the site becomes unresponsive, it forces a restart of the site,
which is fine, but more often than not it never runs and the rig grinds to a halt, at exactly 5am est.
#!/bin/sh
tm=$(date +%k%M)
if (( $tm < 500 )) || (( $tm > 530 )) ; then
curdate=$(date)
okfname=$(date +%F)
freeze=$(/usr/bin/perl /root/servrs/socktest.pl)
wst=$(/usr/bin/curl --connect-timeout 15 -s --head "http://---------.org" | /usr/bin/perl -e 'my ($a) = <STDIN>; print $a = (split /\s+/, $a)[1]*1')
if (( $freeze == 1 )) || (( $wst == 500 )) || (( $wst == 0 )); then
pids=$(/usr/sbin/lsof /tmp/site.socket | /usr/bin/perl -e 'my @pids = map {((split /\s+/, $_)[1])} (<STDIN>); $, = "\n", print @pids[1..$#pids]');
su - siteuser -c "~/run_-----------_site"
for i in $pids; do
kill -9 $i
done
echo "Restarted because fail on $curdate" >> /root/servrs/fail_state
else
echo "OK and HTTP $wst on $curdate" >> /root/servrs/ok_state_$okf name
fi
fi
We have a dedicated server running a fully custom site that relies on several scripts that are used to update the site and deliver content (the site is fully automated) lately we've run into an issue where at a specific time every night, it seems to go down (system becomes unresponsive, etc)
the only error we can find is from one of the cron jobs that run:
this is the error:
/root/servrs/freezerestart
/root/servrs/freezerestart
it goes up from 009 up to that last one, then seems to crash.
here is the script: (the site has been omitted with ------)
can someone look at the script and let me know, if anything would be generating the error ?
the purpose of the script is if the site becomes unresponsive, it forces a restart of the site,
which is fine, but more often than not it never runs and the rig grinds to a halt, at exactly 5am est.
#!/bin/sh
tm=$(date +%k%M)
if (( $tm < 500 )) || (( $tm > 530 )) ; then
curdate=$(date)
okfname=$(date +%F)
freeze=$(/usr/bin/perl /root/servrs/socktest.pl)
wst=$(/usr/bin/curl --connect-timeout 15 -s --head "http://---------.org" | /usr/bin/perl -e 'my ($a) = <STDIN>; print $a = (split /\s+/, $a)[1]*1')
if (( $freeze == 1 )) || (( $wst == 500 )) || (( $wst == 0 )); then
pids=$(/usr/sbin/lsof /tmp/site.socket | /usr/bin/perl -e 'my @pids = map {((split /\s+/, $_)[1])} (<STDIN>); $, = "\n", print @pids[1..$#pids]');
su - siteuser -c "~/run_-----------_site"
for i in $pids; do
kill -9 $i
done
echo "Restarted because fail on $curdate" >> /root/servrs/fail_state
else
echo "OK and HTTP $wst on $curdate" >> /root/servrs/ok_state_$okf
fi
fi
ASKER
00 2 * * * /root/servrs/dailyrestart. sh
is what shows up in crontab
is what shows up in crontab
The leading "0" causes the shell to interpret $tm as an octal number, which of course causes the 8 and 9 to be a an illegal digit when you compare it to other numbers ...
P.S. - this might fix it ...
tm=$(date +%k%M | sed "s/^ 0//g" )
You could use test ([]) as an alternative
if ( [ "$tm" -lt "509" -o "$tm" -gt "530" ] ) ; then
if ( test "$tm" -lt "509" -o "$tm" -gt "530" ) ; then
if ( [ "$tm" -lt "509" -o "$tm" -gt "530" ] ) ; then
if ( test "$tm" -lt "509" -o "$tm" -gt "530" ) ; then
ASKER
so replace: if (( $tm < 500 )) || (( $tm > 530 )) ; then
with: tm=$(date +%k%M | sed "s/^ 0//g" )
sorry been ages since i've used a linux os, and even longer since i've done any scripting.
Garry, you mentioned the leading 0 is causing an illegal digit, can you clarify which you mean ?
thanks!
with: tm=$(date +%k%M | sed "s/^ 0//g" )
sorry been ages since i've used a linux os, and even longer since i've done any scripting.
Garry, you mentioned the leading 0 is causing an illegal digit, can you clarify which you mean ?
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey sorry guys had to go out of town for a week.
looking at the script i dont see any numbers that start with zero, so not sure how the issue is being caused by it.
sorry if its an obvious problem, just not familiar with this.
looking at the script i dont see any numbers that start with zero, so not sure how the issue is being caused by it.
sorry if its an obvious problem, just not familiar with this.
the date-command generates them!
%k is 0-23 hours
you can change that to %l which will represent the 1-12
but you would have to introduce another check dealing with pm to capture the 1-5pm window.
Another option is to preppend a number such that the condition will never have a leading 0
tm=1$(date +"%k%M" )
and modify the check to $tm <10500 || $tm > 10530
you can change that to %l which will represent the 1-12
but you would have to introduce another check dealing with pm to capture the 1-5pm window.
Another option is to preppend a number such that the condition will never have a leading 0
tm=1$(date +"%k%M" )
and modify the check to $tm <10500 || $tm > 10530
ASKER
Oh! Now it makes sense.
I put in the change, it's running tonight *crosses fingers*
I put in the change, it's running tonight *crosses fingers*
ASKER
it worked! thanks guy!!!!
try using /bin/sh cron_script.sh
*/6 * * * * /bin/sh /path/to/the/above/script.
The error you have only happens if the script is executed using anything but /bin/sh.