Advertisement
Guest User

Untitled

a guest
May 6th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #!/bin/bash
  2. ################################################################
  3. # 指定時間、指定ユーザのログインが無ければシャットダウンする #
  4. # ・/etc/rc.localなどで、ユーザ名を引数に & 付きで起動 #
  5. ################################################################
  6.  
  7. LIMIT_SEC=$((60 * 15)) # 15分
  8.  
  9. TIME_LAST_LOGOFF=$(date +%s)
  10. while :;
  11. do
  12. if [ "$(who | cut -d ' ' -f 1 | sort -u | grep ^"$1"$ )" = "$1" ] ;then
  13. # login中
  14. TIME_LAST_LOGOFF=$(date +%s)
  15. else
  16. # loginしてない
  17. TIME_NOW=$(date +%s)
  18. if [ $(($TIME_NOW - $TIME_LAST_LOGOFF)) -ge $LIMIT_SEC ] ;then
  19. # 指定時間(以上)経過したから、shutdown
  20. sync
  21. umount -a
  22. poweroff
  23. exit
  24. fi
  25. fi
  26. sleep 3
  27. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement