Created
February 20, 2013 18:53
-
-
Save apinstein/4998046 to your computer and use it in GitHub Desktop.
thoughts for cron jobs and unix script utilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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