Forum Moderators: bakedjake

Message Too Old, No Replies

Can you help me with my CRON job?

Want to call an app once per minute

         

trillianjedi

12:24 pm on Oct 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've always found CRON a bit user-unfriendly. I understand the basics, but always seem to get this wrong somehow so thought I'd come and ask if I'm doing this right.

I want to call a binary app, call it "/home/jedi/trillian" once a minute, every hour, every day, every week etc.

I have my editor set to nano (I can hear the hisses, but I don't use *nix enough to really know Vi all that well ;-)).

So, I do:-

crobtab -e

Which brings up my current schedule list in nano. As I understand it, the first 5 fields refer to minutes/hours/day of week/weeks/user etc, with asterisks as wildcards.

So to call my app once per minute I think what I need to add is this:-

01 * * * * /home/jedi/trillian

So I add that, exit nano saving changes.

Then a crontab -l will list my jobs just to make sure that it's in there.

Is that it? Or do I need to tell CRON to reload it's schedule list or anything else?

Also, does my CRON entry look right?

This is in roots CRON schedule, so I do the crontab -e while logged in as root. My application needs to be run as root. Do I need to specify that, or as it's roots cron sched anyway, can I leave it?

The applications rights were set with a "chmod u+x trillian", while logged in as root.

Many thanks,

TJ

zCat

12:36 pm on Oct 30, 2005 (gmt 0)

10+ Year Member



01 * * * * /home/jedi/trillian

The "01" means here the first minute of every hour. Use */1 instead, e.g:

*/1 * * * * /home/jedi/trillian

(I believe "* * * * * /home/jedi/trillian" would also mean every minute).

Everything else should work as you describe.

trillianjedi

12:54 pm on Oct 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks zCat.

I think that explains my confusion with CRON actually.

The "minutes" field is actually "minutes past the hour".

Makes sense to me now!

I presume the "* * * * *" works because CRON itself is triggered once every minute?

Thanks,

TJ

zCat

2:40 pm on Oct 30, 2005 (gmt 0)

10+ Year Member



I presume the "* * * * *" works because CRON itself is triggered once every minute?

Yes, I believe that's the case (I didn't know that myself until recently; I still prefer to set the value explicitly though, it makes the intention behind the entry a little clearer).

trillianjedi

3:48 pm on Oct 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm - I have a further problem now.

It seems that CRON doesn't recognise Roots environment variables, so the app is failing.

I can't find a way to set user prefs/variables. Is there a way to tell CRON to use Roots env variables, or can I set it in a bash script somehow?

Basically, I need roots CRON schedule to work just as if I'm executing apps from shell.

Thanks,

TJ

Leosghost

4:43 pm on Oct 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hope you are running this on something at your home in the attic ;)..on a host server elswhere your host would have cow at one cron per minute ..you'd be up for the "overuse of CPU" email within your first 24 hours ..:)

trillianjedi

5:02 pm on Oct 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm testing locally, but I want to run this live on the hosted server once per minute. The app doesn't actually do much - CPU useage will be very low, it just needs to do it frequently.

I'm not sure what an "overuse of CPU" email is though? It's my server, surely I can do what I like with the CPU? Any host that sent me an email like that would not remain my host for very long ;-)

I'm still having problems setting the environment variables - really I want CRON to act just as bash does when I'm logged in as root at the command line via SSH.

TJ

Romeo

11:43 am on Oct 31, 2005 (gmt 0)

10+ Year Member



There are several crontabs, each user can have its own.

If you want stuff run out of the root crontab, then start the "crontab -e" from the root user. That's for the user context (permissions, etc).

If you need the user's login envorinment, then try this:
* * * * * /path/to/bash --login -c "/your/script"

Caution advised with scripts to be run by root: set the file permissions to /your/script very tight (owner root:root, -rwx------), so that other users can not run in root context what they want by just appending own stuff to your script!

Regards,
R.

trillianjedi

11:57 am on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Romeo - that's exactly what I needed.

Leosghost - I think I worked out what you meant about CPU useage emails - but I'm sure that you're talking about shared virtual hosts? Mine are all dedicated - so I'm pretty sure that I can do what I like with them.

TJ

Leosghost

2:33 pm on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah TJ ..

I was refering to multi user machines ..:) I used to have an incredible problem when I was hosting people ..they'd see the cron button in cpanel ..think "what does this do" .."lets see/play" ..and the server would just sit down and sulk ..( of course the non "playing" clients on the same machine would be overjoyed at the speeds )..and I would get the emails then ..rapidos!

Even when it was written up clear "if you don't know what you are doing in cron don't do anything" they still did!

I wonder what it is about "don't touch" notices ..

"eve" complex? :)