Skip to content

Instantly share code, notes, and snippets.

@apinstein
Created February 20, 2013 18:53
Show Gist options
  • Save apinstein/4998046 to your computer and use it in GitHub Desktop.
Save apinstein/4998046 to your computer and use it in GitHub Desktop.
thoughts for cron jobs and unix script utilities
# useful for ignoring certain codes (ie rsync 24) when running under set -e
#
# runIgnoringExitCodes 1,2,3 cmd foo bar
#
# be sure to escape the command as needed
#
# runIgnoringExitCodes 1,2,3 "cmd foo bar | grep baz"
#
function runIgnoringExitCodes {
local ignore_codes=(${1//,/ })
shift
local cmd=$*
# echo "Ignoring ${ignore_codes[@]} while running $cmd"
eval ${cmd} || returnStatus=$? && true
local e
for e in $ignore_codes; do
#echo "testing return against allowed exit status $e"
[[ "${returnStatus}" == "${e}" ]] && return 0
done
#echo "NOT OK TO IGNORE"
return $returnStatus
}
# not sure this works yet
function collectOutput {
local logfile
logfile=$1
[[ -z $logfile ]] && echo "No logfile specified" && return 1
> $logfile exec 2>&1
date
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment