Detect if your Script is Running in CRON
2021-06-21
In my previous post I discussed how I use a wrapper script to back up a fleet of servers.
Here I will just post the part about detecting the terminal/CRON, thought this might be useful and worth putting in a separate post making it easier for crawlers to find.
if [ ! -t 1 ]; then # We don't have a terminal, then we are in cron
# Script running in cron, run without output
else
# Script running interactively, use verbose output
fi
This script is POSIX shell compliant so runs everywhere.
About Me
Dev gone Ops gone DevOps. Any views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.