Operating System - HP-UX
1834254 Members
1974 Online
110066 Solutions
New Discussion

Re: Shell Script Question.

 
SOLVED
Go to solution
Jason Young
Occasional Advisor

Shell Script Question.

Hi,

I was wondering if there was someone who would know an easy way to get the date from yesterday generated in a shell script. What I am doing is outputting a file called YYYY_MM_DD from a script, the only issue is that I want the date to be yesterday not today.

Any ideas?

Jason
Why ?
3 REPLIES 3
John Poff
Honored Contributor
Solution

Re: Shell Script Question.

Hello,

Here is a recent thread for a similar question. Some of the replies included scripts that will calculate the previous dates. If you have Perl loaded on your machine it also makes it easy to do this.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x6e92ee3e323bd5118fef0090279cd0f9,00.html


JP
someone_4
Honored Contributor

Re: Shell Script Question.

Hello if your script runs the date that you want and you want to save the file with that date. Put this on the bottom
stamp=`date +%m%d%H%M`
cp yourfile.txt youfile.$stamp

if you want to calulate a date.
Here is a post that helped me out with that.You can also do a search (top left hand)
for date and you will find other post on this subject.
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x6cc253921f1ad5118fef0090279cd0f9,00.html


Richard



eric stewart_1
Occasional Contributor

Re: Shell Script Question.

I am working for a company that made this simple. From CRON at 23:59 as root they create a file /tmp/yesterday with 444 as the permissions. They put the output of the date command in it. Everyone knows it is there and they agreed on a format. Now any time they need yesterdays date they can get it with cat /tmp/yesterday. VERY SIMPLE SOLUTION.