Operating System - HP-UX
1835516 Members
3297 Online
110078 Solutions
New Discussion

Re: Script not to run on Saturday and Sunday

 
PSS SYS ADMIN
Super Advisor

Script not to run on Saturday and Sunday

Hi everyone,
I want to put on the beginning on a script a "if - then" cicle that check if the day is Saturday or Sunday. If it's true the stop the script.
Can you help me please?

Regards...
PSS
11 REPLIES 11
Ramkumar Devanathan
Honored Contributor

Re: Script not to run on Saturday and Sunday

if [[ `date +%A` = 'Sunday' || `date +%A` = 'Saturday' ]]; then
echo "It is a holiday... laze around..."
exit 1
fi

HTH.

- ramd.
HPE Software Rocks!
T G Manikandan
Honored Contributor

Re: Script not to run on Saturday and Sunday

m=`date|awk -F " " '{print $1}'`
if [ $m = "Wed" -o $m = "Fri" ]
then
echo holiday
else
echo working
fi
T G Manikandan
Honored Contributor

Re: Script not to run on Saturday and Sunday

This should be Sat and Sun in the script above


if [ $m = "Sat" -o $m = "Sun" ]
Leif Halvarsson_2
Honored Contributor

Re: Script not to run on Saturday and Sunday

Hi,
Why not use cron (crontab):

0 0 * * 1,2,3,4,5
John Poff
Honored Contributor

Re: Script not to run on Saturday and Sunday

Hi,

Here is a snippet of code that I use in a script which only ejects a DDS tape during the weekday after a tar backup:

#
# Eject the DDS tapes on weekdays
#
let TODAY=$(date +%u)
if ((TODAY < 6))
then
mt offl
fi


JP
John Meissner
Esteemed Contributor

Re: Script not to run on Saturday and Sunday

day=$(date +%A)
if [ $date = Saturday ] || [ $date = Sunday ]
then
exit 1
fi
#rest of your script
All paths lead to destiny
Ramkumar Devanathan
Honored Contributor

Re: Script not to run on Saturday and Sunday

John

that should be $day rather than $date, eh!

In any case, is PSS looking here at all????

- ramd.
HPE Software Rocks!
John Meissner
Esteemed Contributor

Re: Script not to run on Saturday and Sunday

But I also thing that this is the messy way to do it.... I agree with Leif that this should be scheduled with Cron
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: Script not to run on Saturday and Sunday

Ramkumar - thanks.... typ-o's .... good thing I didn't type rm :)
All paths lead to destiny
Marco Santerre
Honored Contributor

Re: Script not to run on Saturday and Sunday

I also agree wholeheartily that you should do this via cron.
Cooperation is doing with a smile what you have to do anyhow.
Dario_1
Trusted Contributor

Re: Script not to run on Saturday and Sunday

Hi!

Just like Leif mentioned, I will use crontab.

Regards,

DR