Generating log on UNIX
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Generating log on UNIX




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Generating log on UNIX  
Shrikrishna Khare


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-06 06:46 AM

Hi,

I want to run a sequence of commands on UNIX for series of
operations. I would like to have a log of both - the commands as well
as their output.

I can do <command> | tee -a <logfile>. However, it does not
redirect the "command" that I entered into the log file.

How could I get it done?


Thanks in advance,
Shrikrishna






[ Post a follow-up to this message ]



    Re: Generating log on UNIX  
Henry Townsend


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-06 06:46 AM

Shrikrishna Khare wrote:
> Hi,
>
>     I want to run a sequence of commands on UNIX for series of
> operations. I would like to have a log of both - the commands as well
> as their output.
>
>     I can do <command> | tee -a <logfile>. However, it does not
> redirect the "command" that I entered into the log file.
>
>     How could I get it done?

man script





[ Post a follow-up to this message ]



    Re: Generating log on UNIX  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-06 06:46 AM

"Shrikrishna  Khare" <shri.khare@gmail.com> writes:

> Hi,
>
>     I want to run a sequence of commands on UNIX for series of
> operations. I would like to have a log of both - the commands as well
> as their output.
>
>     I can do <command> | tee -a <logfile>. However, it does not
> redirect the "command" that I entered into the log file.
>
>     How could I get it done?

log=/tmp/cmd.log
docmd () {
echo "============" >> $log
date                >> $log
echo "$@"           >> $log
echo "============" >> $log
"$@"           2>&1 >> $log
}

touch $log
tail -f $log & tail_pid=$?

docmd echo 'Howdy?'
docmd ls -l

kill $tail_pid


There's one defect, in that the command line logged lose the words:

docmd echo 'ab cd' ef

would log as:  echo ab cd ef
One Q&D fix would be:

for arg in "$@" ; do
echo -n "$(echo "$arg" | sed -e 's/\(.\)/\\\1/g') "
done    >> $log
echo '' >> $log

instead of:

echo "$@"           >> $log


--
__Pascal Bourguignon__                     http://www.informatimago.com/

"This statement is false."            In Lisp: (defun Q () (eq nil (Q)))





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:34 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register