![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script in saved in compress format | naveeng.81 | Shell Programming and Scripting | 1 | 04-14-2008 08:31 AM |
| mailx saved messages are unreadable (base64) | Squeakygoose | UNIX for Dummies Questions & Answers | 1 | 01-30-2008 11:49 AM |
| Sudo file not saved | Asteroid | UNIX for Advanced & Expert Users | 0 | 07-30-2007 07:18 AM |
| only root's crontab gets not saved | flok | UNIX for Advanced & Expert Users | 1 | 06-25-2007 10:50 AM |
| Where are the password saved in a UNIX server? | hast5 | UNIX for Dummies Questions & Answers | 12 | 10-19-2006 04:11 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How can I identify the last saved log?
Our system produce logs when a script is run which may not be daily, the logs have a format: name_YYMMDD.log - both name and .log are consistent, date changes as per the day the script is run.
Is there a way of finding the last saved log? |
|
|||||
|
Actually, Gee-Money is on the ball. If your script is in a particular directory, you don't need find. Just ls. However, his script is unnecessarily complex:
Code:
ls -1t |sed -n '/name.*\.log$/{p;q}'
|
|
||||
|
Why does this not work?
I have taken the above example and developed a small test script as shown below to do what I want:
NEXT=TEST01 dir='C:/cygwin/var/log/img/aut/' cmd1="sed -n '/" echo $cmd1 cmd2=".*\.mqsc$/{p;q}'" echo $cmd2 echo "$cmd1$NEXT$cmd2" > command.txt command=$(grep sed command.txt) ls -1t $dir | grep $NEXT > temp.txt filename=$($command < temp.txt) The results I get when I run the script are: + NEXT=TEST01 + dir=C:/cygwin/var/log/img/aut/ + cmd1='sed -n '\''/' + echo sed -n ''\''/' sed -n '/ + cmd2='.*\.mqsc$/{p;q}'\''' + echo '.*\.mqsc$/{p;q}'\''' .*\.mqsc$/{p;q}' + echo 'sed -n '\''/TEST01.*\.mqsc$/{p;q}'\''' ++ grep sed command.txt + command='sed -n '\''/TEST01.*\.mqsc$/{p;q}'\''' + ls -1t C:/cygwin/var/log/img/aut/ + grep TEST01 ++ sed -n ''\''/TEST01.*\.mqsc$/{p;q}'\''' sed: -e expression #1, char 1: unknown command: `'' + filename= |
|
||||
|
otheus there was no reason why I could not use:
ls -1t $dir >temp.txt sed -n "/$NEXT/{p;q}" temp.txt I don't even know why I didn't think of it! One of those days. THANK YOU EVERYONE WHO HELPED, GREATLY APPRECIATED. I DON'T KNOW WHAT I WOULD WITHOUT THE HELP. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|