Created
January 7, 2014 18:33
-
-
Save lifuzu/8304186 to your computer and use it in GitHub Desktop.
Bash function collections
This file contains 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
function buildlogcmd { | |
log=$1 | |
shift | |
echo "Build: $*" >> "$log" | |
echo " `pwd`" >> "$log" | |
echo " `date`" >> "$log" | |
echo "" >> "$log" | |
$* 2>&1 | tee -a "$log" | |
status=${PIPESTATUS[0]} | |
if [ $status != 0 ]; then | |
echo "" >> "$log" | |
echo "FAILED" >> "$log" | |
echo "" | |
echo "FAILED" | |
exit $status | |
fi | |
echo "" >> "$log" | |
echo "OK" >> "$log" | |
} |
This file contains 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
# check the network connection | |
function check_connection() { | |
touch ignore.me | |
scp -o ConnectTimeout=10 ignore.me ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_FOLDER} | |
# if scp doesn't work, then send error email to let someone know. | |
if [ $? != 0 ]; then | |
sendemail -f ${FROM_ADDR} -t ${TO_USERS} -u "FATAL ERROR: Can't connect to ${REMOTE_USER}@${REMOTE_HOST} from ${host}" -m "Please have a check and run backup scripts again!!!" -s ${SMTP_SERVER} | |
exit 1 | |
fi | |
} |
This file contains 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
# set trap to clean environment | |
function clean_env() { | |
rm -f ${TARFILE} | |
rm -f ${TARFILE}.md5sum | |
rm -f ${LOGFILE} | |
} | |
trap clean_env EXIT SIGINT SIGTERM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment