@richland007
Then let’s give it a try :slightly_smiling_face:
First create the script:
pi@MagicPi:~ $ cd
pi@MagicPi:~ $ nano top.sh
Copy-paste this:
!/bin/sh
date >> /home/pi/top.txt
top -b -o +%MEM | head -n 22 >> /home/pi/top.txt
top -b -o +%MEM | head -n 22 >> /home/pi/top.txt
echo "=============================================" >> /home/pi/top.txt
Make it executable:
pi@MagicPi:~ $ chmod 755 top.sh
Perhaps a good idea to prepare the output file in order to be sure the cron user can write in it:
pi@MagicPi:~ $ touch /home/pi/top.txt
pi@MagicPi:~ $ chmod 666 /home/pi/top.txt
Now we add a cronjob:
pi@MagicPi:~ $ crontab -e
Add this line at the end:
00,05,10,15,20,25,30,35,40,45,50,55 * * * * /home/pi/top.sh >/dev/null 2>&1
To verify:
pi@MagicPi:~ $ crontab -l
To verify if the cronjob is actually running:
pi@MagicPi:~ $ tail -F /var/log/syslog
To check if something comes in your output file:
pi@MagicPi:~ $ tail -F top.txt
The script will run every 5 minutes, every hour, every day.
It will output the top 15 MEMory usage and the top 15 CPU usage.
In your case, it will be interesting to look at the last entries before the crash.
Need to identify first if it is an CPU or MEM issue, or both.
Then we can modify the script.
Please do not post lengthy output.
Better we minimise the output by grepping and sorting, etc.
Success!