Quote:
Originally Posted by raj k yadav
Thanks for the solution. It works for me but i need to understand a bit more. The way I want to do is:
cd /data/logs/LOG/SIG_SER/Feb-2010-SIG_SER; ls -ltrh| tail -n 1 > $LOGFILE1 | tail -n 20 "echo $LOGFILE1"
|
You are on the right track, but there are several issues.
The quotes aren't quite correct in the last part of your command. To insert the output of a command like echo into another command, you either have to use backquotes, or the $() notation, eg:
Code:
tail -n 20 `echo $LOGFILE1`
Code:
tail -n 20 "$(echo $LOGFILE1)"
However, there is no need to 'echo' a variable, since you can place it directly in the command anyway.
Also, you cannot assign to a variable $LOGFILE by using the redirection. So ultimately your line would end up something like this:
Code:
LOGFILE1=$(ls -tr | tail -n 1); tail -n 20 "$LOGFILE1"
I suspect you are also trying to display the log file details as well. This requires a separate command. The pipe '|' is fine for passing results from one command to the next, but the semicolon ';' is used for running multiple commands on a single line. eg
Code:
LOGFILE1=$(ls -tr | tail -n 1); ls -lh "$LOGFILE1"; tail -n 20 "$LOGFILE1"