Cron Job
Hi All,
actually i have never set up a cron job. i have created a script which will take up the backup. please tell me step by step how can i set cron job. Thanks, Chetan |
First you have to check if the cron daemon is running and if you as a user are allowed to run cron jobs, but don't worry too much, since Linux enables that by default (just check if something doesn't work). To write your own crontab you will issue the command
Code:
crontab -e For the format of a crontab line, that is how to specify a cron job see Code:
man 5 crontab |
help in cron file
Hi All,
I have created a script to take backup. when i run this script using the browser it will work fine and create tar.gz files but when i try to run this using the command line in Linux it will display a error: tar: Removing leading `/' from member names now what to do to solve this problem. my script code is below ###### script code start here ############# $sdate = date("d_m_Y_H_i_s"); $back_path='/home/sites/htdocs/chetan/back/'; $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 -h192.168.10.92 -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/"); ###### script code end here ############# Regards, Chetan |
cron job help
Hi All,
I have written this line in >> crontab -e 0 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php it this work? actually i want to run cron job every 15min or hourly. please help me out Thanks, Chetan |
1. You need to specify shebang line to get the script executed on its own. Do something like:
Code:
> which php Code:
#!/usr/bin/php Code:
0 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php >/dev/null Code:
0,15,30,45 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php >/dev/null |
Further to this. Hourly/daily/monthly/weekly scripts can be executed by placing them in /etc/cron.hourly or other respective directories.
|
Quote:
Code:
0,15,30,45 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php >/home/sites/htdocs/chetan/backuptest/create_zip.log 2>&1 |
A few quick points to note:
When you are executing a script from cron, you should be careful to expand all paths in your script. You might be running the script from a location where you have all the files needed and the script might execute just fine from the command line. But when you put it in the cron file , it will fail. This is a common mistake we do. To run a cronjob every 15 minutes another way would be : */15 * * * * /home/sites/htdocs/chetan/backuptest/create_zip.php >/home/sites/htdocs/chetan/backuptest/create_zip.log 2>&1 The first meathod would not be very easy to use if say for example you want to run it every 5 minutes. So use a */5 and you will get it executed every 5 miutes. |
All times are GMT -5. The time now is 10:57 PM. |