I need to stop server running at aws within 750 hours. Is there anyway i can automate it shutdown process within that time limit ?
Asked
Active
Viewed 106 times
1 Answers
1
Here is a simple bash script to do this job (save this to a file with .sh extension):
#!/bin/bash
reboot=$((750*3600))
uptime=$(awk -F. '{print $1}' /proc/uptime)
if [ $uptime -ge $reboot ]; then
shutdown -h
fi
Let me explain:
reboot=$((750*3600))
We get the representation of 750 hours in seconds
uptime=$(awk -F. '{print $1}' /proc/uptime)
This is the system uptime in seconds
After you saved the file give it executable permissions:
chmod +x name-of-your-file.sh
You can set a cron job to execute this script every hour:
sudo crontab -e
Then paste this:
0 * * * * /path/to/your/script.sh
Sh1d0w
- 1,348