Can I execute multiple sequential commands in a cron using a semi-colon?
Is that how it works?
Example Code:
*/15 * * * * date > log.file; apt update >> log.file; date >> log.file 1. print the date and pipe output to create/overwrite log.file 2. update apt and pipe append output to log.file 3. print the date and pipe append output to log.file (this lets me know how long the apt update command took to finish |
Yes, that should work but it seems silly to run an update every 15 minutes. I guess it depends on what you are actually trying to accomplish. Since the file is being overwritten every time you can not determine if it changes. You can also write the output of the time command to a file to see how long apt takes to update i..e
time apt update > log.file |
did you try it already?
I would recommend you to write a shell script and put everything into it. |
Quote:
I only ever want to know how long and when the last rsync occurred. Quote:
|
time command is your friend.
|
The last crontab field accepts a complete standard shell (no bashism), except that a literal % must be escaped \%
The shell allows to group commands for a common redirection: Code:
*/15 * * * * { date; apt update; date; } > log.file Code:
*/15 * * * * ld=/tmp/mylockdir; if mkdir $ld 2>/dev/null; then apt update; fi; rmdir $ld |
All times are GMT -5. The time now is 06:15 PM. |