LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How can a non-root user determine which days the computer ran? (https://www.linuxquestions.org/questions/programming-9/how-can-a-non-root-user-determine-which-days-the-computer-ran-796988/)

catkin 03-22-2010 02:21 AM

How can a non-root user determine which days the computer ran?
 
Hello :)

Is there any way a non-root user can programmatically determine which days the computer ran during, say, the last month?

The information is in /var/log/messages.* but those files are root:root 640.

Non of the world-readable /var/log files on the Slackware 13.0 development system can be used:
  • boot Not present if boot logging not enabled (default).
  • dmesg No timestamps.
  • lastlog Not enough info.
  • wtmp Rewritten on each boot so not enough info. EDIT: not correct: by default wtmp is rotated weekly and kept for one month as configured in /etc/logrotate.conf
  • xdm.log Not present if xdm not used.
  • Xorg.0.log Not present if X not run.
Best

Charles

JohnGraham 03-22-2010 02:31 AM

Quote:

Originally Posted by catkin (Post 3907244)
The information is in /var/log/messages.* but those files are root:root 640.

Have you tried just changing the permissions to something line root:admin? I assume they wouldn't be reset every boot...

catkin 03-22-2010 03:23 AM

Quote:

Originally Posted by JohnGraham (Post 3907254)
Have you tried just changing the permissions to something line root:admin? I assume they wouldn't be reset every boot...

Thanks John :) That or something like it would work but I'm developing scripts that may be of more than personal use and do not want to require any modifications to the standard system.

Other possible workarounds are:
  • a suid-root binary executable, simply to analyse /var/log/messages. Better to avoid suid-root binaries if possible.
  • start the application as root and drop to another user:group after doing the necessary. Not so good; the application could not then be started by a non-root user.

JohnGraham 03-22-2010 02:42 PM

Quote:

Originally Posted by catkin (Post 3907288)
Thanks John :) That or something like it would work but I'm developing scripts that may be of more than personal use and do not want to require any modifications to the standard system.

Other possible workarounds are:
  • a suid-root binary executable, simply to analyse /var/log/messages. Better to avoid suid-root binaries if possible.
  • start the application as root and drop to another user:group after doing the necessary. Not so good; the application could not then be started by a non-root user.

Don't forget two other options:

1) Check the file permissions - if the user running the program can't read /var/log/messages then (i) disable that particular functionality and (ii) notify the user of how to get this functionality back (i.e. run as root/change the perms on messages). Of course, this is of no use if that functionality is essential to your program!

2) Just exit the program with an error message unless the person is root, or at least has read access to /var/log/messages. Some programs need to be run as root/an admin, and there's just no way around it.

Tinkster 03-22-2010 10:46 PM

Can you please elaborate why 'last' doesn't have enough info?
You get the boot and down times, do you need a breakdown to seconds?


Cheers,
Tink

catkin 03-23-2010 12:30 AM

Quote:

Originally Posted by Tinkster (Post 3908371)
Can you please elaborate why 'last' doesn't have enough info?

Thanks Tinkster :)

Last is the perfect solution. I thought it only gave info since boot having mistaken removal of utmp in rc.S for removal of wtmp :redface:


All times are GMT -5. The time now is 04:04 AM.