Solved

bourne shell day of week

Posted on 2007-12-05
5
2,635 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…

707 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