Forum Moderators: bakedjake

Message Too Old, No Replies

who is cron?

cron job running php

         

freethink

1:57 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



Hi,
I'm in the middle of producing a script that'll write/update some files every night via a cron job.
Basically I only want me and cron to be able to execute the script. What are the permissions necessary on the script?

As it stands I can output the files perfectly but I want to prevent a surfer stumbling on the script and executing it. My problem is that I've read 'the "other" group consists of everyone else -- most imporantly, the web server falls into the "other" category' when I would've expected the server i.e. cron to be USER.

TIA

cyberws

2:14 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



The best way would be to place your script outside of your web directory. Cron can execute a script no matter where it is. So if your site is:

/www/virtual/yourdomain.com/

Then you have your /cgi-bin/,/htdocs/,/logs/ etc simply place your script outside of these folders in your home directory above.

A surfer will not be able to execute this script since they can not access it from the web. If you have shell access you can execute it from shell.

Don't forget to add the necessary command to your cron file (which should be outside your web accessible folders too).

Example:

30 1 * * * perl /full/path/to/backup.cgi

py9jmas

2:19 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



All users (apart from those listed in cron.deny) can submit jobs to be run by cron. Cron runs the scripts as that user.

The best solution probably would be to create a new user. Limit access to your script to this user and add it to that user's crontab. See the manual page for crontab (1) on your system.

freethink

2:27 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



Ahhhhh...thanks for two great and helpful answers guys. I'll probably put it outside the web directory as cyberws suggested.

So just to clarify what py9jmas said - cron isn't 'other' it's the user that sets up the job so setting the script to 700 inside the webdirectory should work?

Cheers

cyberws

2:48 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



Yes that is correct. Each user on a the system can have one cron file which will be execute as that user. In this cron file you can have as many entries as you wish.

Keep mind though the user will need to have the necessary permissions for crons to work. For example if the user doesn't have access to a specific command then it can't access it.

The best protection though is simply locate it outside your web accessible directory both the cgi-bin and htdocs/public_html/whatever HTML is served from.

Good luck.

freethink

2:56 pm on Sep 14, 2004 (gmt 0)

10+ Year Member



Cheers I seem to have a mental block about permissions! Thanks for the invaluable help.