LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 01-14-2009, 08:36 AM   #1
chetansharma_softeng
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Rep: Reputation: 0
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
 
Old 01-14-2009, 08:41 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
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?
 
Old 01-14-2009, 08:47 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
Old 01-14-2009, 08:53 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
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?
 
Old 01-14-2009, 08:59 AM   #5
chetansharma_softeng
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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 View Post
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?
 
Old 01-14-2009, 09:00 AM   #6
chetansharma_softeng
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
for every 1 minute, its just for testing basically i want run cron job dailiy at 1PM IST.

Quote:
Originally Posted by repo View Post
When do you want your cronjob to run?
 
Old 01-14-2009, 09:12 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by chetansharma_softeng View Post
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
scp problem in cron job andreolira Linux - General 9 09-08-2008 05:27 PM
Cron Job Problem imkornhulio Linux - Server 4 08-30-2008 10:50 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron job problem graziano1968 Linux - Software 7 08-27-2005 01:41 AM
Cron Job Problem Corellon Linux - Software 4 08-12-2003 04:27 AM


All times are GMT -5. The time now is 04:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration