Scheduling .sh Script In Crontab

liunx

Guest
Using SSH, my script launches as follows from the command line and it works fine:<br />/home/eproxim/public_html/monitor/convert.sh<br /><br />We want it to run every 5 minutes. In crontab I have it set as follows:<br />5 * * * * /bin/sh /home/eproxim/public_html/monitor/convert.sh<br /><br />It isn't launching. We have several php scripts that work fine from crontab, for example the entry below fires every 30 minutes:<br />30 * * * * /usr/bin/php /home/eproxim/public_html/phpBB2/site_map_announcements_cron_job.php<br /><br />Please let me know how the convert.sh entry needs to be changed in the Advanced (Unix Style) crontab gui.<br /><br />Thanks,<br />Eric<!--content-->
If it works from the command line, but not from the crontab, my guess (without knowing what's in your convert.sh file) is that it could be environment related. The environment your shell has won't necessarily be the same as what a cronjob will have, so you may want to make sure you either have all the correct paths defined in your convert.sh file, or use complete paths for any binaries you are running.<br /><br />If you look in your main account email, are you getting error output from this cronjob that may give a better clue as to why it's failing?<!--content-->
<!--quoteo(post=180236:date=May 24 2006, 05:01 PM:name=TCH-MikeJ)--><div class='quotetop'>QUOTE(TCH-MikeJ @ May 24 2006, 05:01 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=180236"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->If it works from the command line, but not from the crontab, my guess (without knowing what's in your convert.sh file) is that it could be environment related. The environment your shell has won't necessarily be the same as what a cronjob will have, so you may want to make sure you either have all the correct paths defined in your convert.sh file, or use complete paths for any binaries you are running.<br /><br />If you look in your main account email, are you getting error output from this cronjob that may give a better clue as to why it's failing?<!--QuoteEnd--></div><!--QuoteEEnd--><br />I'll list the contents of the convert.sh file here since the script is so short:<br />#!/bin/bash <br /><br />cd /home/eproxim/www/monitor<br />date > convertoutput.txt<br /><br />for x in `pgrep converter.cgi`<br />do<br /> sleep 5<br /> kill $x<br />done<br /><br />That's it, all it does is look for runaway converter.cgi processes and kill them. It sleeps 5 seconds in between so that normal converter.cgi processes have a chance to finish without being killed(normal converter.cgi processes run in a second or less I think).<br /><br />The first 2 lines write to an output file so I can see the last date/time the script ran.<br /><br />I'm not sure how to get to the main account email but if you can help me out by listing the specifics here then I'll check it out. I don't fully understand how the email field works in the Standard Cron Manager gui. I'd like to have an email while we try to get this working but the problem is that if I put an email there then it gets overwhelmed with output from our other cron jobs(we have one that runs every 2 minutes). I wish there was an easy way to assign a different email address to different cron jobs in the gui.<br /><br />Thanks Again for your help,<br />Eric<!--content-->
<!--quoteo(post=180237:date=May 24 2006, 05:28 PM:name=esprague)--><div class='quotetop'>QUOTE(esprague @ May 24 2006, 05:28 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=180237"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->I'm not sure how to get to the main account email but if you can help me out by listing the specifics here then I'll check it out.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />All you should have to do is click on mail in your control panel, select Horde, then look in the inbox. If you get prompted for login at any point, just use your account name (without a domain name) and password as you would when you login to your control panel.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->I don't fully understand how the email field works in the Standard Cron Manager gui. I'd like to have an email while we try to get this working but the problem is that if I put an email there then it gets overwhelmed with output from our other cron jobs(we have one that runs every 2 minutes). I wish there was an easy way to assign a different email address to different cron jobs in the gui.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />If you want to receive the cronjob output in a different email than your main cpanel account, you can change the value of "Please enter an email address where the cron output will be sent:" to be a full email address (such as <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->).<br /><br />Cronjobs in general should not generate output. A good cronjob will only generate output when there's an error. If you do not have the ability for whatever reason to prevent the cronjob from generating output on clean runs, add the following (without quotes) to the end of each cron command that you want to suppress all output for: "> /dev/null 2>&1"<!--content-->
<!--quoteo(post=180239:date=May 24 2006, 05:55 PM:name=TCH-MikeJ)--><div class='quotetop'>QUOTE(TCH-MikeJ @ May 24 2006, 05:55 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=180239"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->All you should have to do is click on mail in your control panel, select Horde, then look in the inbox. If you get prompted for login at any point, just use your account name (without a domain name) and password as you would when you login to your control panel.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />I did this and sifted through 5 pages of junk mail going back to noon today. There were no emails from cron.<br /><br />Earlier when I was experimenting with the scheduling I put my personal email in cron. This goes back to my problem with the Standard Cron Job gui. It seems to ask for an email at a global level applying to all jobs. When my email was there I kept getting an email every 2 minutes due to our php job mentioned earlier but nothing for my sh job.<br /><br />Each email I received had the following subject:<br />Cron <eproxim@dedicated105> /usr/bin/php /home/eproxim/public_html/phpBB2/site_map_recent_posts_cron_job.php <br /><br />and the following body:<br />Content-type: text/html<br /><br /><!--quoteo(post=180239:date=May 24 2006, 05:55 PM:name=TCH-MikeJ)--><div class='quotetop'>QUOTE(TCH-MikeJ @ May 24 2006, 05:55 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=180239"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->Cronjobs in general should not generate output. A good cronjob will only generate output when there's an error. If you do not have the ability for whatever reason to prevent the cronjob from generating output on clean runs, add the following (without quotes) to the end of each cron command that you want to suppress all output for: "> /dev/null 2>&1"<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />I'll add "> /dev/null 2>&1"(w/out the quotes) to the end of the php listings in cron and change the email to my personal again to see if we get anything for the .sh entry.<!--content-->
I changed it to run every minute while I sort things out. I got some emails with the following:<br />/home/eproxim/public_html/monitor/convert.sh: line 4: convertoutput.txt: Permission denied<br /><br />Here is line 4: date > convertoutput.txt<br /><br />I did a chmod from ssh to fix the permission problem: chmod 777 convertoutput.txt<br /><br />Next I changed the scheduling to every 2 minutes.<br /><br />I think everything is ok now.<br /><br />Thanks for all your help TCH-MikeJ, I really appreciate it <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Glad to see you got it working. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
Welcome to the forum, esprague. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums esprague!<!--content-->
Welcome to the forum, esprague<!--content-->
Welcome to the forums, esprague! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums, esprague <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
 
Back
Top