LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to create a cron job and run it ,give simpleexample (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-a-cron-job-and-run-it-give-simpleexample-773171/)

ramakrishnankt 12-03-2009 06:11 AM

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

repo 12-03-2009 06:14 AM

A good start would be
http://www.cyberciti.biz/faq/how-do-...-or-unix-oses/

donanap 12-03-2009 06:19 AM

Example
 
Hi Ramakrishnan,

firstly when you want to create/edit your crontab file type the following.

Code:

crontab -e
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

druuna 12-03-2009 06:19 AM

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.

ramakrishnankt 12-03-2009 06:36 AM

Hi,
Thanks to all
when i type crontab -e on terminal it gives

/var/spool/cron/crontabs/node2: Permission denied

druuna 12-03-2009 06:43 AM

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.

ramakrishnankt 12-03-2009 06:49 AM

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?

druuna 12-03-2009 06:55 AM

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.

ramakrishnankt 12-03-2009 06:59 AM

Quote:

Originally Posted by druuna (Post 3778286)
Hi,

You can create the /etc/cron.allow yourself (as root). It expects one user per line.

How to create it druuna?

druuna 12-03-2009 07:09 AM

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.

chrism01 12-03-2009 05:56 PM

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/

ramakrishnankt 12-03-2009 10:20 PM

Hi,
When i type vi/etc/cron.allow
result is
bash: vi/etc/cron.allow: No such file or directory

chrism01 12-03-2009 10:26 PM

You missed the space between the cmd and the param

vi /etc/cron.allow


http://rute.2038bug.com/index.html.gz

ramakrishnankt 12-03-2009 11:59 PM

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

druuna 12-04-2009 01:38 AM

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 08:49 AM.