LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices

Reply
 
Search this Thread
Old 01-24-2013, 03:56 AM   #1
rajachan
LQ Newbie
 
Registered: Jan 2013
Posts: 10

Rep: Reputation: Disabled
shell script for date


hi

how to do a shell script in aix to display 15 day before the current date.

Last edited by rajachan; 01-24-2013 at 04:15 AM.
 
Old 01-24-2013, 05:17 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 740
Blog Entries: 2

Rep: Reputation: 192Reputation: 192
perl -e 'print scalar localtime (time - (15 * 86400))'
 
2 members found this post helpful.
Old 01-26-2013, 12:44 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Not much sure about AIX, but can you try like bash style:
Code:
PREVDATE=$(date --date="15 day ago")
echo $PREVDATE
 
Old 01-27-2013, 02:48 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
AIX's version of date doesn't have -d, so that won't work.

A quick google turned up this date script. I don't know how well it works:
http://www.williamrobertson.pwp.blue...shift_date.txt
 
Old 01-28-2013, 01:30 AM   #5
rajachan
LQ Newbie
 
Registered: Jan 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
Exclamation

thanks linosaurusroot

your command is working

i am getting the result in following format...

sun jan 13 hh:mm::sec 2013

is it possible to display the date in below format..

13-jan-13
 
Old 01-28-2013, 04:13 AM   #6
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 740
Blog Entries: 2

Rep: Reputation: 192Reputation: 192
"perldoc localtime" shows the breakdown.
 
Old 01-28-2013, 09:03 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,571

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
you might want to install GNU-date, perhaps by name gdate so you could use this way:

Code:
gdate -d'15 days ago' +%d-%b-%y
 
Old 01-31-2013, 01:15 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
You could also use nawk or gawk if you have them (posix awk/mawk don't have time functions).

Code:
nawk 'BEGIN{ print strftime( "%d-%b-%y" , systime() - 15 * 86400 ) }'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script shell - Date / Time doint Programming 4 04-12-2012 09:09 AM
Shell Script - Date/Time runnerpaul Programming 9 08-20-2008 07:45 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
Shell Script for Unix Date ??? ajeetraina Linux - Newbie 11 02-08-2008 12:58 AM


All times are GMT -5. The time now is 12:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration