LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-21-2011, 12:07 PM   #1
r_jr
Member
 
Registered: Feb 2006
Distribution: Ubuntu
Posts: 66

Rep: Reputation: 0
Question cron script for all users


I was wondering how to setup cron to execute a script for all users. Or do I have to set it up for each individual user.
 
Old 11-21-2011, 12:50 PM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by r_jr View Post
I was wondering how to setup cron to execute a script for all users.
simply by editing the global cron job table /etc/crontab.

Quote:
Originally Posted by r_jr View Post
Or do I have to set it up for each individual user.
No. Actually, for quite a long time I didn't know that cron jobs can be set per user. I only new the global /etc/crontab.

[X] Doc CPU
 
Old 11-23-2011, 02:40 PM   #3
r_jr
Member
 
Registered: Feb 2006
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Doc CPU View Post
Hi there,



simply by editing the global cron job table /etc/crontab.



No. Actually, for quite a long time I didn't know that cron jobs can be set per user. I only new the global /etc/crontab.

[X] Doc CPU
Well, I tried adding the job to the /etc/crontab file, but now it does not run at all.
 
Old 11-23-2011, 03:34 PM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Where did you find/read about the option to add jobs to /etc/crontab file ?

It's the directory /etc/cron.daily or /etc/cron.hourly or whichever you want to put the script into
so that executes at desired intervals.
Check the /etc/cron.daily files within and make your script as that inside.
Put your script there and it will run (presuming service crond is running?)

Another way of doing it is edit the crontab file from Root account
with: crontab -e
and putting the line for executing your script at desired time/intervals.

Last edited by lithos; 11-23-2011 at 03:36 PM.
 
Old 11-23-2011, 03:56 PM   #5
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by lithos View Post
Where did you find/read about the option to add jobs to /etc/crontab file ?
I don't remember - it's the way I've always done it. For years. And it has worked ever since. Simplest method of all, IMHO.

Quote:
Originally Posted by lithos View Post
Another way of doing it is edit the crontab file from Root account
with: crontab -e
and putting the line for executing your script at desired time/intervals.
Yea, but in effect, that does nothing else than editing /etc/crontab. [EDIT: Yes, it does something else: It edits user root's crontab, rather than the global one.] So why do it more complicated than necessary? Why not directly edit the config file?

[X] Doc CPU

Last edited by Doc CPU; 11-24-2011 at 10:07 AM.
 
Old 11-24-2011, 06:14 AM   #6
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by Doc CPU View Post
Yea, but in effect, that does nothing else than editing /etc/crontab. So why do it more complicated than necessary? Why not directly edit the config file?
Have you tried to run command:
Code:
crontab -l
what does it show you ?
Mine is:
Code:
root@~#>crontab -l
# This set of options gives you additonal mail options
# If any dont apply to you, please remove from list.
#!mail(yes),noticenotrun(yes)

# All mails will be sent to root
#!mailto(root)

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin

# Run-parts
01 * * * * run-parts /etc/cron.hourly
02 0 * * * run-parts /etc/cron.daily
22 0 * * 0 run-parts /etc/cron.weekly
42 0 1 * * run-parts /etc/cron.monthly

# * */8 * * * htpdate -s -l www.linux.org
# * */6 * * * hwclock --systohc
And if you look at your file: /etc/crontab ?
Code:
cat /etc/crontab
Mine is:
Code:
root@~#>cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
Are the outputs the same ?

Can you please tell me the difference now (besides the Root's crontab is different than /etc/crontab, because ROOT runs some scripts) ?

Last edited by lithos; 11-24-2011 at 06:18 AM.
 
Old 11-24-2011, 06:37 AM   #7
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by lithos View Post
Have you tried to run command:
Code:
crontab -l
what does it show you ?
it tells me:
Code:
no crontab for root
And that's logical, in a way, because I didn't create a crontab for the root user, only the global, non-user-specific one that was automatically created during the system setup.

Quote:
Originally Posted by lithos View Post
And if you look at your file: /etc/crontab ?
Then I see a list of all the system-wide cron jobs, plus the generic cron.hourly, cron.daily etc:

Code:
root@spine / :cat /etc/crontab
# for vixie cron
# $Header: /var/cvsroot/gentoo-x86/sys-process/vixie-cron/files/crontab-3.0.1-r4,v 1.2 2009/05/12 09:13:46 bangert Exp $

# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
59   *  * * *  root  rm -f /var/spool/cron/lastrun/cron.hourly
9    3  * * *  root  rm -f /var/spool/cron/lastrun/cron.daily
19   4  * * 6  root  rm -f /var/spool/cron/lastrun/cron.weekly
29   5  1 * *  root  rm -f /var/spool/cron/lastrun/cron.monthly
*/10 *  * * *  root  test -x /usr/sbin/run-crons && /usr/sbin/run-crons
*/15 *  * * *  root  fetchmail -f /etc/fetchmail-gmx-net-rc      >> /server/mail/gmx.net.log
  [ more cron jobs listed ]
root@spine / :
That's quite similar to your sample.

Quote:
Originally Posted by lithos View Post
Are the outputs the same ?
Of course they're not.

Quote:
Originally Posted by lithos View Post
Can you please tell me the difference now (besides the Root's crontab is different than /etc/crontab, because ROOT runs some scripts) ?
The difference is that one is user-specific by design (albeit for root), the other isn't. That's why, for example, the system-wide crontab has a field for each cron job that specifies the user under which the job shall execute, while the user-specific crontabs don't have that field.

[X] Doc CPU
 
Old 11-24-2011, 12:40 PM   #8
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
thank you, now I know how sys/wide and user cron's.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron appears to be messed up (E: cron: subprocess post-installation script returned e bujutsukai Linux - Newbie 1 07-24-2008 03:39 AM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
help: using cron + my bash script --> don't want mail from script beeblequix Linux - General 7 11-23-2007 09:25 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration