How to view the logs

Having issues with your DietPi installation, or, found a bug? Post it here.
Post Reply
unixmit
Posts: 45
Joined: Wed Jun 13, 2018 7:37 pm

How to view the logs

Post by unixmit »

I have a script that is run every hour that checks the CPU temperature. If it is running hot it sends me a notification. Sometimes I get notified that it is running hot. It’s always at around midnight. It never happens at any other time but not every day.

I would like to add something in my script to read and save the logs at that moment. But where can I find the logs? I see that dietpi-ramlog is installed and that at the moment it is getting saved to RAM and cleared after an hour. So how can I view these logs and save them myself?

Thanks
User avatar
MichaIng
Site Admin
Posts: 2295
Joined: Sat Nov 18, 2017 6:21 pm

Re: How to view the logs

Post by MichaIng »

Logs are usually saved to /var/log. But if you select dietpi-ramlog logging mode, syslogs are not saved there. These are always available via journalctl command. Not sure how these can be read out via script, as by default it opens via pager. Would need an output without pager, to be able to read this output via script. Perhaps journalctl --help gives a hint.

Another option would be to install rsyslog (manually, if you want to keep logs inside RAM). Then /var/log contains:
syslog, daemon.log, and some other possibly interesting system logs.
unixmit
Posts: 45
Joined: Wed Jun 13, 2018 7:37 pm

Re: How to view the logs

Post by unixmit »

That's great thanks. So In my script it can check journalctl and output to a file which I can check. Thanks
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: How to view the logs

Post by baz123 »

@MichaIng Is there a way to view the syslog if ramlog is selected?
User avatar
MichaIng
Site Admin
Posts: 2295
Joined: Sat Nov 18, 2017 6:21 pm

Re: How to view the logs

Post by MichaIng »

@baz123
The default syslog daemon on systemd is systemd-journald. Read it via journalctl: https://manpages.debian.org/stretch/sys ... .1.en.html
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: How to view the logs

Post by baz123 »

@MichaIng Thanks. Yes I was aware of that. I wanted to grep the syslog for a specific term which is across different services and I could not see a way to do that via journalctl.
User avatar
MichaIng
Site Admin
Posts: 2295
Joined: Sat Nov 18, 2017 6:21 pm

Re: How to view the logs

Post by MichaIng »

You can use grep when printing journalctl without pager:

Code: Select all

journalctl --no-pager | grep 'pattern'
Post Reply