0

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 noneto 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?

paradroid
  • 868
  • 5
  • 15
  • 29

2 Answers2

0

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

Anaoliy Tk
  • 58
  • 1
  • 6
  • I should have made it clearer, but I do not want to redirect all stderr, as I want to be informed of errors, but glcloud is directing to stderr when no error occurs. – paradroid Aug 14 '20 at 09:35
0

The solution is to add this global flag, which applies to all gcloud commands:

--no-user-output-enabled

    Print user intended output to the console. 
    Overrides the default core/user_output_enabled property value for this command invocation. 
    Use --no-user-output-enabled to disable.

https://cloud.google.com/sdk/gcloud/reference#--user-output-enabled

Actual errors are still directed to stderr.

paradroid
  • 868
  • 5
  • 15
  • 29