Created
November 24, 2023 00:27
-
-
Save r0mdau/eb56d512022047a3df6b51a75d41f113 to your computer and use it in GitHub Desktop.
Bash scripts cheat reliability sheet
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
#!/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