If you want alternate Mondays, you need to pass two tests:-
Is it a Monday?
Is this an odd week of the year? (Or you may prefer to use the even weeks of course)
The first test can be checked easily with the value from date +%u or date +%A
For the other, use date +%W and test if it's odd like this:-
Code:
((odd_or_even=`date +%W`%2))
This will give the remainder so you can tell odd or even easily, then:-
Code:
if [ $odd_or_even -eq 0 ]
then
: # This is an even week
else
: # This is an odd week
fi
Schedule the job every day and these tests will handle your requirement. Of course, you have to consider how to run the script late if there has been an operational problem, perhaps with a FORCE flag.
You can therefore consolidate it all like this:-
Code:
if [ \( `date +%A` = Monday -a $((`date +%W`%2)) -eq 0 \) -o "$FORCE" = "Y" ]
then
: # This is an even week Monday or forced run
else
: # This is an odd week or not a Monday and not forced.
fi
I hope that this helps.
Robin
Liverpool/Blackburn
UK
I hope that this helps.
Last edited by rbatte1; 02-10-2014 at 06:22 AM..
Reason: Correcting comments
Your code looks like it would run the script every Monday, Wednesday, Friday, and Sunday.
**edit**
Actually I was not exploiting the fact that weeks have an odd number of days. I converted days to weeks. Then I depended on every other week number being odd. I see your point though. I can simplify my code by expoiting the odd number of days per week.
Code:
#! /bin/ksh
alias datecalc=./datecalc
year=$1
month=$2
day=$3
if [[ $(datecalc -D $year $month $day) = "Monday" ]] ; then
echo today is Monday
today=$(datecalc -j $year $month $day)
if ((today%2)) ; then
echo this is an odd Monday
else
echo this is an even Monday
fi
else
echo today is not Monday
fi
exit 0
And testing it...
Code:
$ ./monday2b 2014 2 3
today is Monday
this is an odd Monday
$ ./monday2b 2014 2 10
today is Monday
this is an even Monday
$ ./monday2b 2014 2 17
today is Monday
this is an odd Monday
$ ./monday2b 2014 2 24
today is Monday
this is an even Monday
I have reversed which Monday's are considered even between the two scripts but that was arbritrary anyway.
If i want to run on Friday's, i have to put Friday there rght,
I need to run the scripts on alterante fridays not on EVEN or ODD Fridays..
For eaxmple, for Jan , I have to run the script on 1/3, 1/17, 1/31 and 2/14 ,
If you run the script on Odd fridays , it will run on 1/3, 1/17, 1/31,2/7 not on 2/14.
---------- Post updated at 03:23 PM ---------- Previous update was at 03:22 PM ----------
If i want to run on Friday's, i have to put Friday there rght,
I need to run the scripts on alterante fridays not on EVEN or ODD Fridays..
For eaxmple, for Jan , I have to run the script on 1/3, 1/17, 1/31 and 2/14 ,
If you run the script on Odd fridays , it will run on 1/3, 1/17, 1/31,2/7 not on 2/14.
---------- Post updated at 03:26 PM ---------- Previous update was at 03:23 PM ----------
If i want to run on Friday's, i have to put Friday there rght,
I need to run the scripts on alterante fridays not on EVEN or ODD Fridays..
For eaxmple, for Jan , I have to run the script on 1/3, 1/17, 1/31 and 2/14 ,
If you run the script on Odd fridays , it will run on 1/3, 1/17, 1/31,2/7 not on 2/14.
alias datecalc=./datecalc
year=$1
month=$2
day=$3
if [[ $(datecalc -D $year $month $day) = "Tuesday" ]] ; then
echo today is Tuesday
today=$(datecalc -j $year $month $day)
if ((today%2)) ; then
echo this is an odd Friday
else
echo this is an even Friday
fi
else
echo today is not Tuesday
fi
exit 0
, Output says
Alternate_Friday.ksh[28]: ./datecalc: not found
Last edited by Perderabo; 02-11-2014 at 12:17 PM..
Linux System having all Perl, Python, PHP (and Ruby) installed
From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file
eg
eg
a Shell script run in a case statement call to run a php file, also Perl or/and Python file???
Like
#!/usr/bin/bash
....
....
case $INPUT_STRING... (1 Reply)
I'm trying to create a bash function that will allow me to rename a file name emails.txt to last monday's date
renem ()
{
d=`date -d last-monday`
mv ~/emails.txt ~/myemails/$d
}
but i en up wit this error any suggestion
mv: target `2014' is not a directory (3 Replies)
Hello,
A couple weeks ago I got some great help from a few of you regarding reading an sql query into a shell script. That post can be viewed here. Thanks to all who posted.
The issue I have now is everytime I run the query I get the following error
SP2-0027: Input is too long (> 2499... (6 Replies)
Hello all,
I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly.
My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Hi All,
Requirement :-
I have shell script in kern shell ,have to run alternate week per month
example-today's date is 27 Mar 2013 and my script will run today then for the next time when it will run it should check 1st what was the last run date(27 Mar 2013) if it is matched 15days from... (2 Replies)
Fairly new to the System Admin world, and this is my first post here, hoping to get some clarification.
I am using a BASH script to automate some Logfile Archiving (into .tars). The actual logfiles are accessed through an SSH, so I have used the following EXPECT sub-script within my main BASH... (8 Replies)
how to run an already developed script run against a list of ip addresses solaris 8 question.
the script goes away and check traffic information, for example
check_GE-VLANStats-P3 1.1.1.1
and returns the results ok.
how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all.
* * * * * script.sh
When I run it manually, I can run it. Is that anything wrong with the above line?
If I change it to something like below,... (4 Replies)
Error received when I tried to restore a blank disk with an 'auto recovery' DDS tape via HP-UX recovery system 2.0 onto a 1Gb SCSI. I assumed it would do the setup, wrong. Could someone tell me the procedure to initial disk for recovering files using cpio. The system is a HP-UX 9.04 version on a... (1 Reply)