Cron Jobs

Discuss Applications

Cron Jobs

Postby agent007 » Sat May 31, 2003 12:54 am

hi all,

If I do a crontab -e in root and add a job, will the job run for ALL the users in the system or will it run only for the root user account?

thanks,
007
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Void Main » Sat May 31, 2003 7:39 am

The job will be executed under the root user, just as if you did it manually as root.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby agent007 » Sat May 31, 2003 8:18 am

So, how do I make it run for all users? I mean system wide?

thanks
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Void Main » Sat May 31, 2003 1:10 pm

Can you give me an example of what you want to do? I can't think of a reason you would ever need to do this.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby agent007 » Sat May 31, 2003 2:49 pm

I am using a script to sync the time.....(dont want to use NTPD), so the script should run at specific time.

If I give a cron for that in the r00t account, then the script will run only when the r00t user is logged in. It should run irrespective of the logged in user. Hence, system wide..

007
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Void Main » Sat May 31, 2003 2:54 pm

I don't think you understand what "cron" does. "cron" runs irregardless of a user being logged in. You submit a job to cron to run a job at a specific recurring time/date under a specific userid, it makes no difference as to whether the user is logged in.

As far as synching the system time, only root can do that anyway and the system time is not user specific. You don't even need a script, you could just execute the command "ntpdate -b -s servername" in a root cron job so it runs once a day or so:

0 2 * * * /usr/sbin/ntpdate -b -s ntp.tuxfamily.net

would sync your time every day at 2:00am to ntp server ntp.tuxfamily.net.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby agent007 » Sat May 31, 2003 11:05 pm

Yes....This is what I wanted to know. So, all I do is login as r00t, do a crontab -e, dump in that one line to sync the time, save and logout........

007 8)
agent007
administrator
administrator
 
Posts: 254
Joined: Wed Feb 12, 2003 11:26 pm

Postby Void Main » Sun Jun 01, 2003 3:27 am

You can just:

$ su
# crontab -e
add the line
# exit

Of course your computer will have to be on at 2:00am for the sync to take place. And if you want it to also update your hardware clock in addition to your system clock then you might want this command:

0 2 * * * /usr/sbin/ntpdate -b -s ntp.tuxfamily.net && /usr/sbin/hwclock --systohc
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA


Return to Applications

Who is online

Users browsing this forum: No registered users and 1 guest

cron