我正在尝试编写一个bash脚本,计算用户首次登录和最近一次登录之间的时间差。感谢您的帮助:)
以下是我目前的代码:
以下是我目前的代码:
read -p "Enter a user ID: " ID
echo "You entered the following ID(s): $ID"
#/bin/egrep -i "^$ID" /etc/passwd
echo -n "The users real name is: "
/bin/grep "^$ID" /etc/passwd | cut -f5 -d :
echo -n "$ID's first login time is: "
l1=`last "$ID" | tail -n 1`
echo -n "$ID's last login time is: "
l2=`last "$ID" | head -n 1`
echo $l1
echo $l2
echo -n "The time difference is $(l1-l2) "
getent
命令是特定于Linux的(例如,在Mac OS X上不可用)。last --time-iso
选项仅适用于GNU的last
(例如,在Mac OS X上不可用)。你使用的所有主要date
选项都不直接可用,除非使用GNU的date
命令。虽然GNU代码可以安装在任何类Unix系统上,但该代码在大多数非Linux系统上不能直接运行。 - Jonathan Lefflerdate
不兼容,并且getent
并非仅限于Linux,我知道至少FreeBSD、NetBSD和Solaris都有它,但显然没有OSX... 无论如何,我假设这个问题是关于Linux的...(我调整了兼容性说明)。 - Martin Tournoij