I know my script is going to take more than 10 hours to run. Is there a way to log the time it starts and the time it ends ?
Does the time
command just time the process or do I get the output of the process that I'm timing ?
command time works in most shells. /usr/bin/time should work in all shells. you can change the output of the system time . use -p to get output similar to the shell builtin time . use -f to write your own format.
Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.
On Unix-like systems, there is a utility named 'GNU time' that is specifically designed for this purpose. Using Time utility, we can easily measure the total execution time of a command or program in Linux operating systems.
You can use ' time ' command to get the execution time of the script. This command will call the Tcl interpreter count times to evaluate script (or once if count is not specified).
Use the time
command (details):
time your_prog
If time
does not fit for you, I would try to log the output of date
(details) before and after the execution of your program, e.g.
date > log.txt; your_prog; date >> log.txt
Finally, you can also add some formatting (NOTE: inspired by Raze2dust's answer):
echo "started at: $(date)" > log.txt; your_prog; echo "ended at: $(date)" >> log.txt
The time
command shows how long your process runs:
$ time sleep 2
real 0m2.002s
user 0m0.000s
sys 0m0.000s
$
sleep 2
is just a simple process that takes 2 seconds.
To log the current time, use the date
command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With