Skip to content

Instantly share code, notes, and snippets.

@r0mdau
Created November 24, 2023 00:27
Show Gist options
  • Save r0mdau/eb56d512022047a3df6b51a75d41f113 to your computer and use it in GitHub Desktop.
Save r0mdau/eb56d512022047a3df6b51a75d41f113 to your computer and use it in GitHub Desktop.
Bash scripts cheat reliability sheet
#!/bin/bash
# Enable debug mode
set -x
# Log function
log() {
echo "[INFO] $1"
}
logexit() {
echo "[ERROR] $1 Exiting..."
exit 1
}
# Trap
cleanup() {
log "Cleaning up temporary files..."
rm -f /tmp/website
}
# Trap the EXIT signal and call the cleanup function
trap cleanup EXIT
# Check if curl is installed
log "Checking if curl is installed..."
if ! command -v curl &> /dev/null; then
logexit "curl command is not installed."
fi
# Download the website
log "Downloading the website..."
curl -s -o /tmp/website/index.html https://cv.romaindauby.fr
# Check if the download was successful
log "Checking if the download was successful..."
if [ $? -ne 0 ]; then
logexit "An error occurred while downloading the website."
fi
# Exit with success
log "Script completed successfully."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment