Forum Moderators: bakedjake

Message Too Old, No Replies

Cron to log uptime

Trying to make a crontab to log linux uptime in FC 2

         

mytinytown

5:23 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



I originally put
00 12 * * * /usr/bin/uptime &> /var/log/uptime.txt
To log the uptime @ noon everyday, it did not work.

Another forum suggested:
00 12 * * * /usr/bin/cron.uptime >> /var/log/uptime.txt
This to did not work.

So I tried to chmod the txt to 777 and this did not work. Is there something I missed? The crontab -e shows the crontab was added, so it is running, just not working.

Joe

jollymcfats

8:12 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Try just:
0 12 * * * /usr/bin/uptime >> /var/log/uptime.txt

The log file doesn't need to be 777, but it does need to be writable by whichever user you've got the crontab running under.

mytinytown

8:40 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



OK Dumb question

I am very new at Linux, so please do laugh to much.

How do I make it writable by the user like you said?

Joe

jollymcfats

9:44 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



The simplest way is to log in as that user and create the file. You can use
touch /var/log/uptime.txt
to create an empty file owned by the current user.

mytinytown

4:03 am on Feb 16, 2005 (gmt 0)

10+ Year Member



It still does not work.

No idea what to do.

00 12 * * * /usr/bin/uptime >> /var/log/uptime.txt

Is what exactly in the crontab -e so it is loaded but will not write.

jollymcfats

7:18 am on Feb 16, 2005 (gmt 0)

10+ Year Member



Does it work if you run it from the shell? (Just the part from /usr/bin... to the end of line.)

Also just use one zero for the time, not double 0.

mytinytown

5:02 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



shell would be running the uptime command, like from Konsole, right? If so, yes it does.

I changed it to 0 instead of 00 and it still does not work.

It just does not seem to be writing the file. I did the touch, but I have to log in as su (root) to do it, so the file is owned by root.

Joe

Edit: Could there be some other way to do this? Or maybe put the uptime.txt someplace else?

jollymcfats

7:29 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



> I did the touch, but I have to log in as su (root) to do it, so the file is owned by root.

You are running this from root's crontab? If running '/usr/bin/uptime >> /var/tmp/uptime.txt' on the command line su'd to root works and the same command in root's crontab does not, I think something else is wrong with your system.

mytinytown

7:32 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



A fresh install of Fedora Core 2 is my system. You think I should upgrade to Core 3 or choose a different one all together, maybe like Debian or something?

mytinytown

1:37 pm on Feb 17, 2005 (gmt 0)

10+ Year Member



Changing my system over to Fedora Core 3