From a7205ca33e25f8763fa6ccbc365ba9b370698da3 Mon Sep 17 00:00:00 2001 From: Christophe Lyon Date: Wed, 6 Mar 2019 20:48:37 +0000 Subject: tcwg-cleanup-stale-containers.sh: Do not fail if there is no ssh-agent process to kill. Handle two cases where killall can fail: - command not found, in which case we want an error so that we know we have to install killall - no ssh-agent process running, which is OK Change-Id: I0d6d7e40eed6db7c6250f2231f05b8cca73c8355 --- tcwg-cleanup-stale-containers.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh index cc748c5c..df723dba 100755 --- a/tcwg-cleanup-stale-containers.sh +++ b/tcwg-cleanup-stale-containers.sh @@ -200,9 +200,24 @@ fi if [ "$cleanup_ssh_agent_hours" -gt "0" ]; then res=0; killall --older-than ${cleanup_ssh_agent_hours}h -u $USER ssh-agent & wait $! || res=$? + # Killall can fail for several reasons: + # return-code 127: command not found + # return-code 1: in general means no ssh-agent process was found + # In the first case, we want the cleanup job to fail, so that we + # know we need to install killall + # The second case is OK, unless killall fails for another + # reason. Assume OK for now. if [ $res != 0 ]; then - echo "WARNING: could not kill stale ssh-agent processes" - status=$(($status|16)) + case $res in + 127) + echo "WARNING: could not kill stale ssh-agent processes (killall command not found)" + echo "Increasing exit code to indicate killall is missing" + status=$(($status|16)) + ;; + 1) + echo "WARNING: could not kill stale ssh-agent processes" + ;; + esac fi fi -- cgit v1.2.3