You can invoke directly
The pseudo user reboot logs in each time the system is rebooted. Thus last reboot will show a log of all reboots since the log file was created.
it gives in addition the time from which starts the logfile (
If you are interested in the past too, there are usually stored one or more files with past logs (
Here below a little example script to count the number of reboots and crashes in one day.
You can run it with
/bin/bash Myscript.sh to have the results for today
/bin/bash Myscript.sh "Tue May 20" to have results for the 20 of May
N_Crash=`last -F |grep crash | grep "$StrDay" | sort -k 7 -u | wc -l`
N_Reboot=`last -F | grep reboot | grep "$StrDay" | wc -l `
echo "# Today $Today Report for crash and reboot on $StrDay "
echo "# Crashes $N_Crash"
echo "# Reboot $N_Reboot"
with reboot you have few problem because there is one line each time you reboot.
This crash count is only indicative: you can have many lines (e.g. one for each shell) in case of crash. Even more, if the crash is not abrupt you can have different times for the same crash (maybe a second or a minute if it is in boundary). Moreover, even if this is more rare, you can make crash a shell without a crash of the system. The sort option try to kill duplicate lines for the same time. To have a correct result you should count as reboot only the lines of reboot without crashes between and as crashes the reboot with a crash before.