LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   cronjobs in ubuntu (https://www.linuxquestions.org/questions/linux-server-73/cronjobs-in-ubuntu-799521/)

dinakumar12 04-02-2010 01:25 AM

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.

colucix 04-02-2010 01:33 AM

Hi. Maybe this is what you are looking for: https://help.ubuntu.com/community/CronHowto. Did it occur some specific issue about cron?

dinakumar12 04-02-2010 01:50 AM

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.

colucix 04-02-2010 02:06 AM

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".

dinakumar12 04-02-2010 02:18 AM

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.

dinakumar12 04-02-2010 04:33 AM

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.

colucix 04-02-2010 05:07 AM

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


dinakumar12 04-02-2010 05:31 AM

Hi colucix,

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

thanks&regards,
Dinesh.


All times are GMT -5. The time now is 10:58 AM.