Computing.Net > Forums > Solaris > solaris shell command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

solaris shell command

Reply to Message Icon

Name: greg b
Date: November 12, 2001 at 15:59:54 Pacific
Comment:

help! i need to automatically create a filename based on the prior date. variable='date +%Y%m%d' provides me with the format i need but for the current date. how do i substract one day from this number automatic... e.g. today is 12 Nov 2001, i need to name yesterday's date 20011111.data

greg



Sponsored Link
Ads by Google

Response Number 1
Name: Mark M
Date: November 26, 2001 at 19:50:16 Pacific
Reply:

Try putting this in to whatever you're writing.

date +%Y%m%d | awk '{print $0-1}'

Regards

Mark


0

Response Number 2
Name: Mark M
Date: November 26, 2001 at 19:55:28 Pacific
Reply:

D'oh, wasn't thinking.... this won't work if it's the 1st of the month, obviously... that's quite a tricky one, although I'm sure it can be done with a perl one-liner with the date variable.... not too up on that myself though... sorry!


0

Response Number 3
Name: Mark M
Date: November 26, 2001 at 20:51:59 Pacific
Reply:

I'm bored so tried something... all I can come up with is this:

#!/usr/bin/perl
$ystrdy = time() ( 24 * 60 * 60 );
$thattime = (localtime $ystrdy);
print "$thattime\n";

However this doesn't give you the numerical format that you want.. it'll give you something like Mon Nov 26 05:45:59 2001

You can use cut, paste etc to transpose this though... (and assuming you have perl on your machine). And if you had it in a script you could have

sed 's/Jan/01/g'
sed 's/Feb/02/g' ..... etc etc

anyhow.

Hope this helps in some way. Sorry I can't be of any more help.


0

Response Number 4
Name: Mark M
Date: November 26, 2001 at 21:43:36 Pacific
Reply:

Okay you're probably fed up with me now, but just tried this... maybe it will satisfy your requirements. I saved the perl script to a file called testpl.

You can get a filename (in csh - my shell of choice) with

set myfile = `./testpl | sed 's/ //g' | cut -c 4-8,17-`

This runs the perl script to get yesterday's date, the sed command gets rid of the spaces, and the cut command picks out the info you want (Month, Day, Year).

(if this doesn't work quite right, try messing with the cust parameters as I had to do this on a Linux box at work - no perl on the sun box at my desk - doh!)

use the myfile variable however you need to.

Hope this helps, and I'll shut my big trap now! I was just bored on night shift!

Mark



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Solaris Forum Home


Sponsored links

Ads by Google


Results for: solaris shell command

netra solaris info command www.computing.net/answers/solaris/netra-solaris-info-command/3409.html

In solaris 10 rcp not working www.computing.net/answers/solaris/in-solaris-10-rcp-not-working/4973.html

ultra450 solaris8 shelling command www.computing.net/answers/solaris/ultra450-solaris8-shelling-command/1081.html