Created
March 2, 2017 23:32
-
-
Save theist/79ca8cf1701f92bf56aa2f788af703b9 to your computer and use it in GitHub Desktop.
quick cronshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CRONLOG=/var/log/cron.log | |
RID=$(cat /dev/urandom | tr -dc "[:alpha:]" | head -c 8) | |
CMD=$@ | |
START=$(date +%s) | |
echo "---- CRON --- START at $(date) --------" | ts | sed "s/^/[${RID}] /" >> ${CRONLOG} | |
echo "-- CMD: $@ ----" | ts | sed "s/^/[${RID}] /" >> ${CRONLOG} | |
/bin/bash -c "$@" > >( sed 's/^//') 2> >( sed 's/^/ [ERR]: /' ) | ts | sed "s/^/[${RID}] /" >> ${CRONLOG} | |
RETURN=$? | |
END=$(date +%s) | |
ELAPSED=$(( $END - $START )) | |
echo "-- CMD: $@ - EXITSTATUS:${RETURN}---" | ts | sed "s/^/[${RID}] /" >> ${CRONLOG} | |
echo "---- CRON --- END at $(date) (${ELAPSED} s elapsed)--------" | ts | sed "s/^/[${RID}] /" >> ${CRONLOG} | |
# use in cron as /path/to/cronshell 'bash one line of commands between single quotes, may contain semicolons' | |
# YMMV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment