Need help to create a date script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to create a date script
# 1  
Old 10-19-2006
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.
# 2  
Old 10-19-2006
Use Perderabo's datecalc script -- https://www.unix.com/showthread.php?s...6559#post16559. It's as easy as:
Code:
> datecalc -D 1960 12 31
Saturday

# 3  
Old 10-19-2006
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
# 4  
Old 10-19-2006
datecalc uses ksh. Just chmod +x the datecalc script and run it as
Code:
datecalc -D 1960 12 31

# 5  
Old 10-19-2006
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

# 6  
Old 10-20-2006
With GNU date command :
Code:
date --date="20061019" '+%A'


Jean-Pierre.
# 7  
Old 10-20-2006
Code:
perl -e '@y=localtime(time()-86400);printf "%04d-%02d-%02d",$y[5]+1900,$y[4]+1,$y[3];'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing Date in the file with Create date and timestamp

Hello, I have files that with a naming convention as shown below. Some of the files have dates in the file name and some of them don't have dates in the file name. imap-hp-import-20150917.txt imap-dell-gec-import-20150901.txt imap-cvs-import-20150915.txt imap-gec-import.txt... (8 Replies)
Discussion started by: Saanvi1
8 Replies

2. Shell Programming and Scripting

Please help, need to create script to remove lines by date in file

Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and... (2 Replies)
Discussion started by: m3pwr
2 Replies

3. Shell Programming and Scripting

Create a Date Check Script

I have about 100 Linux servers running in Amazon EC2 (CentOS 6 based) and I need to run a 'date' command against all of them. Rather than logging into each individual server via 'ssh' and running the 'date' command, can someone please help me with how something like this can be scripted? I... (6 Replies)
Discussion started by: cmennens
6 Replies

4. Shell Programming and Scripting

How to create variable from date

I have a requirement to send a trigger file (trigger_dayn.dat) to a remote server through the FTP trigger_dayn.dat - here the dayn is the day number. However the dayn is not sysdate. day 1 is from Monday 07:00.00 AM to Tuesday 06:59:59 AM and so on. So if the trigger file is generated say... (1 Reply)
Discussion started by: k_vikash
1 Replies

5. Shell Programming and Scripting

help to create script for added date to list users

hi my friends im asking for the possibility to creat a script in ubuntu for added date to list users for doing this : - search in debug connected user of all connected users - if a new user is connect for the first time to my server the script record the date of the connection and added it... (1 Reply)
Discussion started by: amzioujda
1 Replies

6. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

7. UNIX for Dummies Questions & Answers

Find and Create by Date

I have a log file that's generated on a daily basis, and saved with the Month and day at the end of it. For instance: file_type_Aug17.csv. As part of my excel conversion I need my script to search for the current Month and day(Aug17) and convert it. Thanks for your help! (14 Replies)
Discussion started by: ravzter
14 Replies

8. Shell Programming and Scripting

Create a script using DATE command?

Not even sure how to word this. Basically, we have a log file that gathers all alerts for a system. What I am doing is grepping through this file and grabbing certain strings that are outputted to a file, then mailed to a group. Here is the catch. Since I cannot copy this file to a temp file... (1 Reply)
Discussion started by: thecoffeeguy
1 Replies

9. Shell Programming and Scripting

need to create a file with its name having system date

Hi, Iam new to unix . I need to write a scritp which can create a file having sysdate as a part of it.and i also need to delete file which is created five days before in a directory.pls Help me out thanks in advance (11 Replies)
Discussion started by: hamsa
11 Replies

10. UNIX for Dummies Questions & Answers

Directory create date

Hi, How do you find the create date of a directory? I can see the modification date using ls -l but I'm looking for the create date. Many thanks Helen (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question