LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-02-2010, 01:25 AM   #1
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Blog Entries: 7

Rep: Reputation: 18
cronjobs in ubuntu


hi,

can anyone provide me the link which consists of the steps to alott cron jobs in ubuntu 9.10 server. i googled for this but can't find any appropriate solution for this.

thanks in advance,
Dinesh.
 
Old 04-02-2010, 01:33 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi. Maybe this is what you are looking for: https://help.ubuntu.com/community/CronHowto. Did it occur some specific issue about cron?
 
1 members found this post helpful.
Old 04-02-2010, 01:50 AM   #3
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
hi colucix,

my problem is my cron process is not getting executed.this is the format i had setup cron job.

18 12 * * * init 6

am i wrong.if it is so, please correct me.

thanks in advance,
Dinesh.
 
Old 04-02-2010, 02:06 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi Dinesh. Your crontab entry states you would like to reboot the machine at 12:18 of every day. Is this correct?

A "problem" is that crontab has a very limited environment (not the same shell environment you get at login). Specifically, the PATH environment variable is limited to /bin:/usr/bin. Since the init command is placed in /sbin, the cron daemon cannot find it. Solution: as a general rule, you have to specify the absolute path of all the commands used in crontab, so that it should read:
Code:
18 12 * * * /sbin/init 6
Furthermore, to check if a cron job has been actually executed, you can look at the logs in /var/log (I don't know which is it exactly on Ubuntu). Finally, take in mind that the standard output and the standard error of your job (if not redirected to a file or to /dev/null) will be sent by mail to the crontab's owner (this is the default behavior): you can try to check the root's mail to see if there is a message from the cron daemon, that most likely inform you about "init: command not found".
 
1 members found this post helpful.
Old 04-02-2010, 02:18 AM   #5
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi colucix,

Thank you very much for your quick reply. As you said we have to mention the path environment, what path have to be mentioned for executing backup command.

thanks in advance,
Dinesh.
 
Old 04-02-2010, 04:33 AM   #6
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi colucix,

the link you have provided is very useful, now i can able to backup my files through cron job by adding the line

PATH=/usr/sbin:/usr/bin:/sbin:/bin

at the top of the cron file.


thanks & regards,
Dinesh.
 
Old 04-02-2010, 05:07 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi Dinesh. Well done! Defining/changing the environment at the beginning of the cron script is another way to workaround the limitations. Note that, if the script calls other scripts you have only to add the export statement:
Code:
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
so that the variable will be inherited from the "parent" (the main script) by its "childs".

In alternative you can "source" a login script, for example:
Code:
. $HOME/.bash_profile
or - better - you can try the -l option of bash (if your cron script is executed by bash) adding it to the she-bang:
Code:
#/bin/bash -l
This means that the shell is invoked as a login shell.

A last note: many insights about the crontab limitations are provided by the following manual pages:
Code:
man 5 crontab
man crontab
man cron
 
1 members found this post helpful.
Old 04-02-2010, 05:31 AM   #8
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi colucix,

Thank you very much. your post is clear to understand,and very helpful. continue your good work.

thanks&regards,
Dinesh.

Last edited by dinakumar12; 04-02-2010 at 05:33 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
CronJobs error archey Linux - Newbie 4 08-22-2009 05:16 PM
Mail for CronJobs! honey bee Linux - Newbie 4 07-07-2008 01:32 PM
some cronjobs don't work xpucto Linux - Newbie 5 05-05-2008 06:25 AM
Cronjobs problem segasieu Linux - Server 2 05-01-2008 10:10 PM
Problem with cronjobs..... freakin'me Linux - General 7 02-11-2006 03:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:31 AM.

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