다음에 로그인 한 현재 사용자가 없을 때마다 컴퓨터를 재부팅하라는 명령이 있습니까?
현재는 시스템에 SSH를 사용하고 "w"명령을 사용하여 로그인 한 사용자를 확인해야 재부팅 할 수 있는지 여부를 알 수 있습니다. 로그인 한 사용자가있는 경우 Linux 상자에 저장되지 않은 작업이 남아있을 수 있으므로 재부팅 할 수 없습니다. 로그인 한 사용자가 없을 때까지 일주일에 여러 번 동일한 컴퓨터에 SSH를 연결해야 할 때 시간이 많이 걸릴 수 있습니다.
이것을 정말 간단하게 만들기 위해 다음이 필요합니다.
현재 로그인 한 사용자가 없을 때 컴퓨터를 재부팅하는 명령입니다.
이것은 도움이 될 것입니다 ...하지만 그것은 명령이 아니라 짧은 스크립트입니다. 나는 그것에 대한 명령이 없다고 믿습니다. cron과 함께 사용하기위한 스크립트이지만 물론 컴퓨터에서 원격으로 실행할 수 있습니다.
업데이트 후 재부팅을 위해 사용하고 있습니다.
#!/bin/bash
# Run this script as a cronjob at some suitable time in the PM, e.g. 10pm.
# Turns off workarea machine if no one is logged on, if someone is logged on
# then checks at 15 minute intervals until a set hour is reached.
# Must be used in conjuntion with the following BIOS settings:
# - Machine powers on in event of AC power being restored after loss
# - Machines turns itself on at a time at least 1 hour after the hour specified
# for $giveupat
# time to give up checking if anyone is logged on at. Specify as an hour on
#24 clock e.g. for 7am set to 07. for 7pm set to 19 (though you probably
#do not want to specify a time in the evening!)
giveupat="07"
# while someone is logged in to the machine...
while [ -n "$(who)" ];do
if [ "$(date +%H)" != "$giveupat" ];then
# if time hasn't read the hour at which to give up, sleep 15 minutes
sleep 900
else
# otherwise stop the script
exit
fi
done
# turn off gui login screen
service xdm stop
# reboot
reboot now
출처 : linuxquestions.org
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다