次に、現在ユーザーがログインしていないときにコンピュータを再起動するコマンドはありますか?
現在は、SSHを介してシステムにログインし、「w」コマンドを使用して、誰がログインしているかを確認して再起動できるかどうかを確認できます。ユーザーがログインすると再起動できません。これは、Linuxボックスにまだ保存されていないタスクがある可能性があるためです。これは一般的なことです。週に数回同じシステムにSSHでアクセスし、ログインしているユーザーがいなくなるのを待つ必要がある場合、これは非常に時間がかかる可能性があります。
これを非常に簡単にするには、次のものが必要です。
現在ログオンしているユーザーがいないときにコンピュータを再起動するコマンド。
ベストアンサー1
役に立ちますが、コマンドではなく短いスクリプトです。そんな順番はないと思います。これは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