Solved

bourne shell day of week

Posted on 2007-12-05
5
2,631 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

737 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