Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
12-03-2009, 07:11 AM
|
#1
|
Member
Registered: Nov 2009
Location: India
Posts: 32
Rep:
|
How to create a cron job and run it ,give simpleexample
Hi,
How create a cron job in terminal,
and how to run it.
Please give a simple example
Thanks
Ramakrishnan
|
|
|
12-03-2009, 07:14 AM
|
#2
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
|
|
|
12-03-2009, 07:19 AM
|
#3
|
Member
Registered: Sep 2008
Location: Perth, Australia
Distribution: RedHat, Solaris
Posts: 38
Rep:
|
Example
Hi Ramakrishnan,
firstly when you want to create/edit your crontab file type the following.
This will open the crontab to edit and will run a check on the cron job for errors when you go to save it.
Here's a simple example.
This line executes the "find" command at 2AM on the 12th of every month that a Sunday or Saturday falls on.
Code:
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * 0,6 /usr/bin/find
I stole this example from here: please check it out for more...
http://www.pantz.org/software/cron/croninfo.html
Good Luck
|
|
|
12-03-2009, 07:19 AM
|
#4
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
Assumptions:
Script you want to run: foo.sh
When: daily 12:15
From the terminal:
crontab -e (a editor session is started)
Add: 15 12 * * * /full/path/to/foo.sh
Save and exit editor.
Done.
Look at man 5 crontab for the explanation of the 15 12 * * * (minutes, hours, monthday, month, weekday ) notation.
Hope this helps.
|
|
|
12-03-2009, 07:36 AM
|
#5
|
Member
Registered: Nov 2009
Location: India
Posts: 32
Original Poster
Rep:
|
Hi,
Thanks to all
when i type crontab -e on terminal it gives
/var/spool/cron/crontabs/node2: Permission denied
|
|
|
12-03-2009, 07:43 AM
|
#6
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
You (the user executing the crontab -e command) must have crontab access.
I'm not sure if this is true for all distro's but have a look at /etc/cron.allow, the user should be added there (you need root access to change that file).
Hope this helps.
Oh, just remembered: The user should not be present in /etc/cron.deny.
|
|
|
12-03-2009, 07:49 AM
|
#7
|
Member
Registered: Nov 2009
Location: India
Posts: 32
Original Poster
Rep:
|
in my ubuntu
/etc/cron.allow is not found
and also when type sudo su in terminal
it shows
sudo: must be setuid root
and i can't install new packages why?
|
|
|
12-03-2009, 07:55 AM
|
#8
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
I'm not an Ubuntu user, but it looks like something was not installed correctly (the setuid thingy). Maybe an Ubuntu user can help you with that one.
You can create the /etc/cron.allow yourself (as root). It expects one user per line.
Hope this helps.
|
|
|
12-03-2009, 07:59 AM
|
#9
|
Member
Registered: Nov 2009
Location: India
Posts: 32
Original Poster
Rep:
|
Quote:
Originally Posted by druuna
Hi,
You can create the /etc/cron.allow yourself (as root). It expects one user per line.
|
How to create it druuna?
|
|
|
12-03-2009, 08:09 AM
|
#10
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
From the terminal, as root user:
vi /etc/cron.allow
Once it opens press i (for insert) and type the username that needs cron access.
Press esc (escsape, you will taken out of insertion mode)
Press: :wq this will write (w) the file and quit (q), don't forget the leading :
Last thing to do is to change the permissions of this file:
chmod 600 /etc/deny.allow
You can cat the file to see if it is ok: cat /etc/cron.allow. You should see the user that was added.
Hope this helps.
Last edited by druuna; 12-04-2009 at 02:31 AM.
Reason: Fixed a typo (g -> q)
|
|
|
12-03-2009, 06:56 PM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,405
|
Actually
:wg
should be
:wq
although it's quicker to do
:x
you'd need to be root to edit cron.allow or cron.deny.
In Ubuntu you should be able to do something like
sudo su -
to become root. If that doesn't work, show us the err msgs you get.
/rant
I REALLY hate the way Ubuntu has messed with the std sudo & su setup that the rest of the *nix world has always used!
end_rant/
|
|
|
12-03-2009, 11:20 PM
|
#12
|
Member
Registered: Nov 2009
Location: India
Posts: 32
Original Poster
Rep:
|
Hi,
When i type vi/etc/cron.allow
result is
bash: vi/etc/cron.allow: No such file or directory
|
|
|
12-03-2009, 11:26 PM
|
#13
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,405
|
You missed the space between the cmd and the param
vi /etc/cron.allow
http://rute.2038bug.com/index.html.gz
|
|
|
12-04-2009, 12:59 AM
|
#14
|
Member
Registered: Nov 2009
Location: India
Posts: 32
Original Poster
Rep:
|
Hi,
when i type vi /etc/cron.allow
and pressed i
then typed root
then esc pressed then i typed :wq
then esc
it shows
"/etc/cron.allow"
"/etc/cron.allow" E212: Can't open file for writing
why
|
|
|
12-04-2009, 02:38 AM
|
#15
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
2 things:
1) You don't need to put the root user in the cron.allow file, root is all powerful. I initially thought you were talking about a normal user.
2) Another way of putting the username into /etc/cron.allow (as root):
echo "username" >> /etc/cron.allow
After that, just in case:
chmod 600 /etc/cron.allow
Hope this helps.
|
|
|
All times are GMT -5. The time now is 11:44 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|