The cron strikes back

I’m still finding that I have mail from cron each time the job executes. I believe I may have found the answer this time. I was originally writing the output of the last command to a null pointer. I went ahead and made sure that all commands calling php5 are now writing to nothing.

This then left me with just one error in my mails. Something about an unterminated string value. I couldn’t find any strings that were not closed. I went ahead and found that I could remove the quotes everywhere since I wasn’t using any spaces. When I did this, I found that it was now complaining about an unknown sle command. AH HA! Apparently there is a limit to the length of my commands

I started scratching my head and started to look around. I tried to look for a way to use batch scripts at first, but it looked like I needed to play around with chmod and grant execute permissions on a text file. I noticed some examples used logic to loop through files. I hunted for a way to perhaps throw in some logic for my commands. It wasn’t long before I found a beginners guide to Linux Shell Scripting which helped demonstrate how to use the “for” command. It is very similar to how I program in JavaScript, C#, PHP, LSL, JAVA, etc. Here is one of my tests that I ran directly from the command line:

for((i = 0; i < 5; i++)) do echo $i; sleep 1; done

Using a loop, I was able to get 39 commands trimmed down to about 10 percent of their initial size.

It’s not always a perfect world though. As I find things that appear to work, I often find that they don’t work as expected. Even though my tests worked directly on the command line, I’m still getting feedback from the cron manager about problems. The latest one is “/bin/sh: Syntax error: Bad for loop variable”.

This latest error indicates that there are different interpretors that don’t understan the script in the same way as others. The crontab appears to run things in a different context then the command line itself. I’m running back looking at batch files again (shell scripts), because the first line allows you to identify which interpretor to use when processing the scripts. It’s plenty of techno babel I suppose, but I’m determined to find a working, proper solution to this problem.

posted by Dedric Mauriac on Applewood using a blogHUD : [blogHUD permalink]

Comments are closed.

%d bloggers like this: