On Tue, May 24, 2011 at 9:34 AM, Steve Holdoway <[email protected]> wrote: > Oldschool... > echo "Backup starts at: `/bin/date +%H:%M:%S`"
printf is the POSIX-preferred command, as echo has too many different implementations across different operating systems. Not something that will bother Roger's example :-) And, if you are using a variant on bash, the backticks should be replaced with $(...) instead -- because they are more visible and obvious when reading the script, and also allow nested calls. If you want to grow your own timing stats, you should collect the date in a numeric format at the beginning of an operation, and throw it back at the end ... STARTDATE=$(date +%H:%M:%S) STARTSEC=$(date +%s) ( ... commands ... ) FINISHSEC=$(date +%s) FINISHDATE=$(date +%H:%M:%S) printf "Started at $STARTDATE\nFinished at $FINISHDATE\nElapsed: $((FINISHSEC-$STARTSEC)) seconds\n" I put a 'sleep 5' in there for a test ... jim@hex:~/tmp$ ./timing.sh Started at 10:29:59 Finished at 10:30:04 Elapsed: 5 seconds However, as Anatoly said, there's already the handy 'time' shell builtin command, which tells you about an individual command's timing. jim@hex:~/tmp$ time sleep 5 real 0m5.004s user 0m0.010s sys 0m0.000s For more interesting investigation, 'man time' tells you about the abilities of the external (non-builtin) /usr/bin/time command. Here I'll get it to tell me the elapsed time, exit status and command-line invoked (this turns out to be an easy way to collect exit status values, instead of looking for $? all the time, BTW) jim@hex:~/tmp$ /usr/bin/time -f '%E %x %C' sleep 5 0:05.00 0 sleep 5 I think you'll find something to keep you amused in that lot ... -jim _______________________________________________ Linux-users mailing list [email protected] http://lists.canterbury.ac.nz/mailman/listinfo/linux-users
