Skip to content

Instantly share code, notes, and snippets.

@oilbeater
Last active March 8, 2024 10:58
Show Gist options
  • Save oilbeater/80d9bcf34758d1e720197b7a04dea512 to your computer and use it in GitHub Desktop.
Save oilbeater/80d9bcf34758d1e720197b7a04dea512 to your computer and use it in GitHub Desktop.
shut down when ssh idle for more than 5 minutes
#!/bin/bash
# docker run --name=close --network=host --privileged --restart=always -d close:v0.0.1
while true; do
if [ -f dump ]; then
rm dump
fi
timeout 5m tcpdump -nn tcp and port 22 and greater 44 -w dump
line_count=$(wc -l < dump)
if [ $line_count -gt 0 ]; then
rm dump
else
rm dump
shutdown -h now
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment