I have a bash script running as cron job which has some gcloud commands in it.
eg.
gcloud compute firewall-rules update allow-ssh--source-ranges=$(echo "${mylocations[@]}" | tr ' ' ',')
I have the crontab entry redirecting stdout to /dev/null, so that I don't get emails every time it runs.
The problem is that gcloud's output goes to stderr, even when there is no error, so I get emails like this:
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].
...
I have tried adding --verbosity=error
, critical
and none
to the gcloud commands, but they have no effect.
So how do I stop gcloud from sending this message to stderr when it completes successfully? Why does it even do that?
I suppose, it do that, because, you redirect in /dev/null ONLY stdout. Cron also would send you emails if there are some errors. Try to redirect in /dev/null stderr too. Add in the end of your crontab command something like that:
> /dev/null 2>&1
The solution is to add this global flag, which applies to all gcloud commands:
https://cloud.google.com/sdk/gcloud/reference#--user-output-enabled
Actual errors are still directed to stderr.