The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Create a script using DATE command? thecoffeeguy Shell Programming and Scripting 1 05-15-2008 03:33 PM
want to create directory with the previous date sridhusha Shell Programming and Scripting 7 11-19-2007 01:44 AM
need to create a file with its name having system date hamsa Shell Programming and Scripting 11 10-18-2006 01:48 AM
Order files by create date mab_arif16 Shell Programming and Scripting 4 05-15-2006 10:04 AM
Directory create date Bab00shka UNIX for Dummies Questions & Answers 2 06-29-2005 07:42 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-19-2006
Registered User
 

Join Date: Oct 2006
Posts: 2
Need help to create a date script

So I need to create a shell script that can take as input a numeric day, month and year and output the day of the week for the input date.

So let's say, I input "programname 19 10 2006" it should output Thursday... I tried messing around with the grep and awk commands, but I can't get it to work.

I'd appreciate any help.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-19-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Use Perderabo's datecalc script -- http://www.unix.com/showthread.php?s...6559#post16559. It's as easy as:
Code:
> datecalc -D 1960 12 31
Saturday
Reply With Quote
  #3 (permalink)  
Old 10-19-2006
Registered User
 

Join Date: Oct 2006
Posts: 2
So I tried to run the script named it Zoltar...

[elee@uxprod elee]$ bash Zoltar -D 1960 09 09
Zoltar: line 116: integer: command not found
Zoltar: line 81: integer: command not found
Zoltar: line 83: set: -A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
Zoltar: line 91: ((: 09: value too great for base (error token is "09")
Zoltar: line 96: ((: 09: value too great for base (error token is "09")
Zoltar: line 110: print: command not found
Zoltar: line 123: ((: 09: value too great for base (error token is "09")
Zoltar: line 131: ((: 09: value too great for base (error token is "09")
Zoltar: line 135: print: command not found
Zoltar: line 142: integer: command not found
Zoltar: line 143: set: +A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
Zoltar: line 154: print: command not found
Reply With Quote
  #4 (permalink)  
Old 10-19-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
datecalc uses ksh. Just chmod +x the datecalc script and run it as
Code:
datecalc -D 1960 12 31
Reply With Quote
  #5 (permalink)  
Old 10-19-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,448
Python alternative
Code:
import sys,time
day,month,year = sys.argv[1:] #assume first param is day, then month, finally year
b = time.strptime("%s %s %s" % (day ,month, year), "%d %m %Y")
convert = time.strftime("%A", b)
print convert
output:
Code:
/home> python test.py 19 10 2006
Thursday
Reply With Quote
  #6 (permalink)  
Old 10-20-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,199
With GNU date command :
Code:
date --date="20061019" '+%A'

Jean-Pierre.
Reply With Quote
  #7 (permalink)  
Old 10-20-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
perl -e '@y=localtime(time()-86400);printf "%04d-%02d-%02d",$y[5]+1900,$y[4]+1,$y[3];'
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0