一
ip_show.sh 网卡 显示当前的IP
vim ip_show.sh
###
ifconfig ens3 | awk '/inet\>/{print $2}'
###
sh ip_show.sh
二
host_messages.sh 显示当前主机的名称,ip登陆当前主机的用户
hostname: xxxxx
ipaddress: xxxx.xxxx.xxx.xxx
username: root
vim host_messages.sh
###
echo -e "hostname:\t$(hostname)"
echo -e "ipaddress:\t$(ifconfig ens3 | awk '/inet\>/{print $2}')"
echo -e "username:\t$USER"
###
\t代表tab
精简:
echo -e "hostname:\t$(hostname)\nipaddress:\t$(ifconfig ens3 | awk '/inet\>/{print $2}')\nusername:\t$USER"
三
clear_log.sh 执行次脚本后可以清空日志
vim clear_log.sh
###
[ "$USER" = "root" ] || {
echo "Please run $0 with root!!!" #$0是脚本本身
exit
}
[ -e "/var/log/messages" ] || {
echo "No logfile here!!!"
exit
}
> /var/log/messages && {
echo "logfile is cleared!!!"
}
###
sh clear_log.sh