脚本:
#!/bin/bash
# 定义开机和关机时间
start_time="09:00"
end_time="22:00"
# 获取当前时间
current_time=$(date +%H:%M)
# 对比当前时间和开机时间
if [[ "$current_time" < "$start_time" ]]; then
# 如果当前时间早于开机时间,则等待直到开机时间
echo "等待开机.."
while [[ "$current_time" < "$start_time" ]]; do
current_time=$(date +%H:%M)
sleep 60
done
fi
# 开机
echo "开机!"
# 对比当前时间和关机时间
while [[ "$current_time" < "$end_time" ]]; do
current_time=$(date +%H:%M)
sleep 60
done
# 关机
echo "关机!"
shutdown -h now
授权:
chmod +x auto_shutdown.sh