Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display day of week in shell script

Status
Not open for further replies.

ITGoddess

IS-IT--Management
Dec 13, 2001
8
US
Greetings!

I have a fairly simple admin script to show progress on various overnight jobs. On one, I show the date of the last 3 runs on a particular job,(to represent Base, Previous, Last Run). Like this

echo "`ll /file1 | cut -c 45-51` `ll /file2 | cut -c 45-51` `ll /file3 | cut -c 45-51`"

Result:

Base Previous Last Run
Nov 19 Nov 21 Nov 22


I'd like to also show the day of week that file1, file2, file3 were generated in an echo statement directly below. I'm thinking that a date and grep statement is the answer.

Ideal Result:

Base Previous Last Run
Nov 19 Nov 21 Nov 22
Tues Thu Fri

I would definately appreciate a code snippet or a strong hint on how to do this.

Thanks in advance!

-Michelle
 
I would think that the best solution would be to create a flag file when the script ran showing all of the info you need like so:

Month:Day:"Day of Week"

/usr/bin/date "+%b %d:%a" > ${FLAGFILE}

Then you would have some other parser script which would get the last three created flag files and remove any miscellaneous ones from the system. It would then display the info how you want it:

Example:

MONTH=`/usr/bin/cat ${FLAGFILE}|/usr/bin/cut -d ":" -f1`
DAY=`/usr/bin/cat ${FLAGFILE}|/usr/bin/cut -d ":" -f2`
 
Here's an awk script that uses Zeller's algorithm. I converted it from a PL1 version I found at


echo 2002 11 25 | awk -f dayofweek.awk

# ------ dayofweek.awk ------
{
yy=$1
wm=$2
dd=$3
if (wm<3) {
wm+=12
yy--
}
print int(yy/400 - yy/100 + (wm+1)*26/10 + yy*125/100 + dd - 1) % 7
}
~ CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top