Operating System - HP-UX
1834461 Members
2797 Online
110067 Solutions
New Discussion

Scripts need hourly augment.

 
SOLVED
Go to solution
Saraswathy_1
Advisor

Scripts need hourly augment.

My script need hour as an augument.

For example:- If I want to check 3 AM log details I execute the script like below:

./oom_moni.sh 3

I want to execute this every hour so Iam scheduling through cron job on hourly basis.

Problem is how can I pass hourly augument to my script.
Please advice in this matter
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: Scripts need hourly augment.

Have your script check the hour of the day using the date command:

# date +'%H'
06


Pete

Pete
Saraswathy_1
Advisor

Re: Scripts need hourly augment.

Thanks Pete,

The problem now is

If Iam executing script at 4 AM I should give augument as 3. (Which means Before number I should give)
Pete Randall
Outstanding Contributor

Re: Scripts need hourly augment.

The obvious answer would be to set your cron job up to run at 3:59, rather than 4:00.


Pete

Pete
Peter Godron
Honored Contributor

Re: Scripts need hourly augment.

Hi,
if you do have to run the script after 3:59 you could look into the TZ parameter.

In the UK:
$ date +'%Y%m%d%H%M'
200605261237
$ TZ=BST date +'%Y%m%d%H%M'
200605261137
or for your case:
$ date +'%H'
12
$ TZ=BST date +'%H'
11
James R. Ferguson
Acclaimed Contributor

Re: Scripts need hourly augment.

Hi:

If you want to deduct an hour from your current runtime, I would use a Perl snippet like:

# perl -le '$t=(localtime(time()-3600)) [2];print $t'

Perl handles time/date in epoch seconds, so 3600 is the equivalent of one-hour.

Regards!

...JRF...
RAC_1
Honored Contributor
Solution

Re: Scripts need hourly augment.

get hour of the time with date '+%H' and do following to get required argumnets.

if [ "$(date '+%H'|cut -c1) = "0" ];then
hour=$(date '+%H'|cut -c2)
else
hour=$(date '+%H')
fi

then call your script.
your_script ${hour}
There is no substitute to HARDWORK