1、在当前主机编写脚本文件history_max.sh显示主机中执行频率最高的前5个命令。
#!/bin/bash
history | tr -s " " " " | cut -d " " -f 3 | sort | uniq -c | sort -nr | head -5
2、判断主机是否存在rhel用户,如果存在则设置密码为redhat,如果不存在则创建用户并设置密码。
#!/bin/bash
{
id rhel && echo rhel:12345 | chpasswd
} || {
useradd rhel && echo rhel:12345 | chpasswd
}
3、通过设置变量HISTTIMEFORMAT,使得当执行history命令时输出格式如下:2022-12-25 16:53:42history
vi ~/.bashrc
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S history: " 在编辑器里面加入这段指令