|
Home > Archive > Unix Programming > September 2006 > Generating log on UNIX
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Generating log on UNIX
|
|
| Shrikrishna Khare 2006-09-23, 1: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
| |
| Henry Townsend 2006-09-23, 1: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
| |
| Pascal Bourguignon 2006-09-23, 1: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)))
|
|
|
|
|