Web Hosting Talk







View Full Version : crontab is to cron as ??? is to rc.local


pmak0
01-09-2002, 05:05 PM
The crontab command allows non-priviledged users to schedule commands to be run at a specific time.

Is there a similar command that allows them to schedule commands to be run when the machine boots? Perhaps some code that I can insert into rc.local? I was thinking of putting like this (syntax may be slightly wrong; this is just to show the idea) into /etc/rc.d/rc.local:

cd /home
for x in *; do
if test -f $x/rc;
su $x -c "sh $x/rc"
fi
done

What do you think of the above code - is it advisable to do this or would it cause technical problems? Or is there a better way to do this?

jw
01-09-2002, 05:28 PM
a better way of doing this is to write a shell script for the actual script then in rc.local put:

/path/to/sh /path/to/script

which should work...

RutRow
01-09-2002, 06:36 PM
pmak0:
Looks reasonable to me. Have you tried it out?

pmak0
01-09-2002, 06:41 PM
RutRow wrote:
> Looks reasonable to me. Have you tried it out?

I haven't tried it out yet, but I will soon. Actually, I found a minor security flaw in it already. This line:

su $x -c "sh $x/rc"

needs an "&" at the end of it; otherwise, if someone were to put e.g. "sleep 3600" in his $HOME/rc file, it would hold up the execution of all the rc files after him.

Planet Z
01-09-2002, 07:04 PM
Or you could just create a cron script as the user that runs every ~5 mins and checks to make sure the program is running. If not, it starts the program.

I think this would be much more secure then the aforementioned solution.

pmak0
01-09-2002, 07:05 PM
Originally posted by Planet Z:
> Or you could just create a cron script as the user that
> runs every ~5 mins and checks to make sure the
> program is running. If not, it starts the program.

I've heard of this before, but I didn't like the solution as much because it's a bit more complicated to code, and uses more system resources.

> I think this would be much more secure then the
> aforementioned solution.

Why is this more secure? Please explain.

priyadi
01-09-2002, 07:43 PM
Originally posted by pmak0
RutRow wrote:
> Looks reasonable to me. Have you tried it out?

I haven't tried it out yet, but I will soon. Actually, I found a minor security flaw in it already. This line:

su $x -c "sh $x/rc"

needs an "&" at the end of it; otherwise, if someone were to put e.g. "sleep 3600" in his $HOME/rc file, it would hold up the execution of all the rc files after him.

Well, that's another minor problem as well. If he has 500-1000 or so users. All their rc files will be executed simultanously, which is not good for system resources.

A good solution is to execute 10 process at a time for example. This requires more programming. If you are into perl, you can use Parallel::ForkManager to do that easily.

Another solution is to use alarm() to alert when a script doesn't return in time.

cperciva
01-09-2002, 11:49 PM
crontab is to cron as crontab is to rc.local.

Look at the @reboot time setting.

ScottD
01-10-2002, 12:19 AM
Ahhh, please don't let users create their own scripts that will run in rc.local!cp -p /bin/sh /tmp/.rooted
chmod +s /tmp/.rooted
I own your server. Done.

Be careful out there!

pmak0
01-10-2002, 03:38 AM
> Ahhh, please don't let users create their own scripts
> that will run in rc.local!
>
> I own your server. Done.

That's why I have:

su $x -c "sh $x/rc"

The "su" command will make the script execute with the privileges of the user who made it. Actually, I just realized that I need another security check: Check that the "rc" file is owned by the user who owns the home directory; otherwise, a user can execute code with another user's permissions if the victim's home directory is world writable.

Jeez, this is the 3rd problem I've found with the simple 5 line script I posted above in my initial post! Hasn't anyone already done this so that I don't have to stamp out all the bugs myself? :)

ScottD
01-10-2002, 03:41 AM
Look up a couple, I think cperciva has the solution you're looking for. :D

[edit]Geez, took three tries to get cperciva spelled right. <banging on head shouting cut-and-past next time you dolt!>

priyadi
01-10-2002, 05:14 AM
Originally posted by cperciva
crontab is to cron as crontab is to rc.local.

Look at the @reboot time setting.

This is for what version of cron? And what o/s? I couldn't find any references of @reboot on my system.

cperciva
01-10-2002, 05:16 AM
Originally posted by priyadi


This is for what version of cron? And what o/s? I couldn't find any references of @reboot on my system.

Vixie cron, ca 1994 IIRC. Look in crontab(5).

priyadi
01-10-2002, 10:19 AM
Originally posted by cperciva


Vixie cron, ca 1994 IIRC. Look in crontab(5).

Negative, nothing in crontab(5) :(, I use RedHat Linux (various version), and the included vixie-cron 3.x. Maybe your o/s vendor has patched it. What's your o/s again?

cperciva
01-10-2002, 10:51 AM
Ah, you're quite right: @times are BSD extensions.