Shell脚本实现获取最近登录IP和时间
Shell脚本实现获取最近登录IP和时间
#!/bin/bash Line=`who|wc -l` for LINE in `seq ${Line}` do LoginIP=`who | sed -n "${LINE}p" |awk -F '[()]' '{print $2}'` if [ -z "${LoginIP}" ];then continue else Account=`who| sed -n "${LINE}p" |grep "$ip"|awk '{print $1}'` Date=`who | sed -n "${LINE}p" |grep "$ip"|awk '{print $3" "$4}'` echo "${Date} | ${LoginIP} | ${Account}" fi done