Koozali.org: home of the SME Server

Obsolete Releases => SME 7.x Contribs => Topic started by: JoshuaR on May 12, 2010, 03:51:40 PM

Title: crontab entry help
Post by: JoshuaR on May 12, 2010, 03:51:40 PM
Hi,
I am working on my first SME contrib (slowly  :P) and part of it involves creating a cron job. It does so by creating a file called 20mycontrib in /etc/e-smith/templates/etc/crontab/
the content of the file is:
Code: [Select]
# refresh access list
*/5 * * * * root /path/to/script.sh
as a test, I run
Code: [Select]
expand-template /etc/crontab which if I then
Code: [Select]
cat /etc/crontab I can see my entry formatted correctly etc, but for some reason it just doesn't run. I think my cron sytax is right (above should run every 5 min?) and if I manually run the script it runs fine.
Can anyone point out where I'm going wrong?

--Josh R
Title: Re: crontab entry help
Post by: Stefano on May 12, 2010, 04:02:28 PM
check cron's log

I bet a beer the problem is in your script ;-) (hint: paths and environment variables)
Title: Re: crontab entry help
Post by: JoshuaR on May 12, 2010, 04:06:55 PM
Quote
check cron's log
ahh, sometimes the most obvious things slip past :P
I'm getting:
Code: [Select]
May 13 00:00:01 hostname crond[7647]: (root) CMD (/path/to/script.sh^M)
I'm not sure where it's pulling the
Code: [Select]
^M from
Title: Re: crontab entry help
Post by: cactus on May 12, 2010, 04:11:42 PM
ahh, sometimes the most obvious things slip past :P
I'm getting:
Code: [Select]
May 13 00:00:01 hostname crond[7647]: (root) CMD (/path/to/script.sh^M)
I'm not sure where it's pulling the
Code: [Select]
^M from
My guess it is in your template fragment somewhere. Did you check that already?
Title: Re: crontab entry help
Post by: JoshuaR on May 12, 2010, 04:15:16 PM
Thanks heaps! That was it, in my template fragment I had two line 'line breaks' after the cron entry.
I had checked it, I just didn't realize that it would cause a problem.

Cheers,
Josh R
Title: Re: crontab entry help
Post by: cactus on May 12, 2010, 04:19:41 PM
Thanks heaps! That was it, in my template fragment I had two line 'line breaks' after the cron entry.
I had checked it, I just didn't realize that it would cause a problem.
Most likely it has nothing to do with a two line line break. My guess is that one of them was a special non printable character.
Title: Re: crontab entry help
Post by: Stefano on May 12, 2010, 04:21:15 PM
Most likely it has nothing to do with a two line line break. My guess is that one of them was a special non printable character.

me too
Title: Re: crontab entry help
Post by: JoshuaR on May 12, 2010, 04:23:00 PM
I've been using Notepad++ as my editor...I wonder if that maybe did it? In viewing the file the two extra lines didn't seem to contain anything.

Edit: When I removed the extra line I used vi   as soon as I edited the file with Notepad++ and applied it again, it appended that ^M  .
Thanks guys.

(on that note, can you recommend a good editor--I'm worried about the integrity of the rest of my contrib now :P )
Title: Re: crontab entry help
Post by: Stefano on May 12, 2010, 04:44:07 PM
use your favourite editor in SME's console ;-)
Title: Re: crontab entry help
Post by: cactus on May 12, 2010, 05:58:44 PM
I've been using Notepad++ as my editor...I wonder if that maybe did it? In viewing the file the two extra lines didn't seem to contain anything.

Edit: When I removed the extra line I used vi   as soon as I edited the file with Notepad++ and applied it again, it appended that ^M  .
Thanks guys.

(on that note, can you recommend a good editor--I'm worried about the integrity of the rest of my contrib now :P )
AFAIK Notepad++ is a good, but extensive editor. It might be that you do not have the document format set properly. Under encoding you set the encoding type, not sure what it should be for SME Server though.

But as others said there are plenty of editors on your SME Server/linux box that will do the trick as well. :-D
Title: Re: crontab entry help
Post by: JoshuaR on May 12, 2010, 06:56:41 PM
I still find it quicker to navigate an editor with a (dare I say 'GUI' in a linux forum?)  :grin:
Thanks for the advice guys  :!:
Title: Re: crontab entry help
Post by: timn on May 12, 2010, 08:03:32 PM
^M is a carriage return so probably saved the file in MSDOS/Windows format with a CR/LF pair to start new lines

Goto View -> Show Symbol -> Show End of Line (or Show All Symbols) to see what is being saved.

Also use Edit -> EOL Conversion -> Unix Format to save with just LF at the end
Title: Re: crontab entry help
Post by: JoshuaR on May 12, 2010, 11:56:39 PM
Cheers, that's worked.

--Josh R
Title: Re: crontab entry help
Post by: Stefano on May 13, 2010, 12:20:49 AM
Cheers, that's worked.

--Josh R

I forgot: I've lost my bet.. you have a virtual beer payed ;-)
Title: Re: crontab entry help
Post by: JoshuaR on May 13, 2010, 02:27:05 AM
 :pint:
cheers