- To: slug@xxxxxxxxxxx
- Subject: Re: [SLUG] passing parameter to a shell script
- From: Jamie Wilkinson <jaq@xxxxxxxxxxxxxx>
- Date: Tue, 3 Aug 2004 11:45:27 +1000
- Reply-by: Sun, 04 Jul 2004 11:34:43 +1000
- User-agent: Mutt/1.5.6+20040722i
This one time, at band camp, Voytek wrote:
>Peter Rundle said:
>> Command line parameters to a script appear as $1, $2, $3 etc with $0
>> being the script name and $# being the number or arguments. It's common
>> practise to do something like this at the beginning of the script,
>> case $# in
>> 1)
>> DOMAIN=$1
>> ;;
>> *)
>> echo "Usage: $0 <domain.name>" 1>&2
>> exit
>> ;;
>> esac
>> if [ -s /home/$DOMAIN/logs/2004-access.log ]
>> ...
>
>Peter, thanks
>above was exactly what I was aiming for.
>
>how can I time the execution lenght, and, write out a log at completion like
>
>$0 executed on date/time in xx sec
>
>into /var/logs/$0.log
starttime=`date +%s`
while true; do stuff; done
endtime=`date +%s`
exectime=$(($endtime - $starttime))
echo "$0 executed on date/time in $exectime sec" >> /var/logs/$0.log
--
jaq@xxxxxxxxxxxxxx http://spacepants.org/jaq.gpg