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 ]
|