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/ line 5: ((: 059: value too great for base (error token is "059")
/root/servrs/ 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.


tm=$(date +%k%M)

if (( $tm < 500 )) || (( $tm > 530 )) ; then

    okfname=$(date +%F)
    freeze=$(/usr/bin/perl /root/servrs/
    wst=$(/usr/bin/curl --connect-timeout 15 -s --head "" | /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
      echo "Restarted because fail on $curdate" >> /root/servrs/fail_state
        echo "OK and HTTP $wst on $curdate" >> /root/servrs/ok_state_$okfname
Who is Participating?
You can either alter the way the value is assign by preventing the value from having a leading 0 or alter the if statement to work without regard to the value set in tm with or without a leading 0
test converts treats the value the same way whether it has a leading 0 or not.
The condition -lt (less then) -gt (greater than) set the parameters to be treated as numbers.

Either replace the
tm=$(date +%k%M) with tm=$(date +%k%M | sed "s/^ 0//g" )
or replace
if (( $tm < 500 )) || (( $tm > 530 )) ; then with  if ( test "$tm" -lt "500" -o "$tm" -gt "530"  ) ; then

can you post the cron entry you have?
try using /bin/sh

*/6 * * * * /bin/sh /path/to/the/above/

The error you have only happens if the script is executed using anything but /bin/sh.
justin33234Author Commented:
00   2 * * * /root/servrs/

is what shows up in crontab
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Garry GlendownConsulting and Network/Security SpecialistCommented:
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 ...
Garry GlendownConsulting and Network/Security SpecialistCommented:
P.S. - this might fix it ...
tm=$(date +%k%M | sed "s/^ 0//g" )

Open in new window

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
justin33234Author Commented:
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 ?

Garry GlendownConsulting and Network/Security SpecialistCommented:
Using the numerical comparison "<" or ">" causes the shell script to look at your variable as a number. If you have a number that begins with a "0", it's interpretet as octal ... so comparisons will not end up as intended:

if ((010<9)) ; then echo "first arg smaller than 9" ; fi

Open in new window

=> This does not compare 10 to 9, but 010 Base 8 to 9, so 8 < 9 !
justin33234Author Commented:
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.
Garry GlendownConsulting and Network/Security SpecialistCommented:
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
justin33234Author Commented:
Oh! Now it makes sense.

I put in the change, it's running tonight *crosses fingers*
justin33234Author Commented:
it worked! thanks guy!!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.