dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

KSH to determine the day - aix

This is a discussion on KSH to determine the day - aix ; Hello, I'm trying to figure out why this isn't working: DAY=`/usr/bin/date|awk '{print $1}'` if [[ $DAY != "Thur" || $DAY != "Fri"]] then echo "It Works!" fi When I try to run this I get a "`then' is not expected." ...


Home > Database Forum > Operating Systems > aix > KSH to determine the day

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-12-2008, 02:54 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default KSH to determine the day

Hello,

I'm trying to figure out why this isn't working:

DAY=`/usr/bin/date|awk '{print $1}'`
if [[ $DAY != "Thur" || $DAY != "Fri"]]
then
echo "It Works!"
fi

When I try to run this I get a "`then' is not expected." error. Since
today is not Thursday or Friday, I expected this to work. How can I
determine when it's not either of 2 days? I have a script which needs
to run one thing on Thurs & Fri, but something else every other day.

Thanks!
Reply With Quote
  #2  
Old 11-12-2008, 03:15 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: KSH to determine the day

Pete wrote:
> Hello,


> I'm trying to figure out why this isn't working:


> DAY=`/usr/bin/date|awk '{print $1}'`
> if [[ $DAY != "Thur" || $DAY != "Fri"]]
> then
> echo "It Works!"
> fi


> When I try to run this I get a "`then' is not expected." error. Since
> today is not Thursday or Friday, I expected this to work. How can I
> determine when it's not either of 2 days? I have a script which needs
> to run one thing on Thurs & Fri, but something else every other day.


Is this exactly your script? Then it is at least missing a Space before the
closing bracket "]]". And Thursday would be output as "Thu" not "Thur" but
this would also depend on languange settings.

Personally I would use two scripts and start the second one via cron only
on thursdays and fridays, which is rather easy to accomplish.

Thomas Scheunemann
Reply With Quote
  #3  
Old 11-12-2008, 04:20 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: KSH to determine the day

On Nov 12, 1:54*pm, Pete wrote:
> Hello,
>
> I'm trying to figure out why this isn't working:
>
> DAY=`/usr/bin/date|awk '{print $1}'`
> if [[ $DAY != "Thur" || $DAY != "Fri"]]
> then
> echo "It Works!"
> fi
>
> When I try to run this I get a "`then' is not expected." error. *Since
> today is not Thursday or Friday, I expected this to work. *How can I
> determine when it's not either of 2 days? *I have a script which needs
> to run one thing on Thurs & Fri, but something else every other day.
>
> Thanks!


Here is a sample of how I would code it. In my example, I used the
built-in date functions to look at the day of the week as a value
rather than a string. I can in this way set up my script to do
something different for EACH day of the week if I wanted.

################## START OF SCRIPT ##################

#!/bin/ksh

integer DayOfWeek=$(date +"%w")

case ${DayOfWeek} in
0|6) { echo "Today is the weekend"
};;
1) { echo "I dont like Mondays"
};;
2) { echo "Today is Tuesday"
};;
3|4) { echo "Today is Wednesday or Thursday"
};;
5) { echo "Thank God its Friday!"
};;
esac

############## END OF SAMPLE #####################
Reply With Quote
  #4  
Old 11-12-2008, 06:37 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: KSH to determine the day

On Nov 12, 11:15*am, Thomas Scheunemann duisburg.de> wrote:
> Pete wrote:
> > Hello,
> > I'm trying to figure out why this isn't working:
> > DAY=`/usr/bin/date|awk '{print $1}'`
> > if [[ $DAY != "Thur" || $DAY != "Fri"]]
> > then
> > echo "It Works!"
> > fi
> > When I try to run this I get a "`then' is not expected." error. *Since
> > today is not Thursday or Friday, I expected this to work. *How can I
> > determine when it's not either of 2 days? *I have a script which needs
> > to run one thing on Thurs & Fri, but something else every other day.

>
> Is this exactly your script? Then it is at least missing a Space before the
> closing bracket "]]". And Thursday would be output as "Thu" not "Thur" but
> this would also depend on languange settings.
>
> Personally I would use two scripts and start the second one via cron only
> on thursdays and fridays, which is rather easy to accomplish.
>
> Thomas Scheunemann


Yes, this was exactly my script - and you are correct in that I was
missing the space. DOH!

As for cron, I have this set-up that way temporarily right now. I was
trying to keep a cleaner cron by writing a savvy script. This will
help me accomplish that....

Thanks!
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 11:50 PM.