Skip to content

Instantly share code, notes, and snippets.

@RobCranfill
Created August 22, 2024 00:17
Show Gist options
  • Save RobCranfill/21ac27be6d0c9b8f944ccae351f0c0e4 to your computer and use it in GitHub Desktop.
Save RobCranfill/21ac27be6d0c9b8f944ccae351f0c0e4 to your computer and use it in GitHub Desktop.
Bash script to check how old the Crandard file is, and copy the "down" file if it's too old.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="30">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link href='https://fonts.googleapis.com/css?family=Stylish' rel='stylesheet'>
<link rel="icon" type="image/png" href="favicon.ico" />
<style>
.mainMessage {
font-family: 'Stylish'; font-size: 224px;
background-color: lightblue;
text-align: center;
line-height: 80%;
padding-top: 5px;
padding-bottom: 5px;
}
</style>
</head>
<body>
<div class="mainMessage">down?</div>
</body>
</html>
#!/bin/bash
# check how old the Crandard file is, and copy the "down" file if it's too old.
CHECK_FILE='/var/www/html/weather/Crandard/index.html'
DOWN_FILE=index-down.html
TOO_MANY_SECONDS=$((600))
echo Checking file $CHECK_FILE...
MOD_SECONDS=`stat -c %Y $CHECK_FILE`
NOW_SECONDS=`date +%s`
DELTA=$((NOW_SECONDS - MOD_SECONDS))
echo "Current time: $NOW_SECONDS"
echo "File modified: $MOD_SECONDS"
echo "Delta: $DELTA seconds"
if [ "$DELTA" -gt "$TOO_MANY_SECONDS" ]; then
echo "Copying 'down' file!"
cp $DOWN_FILE $CHECK_FILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment