LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron Job Problem (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-problem-697234/)

chetansharma_softeng 01-14-2009 07:36 AM

Cron Job Problem
 
Hi All,

I am facing the problem, i am putting what i have done:

This is my script( create_zip.php)
##### create zip file code start here ######
#!/usr/local/php5
<?php

$sdate = date("d_m_Y_H_i_s");

$back_path='/home/sites/htdocs/chetan/backuptest/';
$target_path='/home/sites/htdocs/chetan';


$db_script_name = $back_path."testnewdb_".$sdate.".sql";

$code_sugar = $back_path."sugarCRM_".$sdate.".tar.gz";

/*shell_exec("mysqldump -h<myhostname> -usharma -psharma testnewdb > $db_script_name");
shell_exec("tar -czf $db_script_name.tar.gz $db_script_name");
shell_exec("rm -rf $db_script_name");

shell_exec("tar -czf $code_sugar $target_path/sugarCRM/");*/

shell_exec("mysqldump -h<myhostname> -usharma -psharma testnewdb > $db_script_name");
shell_exec("zip -r $db_script_name.tar.gz $db_script_name");
shell_exec("rm -rf $db_script_name");

shell_exec("zip -r $code_sugar $target_path/sugarCRM");
?>

##### create zip file code end here ######

and my crontab file is having the following details
# m h dom mon dow command
0,01,02,03 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php >> /dev/null 2>&1


Now please tell me where i am wrong

how can i check my cron job is running or not because it's putting me back.

Regards,
Chetan

repo 01-14-2009 07:41 AM

Quote:

how can i check my cron job is running or not because it's putting me back
I don't understand your question.

Does the script work when you execute it?
look in /home/sites/htdocs/chetan/backuptest/ if the files are made?

colucix 01-14-2009 07:47 AM

First check the system logs, for example /var/log/cron or /var/log/messages and check for entries like
Code:

Jan 11 07:30:01 linux crond[14672]: (username) CMD (/home/sites/htdocs/chetan/backuptest/create_zip.php >> /dev/null 2>&1)
if the cron jobs is executed and something has gone wrong, strip out the redirection of standard output and standard error from the cron entry and wait for it run again. Then check the mail of the crontab owner (using the mail command from a terminal) since it is the place where the cron daemon sends stdout and stderr by default (if not redirected elsewhere).

Regarding this specific issue, I found an interesting article here. Hope this helps.

repo 01-14-2009 07:53 AM

Quote:

0,01,02,03 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php >> /dev/null 2>&1
When do you want your cronjob to run?

chetansharma_softeng 01-14-2009 07:59 AM

Cron Job
 
yes my script is running when i run my script using the command prompt

i am using this command to run the script from command prompt
php create_zip.php

the above command create two tar.gz files in the

/home/sites/htdocs/chetan/backuptest




Quote:

Originally Posted by repo (Post 3408266)
I don't understand your question.

Does the script work when you execute it?
look in /home/sites/htdocs/chetan/backuptest/ if the files are made?


chetansharma_softeng 01-14-2009 08:00 AM

for every 1 minute, its just for testing basically i want run cron job dailiy at 1PM IST.

Quote:

Originally Posted by repo (Post 3408277)
When do you want your cronjob to run?


colucix 01-14-2009 08:12 AM

Quote:

Originally Posted by chetansharma_softeng (Post 3408289)
i am using this command to run the script from command prompt
php create_zip.php

So why don't you put the php command (using its full path) in the crontab entry? Have you read the article I linked in post #3 above?


All times are GMT -5. The time now is 03:33 AM.