内容一:只显示最近一次开机时间
1.1 使用 top 命令
# top -bn1 | head -1
1.2 使用 who 命令
# who -b
1.3 使用 uptime 命令
# uptime
内容二:显示最近多次开机时间
# last reboot
# top -bn1 | head -1
# who -b
# uptime
# last reboot
# TMOUT=900
或者:
# export TMOUT=0
(
补充:
1) 这里以设置超过 900 秒用户就会超时为例
2) 如果 TMOUT=0 则用户永不会超时
)
# vim /etc/profile
添加以下内容:
......
TMOUT=900
(
补充:
1) 这里以设置超过 900 秒用户就会超时为例
2) 如果 TMOUT=0 则用户永不会超时
3) 补充 /etc/bashrc 文件会比 /etc/profile 文件更有优先级
)
# source /etc/profile
# vim /etc/bashrc
添加以下内容:
......
TMOUT=900
(
补充:
1) 这里以设置超过 900 秒用户就会超时为例
2) 如果 TMOUT=0 则用户永不会超时
3) 补充 /etc/bashrc 文件会比 /etc/profile 文件更有优先级
)
# source /etc/bashrc
# echo $TMOUT
当通过以上设置造成用户登录超时时,系统会输出以下内容:
# timed out waiting for input: auto-logout
# vim /root/12456.sh
创建以下内容:
#!/bin/bash
for i in {1..5}
do
echo $i
done
(补充:这里以创建 /etc/root/for.sh 脚本为例)
# vim /etc/systemd/system/12456.service
创建以下内容:
[Unit]
Description=12345
After=default.target
[Service]
Type=oneshot
ExecStart=/root/12456.sh
[Install]
WantedBy=default.target
(补充:这里以创建 /etc/systemd/system/12456.service 来管理 ExecStart=/root/12456.sh 为例)
# systemctl daemon-reload
# chmod u+x /etc/systemd/system/12456.service
# systemctl start 12456.service
# systemctl stop 12456.service
# systemctl restart 12456.service
# systemctl enable 12456.service