I have a bash script for a cron job that uses Google Cloud SDK's gcloud
command after some conditional statements.
eg.
gcloud compute firewall-rules update allow-ssh --source-ranges=$(echo "${mylocations[@]}" | tr ' ' ',')
It is run using crontab
like this:
*/2 * * * * /home/user/bin/firewall-update.sh >/dev/null
I have an email MTA set up, so I can get emails regarding any errors from the server, but stdout is redirected to /dev/null
.
The problem is that gcloud output goes to stderr, even when run successfully, so I always get an email with these sort of line whenever the script is run.
TITLE: Cron user@host /home/user/bin/firewall-update.sh >/dev/null
Updated [https://www.googleapis.com/compute/v1/projects/project-name-4234534/global/firewalls/allow-ssh].
Updated [https://www.googleapis.com/compute/v1/projects/project-name-4234534/global/firewalls/allow-mosh].
...
I have tried adding --verbosity=error
, critical
and none
to the gcloud commands, but they have no effect.
Why does the output go to stderr when it completes successfully and how can I stop getting these emails, while still getting them when there is an error?