
gcloud
일부 조건문 다음에 Google Cloud SDK의 명령을 사용하는 크론 작업용 bash 스크립트가 있습니다 .
예.
gcloud compute firewall-rules update allow-ssh --source-ranges=$(echo "${mylocations[@]}" | tr ' ' ',')
다음과 같이 실행됩니다 crontab
.
*/2 * * * * /home/user/bin/firewall-update.sh >/dev/null
이메일 MTA가 설정되어 있어 서버의 오류에 관한 이메일을 받을 수 있지만 stdout은 /dev/null
.
문제는 gcloud 출력이 성공적으로 실행되더라도 stderr로 이동하므로 스크립트가 실행될 때마다 항상 이런 종류의 줄이 포함된 이메일을 받는다는 것입니다.
제목: Cron user@host /home/user/bin/firewall-update.sh >/dev/null
[https://www.googleapis.com/compute/v1/projects/project-name-4234534/global/firewalls/allow-ssh]를 업데이트했습니다.
[https://www.googleapis.com/compute/v1/projects/project-name-4234534/global/firewalls/allow-mosh]를 업데이트했습니다.
...
gcloud 명령어에 및 를 --verbosity=error
추가해 보았지만 아무런 효과가 없습니다.critical
none
성공적으로 완료되면 출력이 stderr로 이동하는 이유는 무엇이며 오류가 있을 때 계속 이메일을 받는 동안 이러한 이메일 수신을 중지하려면 어떻게 해야 합니까?
답변1
해결 방법은 모든 gcloud 명령어에 적용되는 다음 전역 플래그를 추가하는 것입니다.
--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
실제 오류는 여전히 stderr로 전달됩니다.