Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell script question!!!!(date)

Status
Not open for further replies.

menace212

Programmer
Jul 11, 2003
144
US
I creating a shell script but I want to attache the date to it...I know the symbols for the date...But my scipt won't attached the date to the file I'm creating...Example below
#!/bin/sh
logpath="/export/home"
datestring="date'%m/%d/%y:%H%M%S'"
pingfile="ping 1.1.1.1"
export pingfile datestring logpath

$pingfile > $logpath/test.$datestring

But the problem is I'm getting it won't create the date on the end....

I'm tring to get to look like this test.9/1/01:5:01:30
 
[tt]datestring=`date '+%m/%d/%y:%H%M%S'`[/tt]
However I'd don't use / in filenames ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Don't use slashes or colons. You will have nothing but headaches down the road.

Also, if you put your date as YYYYMMDD, your files will always be in chronological order in a directory listing (unless you sort it by something else).

Try this...
Code:
#!/bin/sh

logpath="/export/home"
pingfile="ping 1.1.1.1"
export pingfile logpath

$pingfile > $logpath/test.`date '+%Y%m%d-%H%M%S'`
 
Filename variables with slashes in 'em in a shell script redirection will most likely lead to invalid path names anyway (directory does not exist type of errors).


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top