Solved

bourne shell day of week

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

786 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