Scripting AIX date output !!


 
Thread Tools Search this Thread
Operating Systems AIX Scripting AIX date output !!
# 1  
Old 03-01-2010
Scripting AIX date output !!

Hi,

I am writing a korn shell script in AIX. I want to pass the date [in YYYYMMDD format] as a parameter to script and inside it should convert the format to +%a" "%h" "%d" "%Y.

For e.g., a parameter passed as "20100301" should be converted to "Mon Mar 01 2010". I can easily do this with AIX "date" option for the current day. Can someone help me to figure out how I can use this script to accept any previous or future dates and return the formatted output as above.

Thanks in advance.
# 2  
Old 03-01-2010
This is easy save for figuring out the day of the week. The rest is simple string manipulation.

You should give perderabo's master hack "datecalc" a try. search for it in our forum, it is a well written shell script and thankfully perderabo has given public permission to use it.

I hope this helps.

bakunin
# 3  
Old 03-01-2010
Generating formatted time strings.

This could also be done fairly easy with a perl (helper) script (or a C helper).

You only need the seconds since epoch and the built in functions do the rest. This makes printing the date for an offset (such as 1 day from now) really easy... you just add 1 days worth of seconds to the current time, and then print a formatted string.

One key benefit of using the functions (rather than rolling your own) is that they will always get the date right. The pre AIX 6 time database and now the olsen DB in 6.1 always know the proper calculation needs for your TZ such as time shifts, if you have a Feb 29th, etc...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in scripting in AIX

Hello, In a loop I am using below command for every database crsctl status res | grep -E "ora\.$DATABASE\.(.+)\.svc" and below is one of the sample output NAME=ora.sgraphut.sgraphutxdb.svc Now I want to extract just service name out of this string (that is sgraphutxdb) please help me how... (1 Reply)
Discussion started by: Vishal_dba
1 Replies

2. Shell Programming and Scripting

need help scripting a date when the date is 1st to 9th

I'm new to scripting, I am trying to get the current month and date in my script I have this line MYDATE=`date '+%b %d'` this works for dates 10-31, but it returns a 09 for the 9th, where the file name has a 9, I tried MYDATE=`date '+%b %_d'` but that returns Jul %_d I... (5 Replies)
Discussion started by: rsurwill
5 Replies

3. AIX

Get Next month in AIX from curent date in unix AIX

How could we derive teh Next month in MON-RR format from current date ie sysdate in UNI AIX sheel script.I coould get a command but i supports only inLinux susse andnotin AIX. I need for Unix AIX.Pls Help. Regards Shiv (2 Replies)
Discussion started by: SHIV75
2 Replies

4. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

5. Shell Programming and Scripting

help in ksh scripting in aix

Hello gurus I am looking for a script : We need to generate a file list created by user id on a AIX box. Criteria 1: other than userid : dwimpid & aiadmin Criteria 2: Files older than 2 months ( it can be any user id ). File Path to Look: /project and /project1 Thx silu (7 Replies)
Discussion started by: silu
7 Replies

6. Shell Programming and Scripting

Help with ksh scripting in AIX

I am looking for a script which does the following Script will run daily. 1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts. 2.Then it will compare new snapshot with the snapshot created in the previous run. 3.If filesystem exists in... (20 Replies)
Discussion started by: saidiya
20 Replies

7. AIX

scripting routing changes on aix 4.3 and 5x

Hi All, I need to script a routing changes on my aix servers. I can't use smitty, very slow. I need to delete the static routing and add a new one. I also need to change default routing. I know using route add and route delete but I think I remember that this is not enough that's why I... (2 Replies)
Discussion started by: itik
2 Replies

8. Shell Programming and Scripting

Date Scripting Question

I am trying to append a portion of a file with a date on it that changes daily to a temp file. Here are my commands: set DATE = ('date +%Y%m%d_sum.log') cat $HOME/right/$DATE > /export/home/temp.txt Here is the error I keep receiving: cat: cannot open /temp/usr/nedaniel/right/date... (6 Replies)
Discussion started by: BigDawg32
6 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

10. Shell Programming and Scripting

scripting guru's pls help me with scripting on AIX

can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files... pls someone help me on this... thanking in anticipation.... (1 Reply)
Discussion started by: thatiprashant
1 Replies
Login or Register to Ask a Question