Skip to content

Instantly share code, notes, and snippets.

View Jflick58's full-sized avatar
💭
Probably drinking coffee

Justin Flick Jflick58

💭
Probably drinking coffee
  • Homesite Insurance
View GitHub Profile
@Jflick58
Jflick58 / idle_shutdown.sh
Created August 24, 2021 06:10
Shutdown Idle EC2 instances after 5 minutes of no SSH activity
#crontab entry - replace your_user with your actual user name
#*/10 * * * * /home/your_user/idle_shutdown.sh > shutdown_logs.txt
#check for established SSH connections
SSH_CONNS=`netstat | grep ssh | grep ESTABLISHED`
#If None
if [ -z "$SSH_CONNS" ]
then
#wait 5 minutes and check again
echo "No SSH Connections. Checking again in 5 minutes"