Computing.Net > Forums > Solaris > solaris shell command

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

solaris shell command

Reply to Message Icon

Original Message
Name: greg b
Date: November 12, 2001 at 15:59:54 Pacific
Subject: solaris shell command
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


Report Offensive Message For Removal


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


Report Offensive Follow Up For Removal

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!


Report Offensive Follow Up For Removal

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.


Report Offensive Follow Up For Removal

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



Report Offensive Follow Up For Removal







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



Results for: solaris shell command

Mail subject produced by at command
    Summary: Does any one know if it is possible to change the mail subject sent by the unix "at" command. ...
www.computing.net/answers/solaris/mail-subject-produced-by-at-command/4157.html

netra solaris info command
    Summary: hi, is there a command in Solaris 8 that lets you see what the specs of your machine are. Like the processor speed, memory etc... or maybe a tool that you can download that shows you... thanks, ...
www.computing.net/answers/solaris/netra-solaris-info-command/3409.html

In solaris 10 rcp not working
    Summary: If small then consider tftp. It should be open. rsh/rlogin/rcp mapping Solaris 10 no longer maps the original remote shell commands ("rsh" for "remote shell", "rlogin" for "remote login" and "rcp" fo...
www.computing.net/answers/solaris/in-solaris-10-rcp-not-working/4973.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software