LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-22-2010, 02:21 AM   #1
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,544
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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

Last edited by catkin; 03-23-2010 at 12:35 AM.
 
Old 03-22-2010, 02:31 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by catkin View Post
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...
 
Old 03-22-2010, 03:23 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,544
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by JohnGraham View Post
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.
 
Old 03-22-2010, 02:42 PM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by catkin View Post
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.
 
Old 03-22-2010, 10:46 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
1 members found this post helpful.
Old 03-23-2010, 12:30 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,544
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by Tinkster View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a command as another user in a bash script ran as root? camphor Programming 2 03-29-2009 03:11 PM
Ran Firefox as root, now can't run as user! mazinoz Linux - Desktop 1 01-13-2007 03:16 AM
Help ran out of space on root synapse Slackware 7 11-10-2004 12:46 PM
3+ days to compile KDE? Even on an old computer? ColinAnderson Linux - Software 5 11-21-2003 05:28 AM
ran fsck -ASV by accident! computer won't boot JustinHoMi Linux - General 3 10-13-2001 11:34 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration