1828208 Members
2258 Online
109975 Solutions
New Discussion

Re: scripting help.

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

scripting help.

Hi everyone,

I am trying to create a script that checks the run time of a job from a file then works out whether another script should run. ie

script where date and times are:

LOG

monday 2200 - 0700
tuesday 0800 - 1700
wednesday 0800 - 1700
etc etc

BACKUP

monday 0800 - 0700
tuesday 0900 - 1700
wednesday 0800 - 1700
etc etc

so

i try running awk to search for BACKUP then check the date and get the time as a string to be tested against the current time.

but

i just cannot work it out,


please help.

Thanks

hello
4 REPLIES 4
Ninad_1
Honored Contributor

Re: scripting help.

You can do the following

todaysday=$(date +%A | tr -s [:upper:] [:lower:])
todaystime=$(date +%H%M)
awk '/BACKUP/,/ZZZ/' logfile | grep $todaysdate | head -1 | read logday starttime junk1 endtime
if [[ $todaystime -ge $starttime ]]
then
if [[ $todaystime -le $endtime ]]
then
echo Run script
fi
fi


Hope this is what your requirement is.
Please clarify if not.

Best luck.
Ninad
Ninad_1
Honored Contributor
Solution

Re: scripting help.

Sorry - forgot to check the day. heres the modofied one

todaysday=$(date +%A | tr -s [:upper:] [:lower:])
todaystime=$(date +%H%M)
awk '/BACKUP/,/ZZZ/' logfile | grep $todaysdate | head -1 | read logday starttime junk1 endtime
if [[ "$todaysday" = "$logday" ]]
then
if [[ $todaystime -ge $starttime ]]
then
if [[ $todaystime -le $endtime ]]
then
echo Run script
fi
fi
fi

Regards,
Ninad
James R. Ferguson
Acclaimed Contributor

Re: scripting help.

Hi:

You can use this to extract the line corresponding to the current day (name) in the stanza beginning with "BACKUP":

# perl -ne 'BEGIN{$d=substr(localtime,0,3)};$i++ if m/BACKUP/;print if $i && m/$d/i' filename

...If your file contained a line for today (a Thursday) in the "BACKUP" stanza, it would print that line. You can capture that output in a shell variable and parse the fields you want however you want.

Regards!

...JRF...
lawrenzo_1
Super Advisor

Re: scripting help.

thank you both for your suggestions, even though they both work I am using Ninad method as I am not familiar with perl.

cheers!


Lawrenz0
hello