Solved

bourne shell day of week

Posted on 2007-12-05
5
2,624 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
  • 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…

829 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