LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   crontab job (https://www.linuxquestions.org/questions/linux-software-2/crontab-job-462285/)

Thulemanden 07-09-2006 04:35 AM

crontab job
 
Will it work saving a file named 'crontab' using any text editor with the content

1 * * * * webalizer

in path /var/spool/cron/crontabs/

I want webalizer to run every hour a minute 1

Will it produce too many log lines?

Will

* 17 * * * webalizer

run it a 17:00 hrs each day?

I use this as source:
http://www.adminschoice.com/docs/crontab.htm

trev_vb 07-09-2006 05:11 AM

In answer to question #1 ("Will it work saving ...)
The best answer I can give is "Probably not, and even if it does wok, it might not give you _exactly_ what you EXPECTED".

Your login tag states that you're using Xandros (and this is, afterall, the slackware forum). Having said that, you're _probably_ using the same cron we all use.
Technically speaking, the _correct_ way to install a cron job is to use the crontab(1) command. (I would stronly urge you to do a "man crontab" sometime soon and read it).

Basically, cron is a process that schedules tasks to run at specific times. Perhaps most importantly of all though is that cron _ALSO_ specifies which user-id the task runs as and thus the scheduled task will 'inherit' all the permissions / capabilities of that nominated user.

By manually creating a file as /var/sppol/cron/crontabs/crontab (that _is_ what you were stating afterall), then you're creating an entry in the task schedule to run the task using the permissions / capabilities of a user named "crontab" (that being the name of the file in question). If you don't _have_ a user named "crontab" on your system, then your results will be at best unpredictable, and at worst, no results at all other than a line in your system error log.

If you created the file in your home directory instead (let's say you called it 'cron.job' and then submitted it to the cron scheduler with the command:
crontab cron.job
It would create the relevant file for you in /var/spool/cron/crontabs (naming it using YOUR login name, and giving the file relevant permissions).
This job would run the program named 'webalizer' at 1 minute past the hour on EVERY hour of EVERY day and the program would inherint *YOUR* login credentials.

Now here's a few potential 'gotchas' that you should be aware of
1: Since you've not specified a FULL pathname to the application to be run, cron will search through its $PATH hierarchy and run the first one it finds. Thus, it becomes potentially 'easier' for some a$$hole to create a 'rogue' program in a directory that is higher up in your path hierarchy and cron will dutifully run HIS / HER program instead of yours. (Therefore, I would suggest you might want to fully path the application to run from the cron job).
2: I'm guessing that webalizer is a process to extract summary data from your webserver, I am surmizing that *YOUR* login probably doesn't have the necessary permissions to access the relevant log files in order for webalizer to run. (Or at least I *HOPE* your doesn't?... You don't login as root do you?) Therefore, you might wish to have this cron job submitted to the scheduler as some OTHER username [RTFM on crontab as mentioned above, specifically the "-u" switch]. I'd try to AVOID running the job as root unless you ABSOLUTELY HAVE TO (due to the implicit security considerations). The user that the web service itself runs as should be ideal for the job.

Now, to your 2nd question... (re running a job at 17:00 hrs each day)
The sample you've given would run the task at 17:00, then again at 17:01, then again at 17:02 (etc etc) until 17:59 (i.e. 60 times in total)
What you probably _WANT_ instead is something like this:
0 17 * * * webalizer
The explicit coding of 0 for minutes means it runs ONLY at 17:00 (and not the other 59 minutes). The process is started once per day every day (and it will run for as long as it takes, so if it is still running at 17:01, don't be worried)

HTH,

TvB

Thulemanden 07-09-2006 06:57 AM

Thank you very much.

I have included the path and put in the zero, saved the file as crontab.job and run 'crontab crontab.job'

That was the easy part. I'll look at the user issue.

Actually, the labtop web server is running DSL with Firestarter.
I'm writing from my main PC carrying PC-BSD :-)

A Windows XP is seldom turned on any longer. :-)))

Thanks again.


All times are GMT -5. The time now is 07:12 AM.