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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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 ...
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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 ?

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.