Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

bourne shell day of week

Posted on 2007-12-05
5
Medium Priority
?
2,648 Views
Last Modified: 2013-12-26
We need to write a bourne shell script to call a different command on different days of the week and dates of the month. Example;

IF date of month = 14 THEN

ELSE IF day of week = 1 (Monday) THEN

ELSE IF day of week = 3 (Wednesday) THEN

etc.

How can I get the current date of month and day of week?
0
Comment
Question by:bmiller250
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:DrNikon224
ID: 20415823
Is the use of cron out of the question? With cron you could keep a Monday.sh, Tuesday.sh, 14th.sh, etc and schedule them using crontab.
0
 
LVL 16

Expert Comment

by:DrNikon224
ID: 20415882
You can still do the entire thing in a single script. To get dates, use `date +%?` - get the appropriate character for ? from the man page for strftime

Placeholders for values used in your example:
%w is weekday - 0-6 with Sunday as 0
%d is day of month with leading zero - 01-31


# date +%d
# 05

# date +%w
# 3
0
 

Author Comment

by:bmiller250
ID: 20415898
Cron will not work, because  the users will action the scripts and we don't want them to enter the parms
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 20416202

#!/bin/sh
dom=`date +%d`
day=`date +%A`
 
if [ $dom -eq 14 ]
then
   ..
elsif [ $day = Monday ]
then
   ..
elsif [ $day = Wednesday ]
then
   ..
fi

Open in new window

0
 
LVL 48

Expert Comment

by:Tintin
ID: 20416221
or a variation on the above.

#!/bin/sh
dom=`date +%d`
day=`date +%a`
 
if [ $dom -eq 14 ]
then
   ..
   exit
fi
 
case $day in
Mon)    command ;;
Tue)    command ;;
Wed)    command ;;
Thu)    command ;;
Fri)    command ;;
Sat)    command ;;
Sun)    command ;;
esac

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question