So how do you find Linux / UNIX system last reboot or shutdown date and time? The last utility will either list the sessions of specified users, ttys, and hosts, in reverse time order, or list the users logged in at a specified date and time. Each line of output contains the user name, the tty from which the session was conducted, any hostname, the start and stop times for the session, and the duration of the session.
who command
You need to use who command, to print who is logged on. It also displays the time of last system boot. Use last command to display system reboot and shutdown date and time.
$ who –b
Output:
system boot Apr 30 15:08Use last command to display listing of last logged in users and system last reboot time and date:
$ last reboot | less
Or better try:
$ last reboot | head -1
Output:
reboot system boot 2.6.15.4 Sun Apr 30 15:08 - 16:22 (01:13)last command searches back through the file /var/log/wtmp and displays a list of all users logged in (and out) since that file was created. The pseudo user reboot logs in each time the system is rebooted. Thus last reboot command will show a log of all reboots since the log file was created.
To display last shutdown date and time use following command:
$ last -x|grep shutdown | head -1
Output:
shutdown system down 2.6.15.4 Sun Apr 30 13:31 - 15:08 (01:37)Where,
-x: Display the system shutdown entries and run level changes.
For more information read last command man page.
http://www.cyberciti.biz/tips/linux-last-reboot-time-and-date-find-out.html
------------------
2 diana 10.15.07 at 12:57 pm
i couldn’t find out the error. please help me.
#Send list of users logged on to server via email
59 11 * * * last | grep date ‘+%a %b %d’ > /tmp/users.out ; mail -s “Users Logged Today” ephrondiana@gmail.com
when i tried to execute,
$ last |grep date ‘+%a %b %d’
i got no such file or directory error.
3 vivek 10.15.07 at 1:06 pm
Should be..
59 11 * * * last | grep $(date '+%a %b %d') > /tmp/users.out ; mail -s “Users Logged"
4 diana 10.15.07 at 1:25 pm
thanks a lot vivek.i din’t expect this much fast reply.But unfortunately when i execute,
$ last | grep $(date ‘+%a %b %d’)
i couldn’t get anything.Please help
5 vivek 10.15.07 at 2:12 pm
My bad…I forgot to include double quote …
59 11 * * * last | grep "$(date '+%a %b %d')" > /tmp/users.out ; mail -s “Users Logged"Also you may wanna try out:
last -t yyyymmddhhmmssHTH
who command
You need to use who command, to print who is logged on. It also displays the time of last system boot. Use last command to display system reboot and shutdown date and time.
$ who –b
Output:
system boot Apr 30 15:08Use last command to display listing of last logged in users and system last reboot time and date:
$ last reboot | less
Or better try:
$ last reboot | head -1
Output:
reboot system boot 2.6.15.4 Sun Apr 30 15:08 - 16:22 (01:13)last command searches back through the file /var/log/wtmp and displays a list of all users logged in (and out) since that file was created. The pseudo user reboot logs in each time the system is rebooted. Thus last reboot command will show a log of all reboots since the log file was created.
To display last shutdown date and time use following command:
$ last -x|grep shutdown | head -1
Output:
shutdown system down 2.6.15.4 Sun Apr 30 13:31 - 15:08 (01:37)Where,
-x: Display the system shutdown entries and run level changes.
For more information read last command man page.
http://www.cyberciti.biz/tips/linux-last-reboot-time-and-date-find-out.html
------------------
2 diana 10.15.07 at 12:57 pm
i couldn’t find out the error. please help me.
#Send list of users logged on to server via email
59 11 * * * last | grep date ‘+%a %b %d’ > /tmp/users.out ; mail -s “Users Logged Today” ephrondiana@gmail.com
when i tried to execute,
$ last |grep date ‘+%a %b %d’
i got no such file or directory error.
3 vivek 10.15.07 at 1:06 pm
Should be..
59 11 * * * last | grep $(date '+%a %b %d') > /tmp/users.out ; mail -s “Users Logged"
4 diana 10.15.07 at 1:25 pm
thanks a lot vivek.i din’t expect this much fast reply.But unfortunately when i execute,
$ last | grep $(date ‘+%a %b %d’)
i couldn’t get anything.Please help
5 vivek 10.15.07 at 2:12 pm
My bad…I forgot to include double quote …
59 11 * * * last | grep "$(date '+%a %b %d')" > /tmp/users.out ; mail -s “Users Logged"Also you may wanna try out:
last -t yyyymmddhhmmssHTH
本文介绍如何使用Linux命令行工具查询系统的最后重启时间和关闭时间。通过`who -b`和`last reboot`命令可以获取系统启动的时间,而使用`last -x | grep shutdown`则可以查看最近一次系统关闭的具体日期和时间。
1335

被折叠的 条评论
为什么被折叠?



