Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab question

Status
Not open for further replies.

skiflyer

Programmer
Joined
Sep 24, 2002
Messages
2,213
Location
US
I'm stumbling like mad over cron and crontabs, what an unintuitive interface these things have.

First question, can anyone recommend a good tutorial? All I can find online is the same crap over and over about how the crontab file is supposed to look.

Second question, is it possible for one user to load multiple crontab files?

Specifically, I want different commands to load in different home directories.
 
First of all, millions of unix users find the crontab syntax perfectly acceptable.

Second, all I've *ever* read was the crontab man page, which really contains everything you need to know about setting it up. You may try google.

Third,
I want different commands to load in different home directories.
That doesn't make any sense. a) a user only has one home directory. If you want to set your default directory, do it in the script with a 'cd'. b) all commands run no matter what other commands running, that's not very clear, but I can't explain it better.

Cron is just a way of scheduling, 'at this time, run this job'. What does home directory or user or multiple commands have to do with anything?
 
I find it perfectly acceptable and incredibly powerful, just not intuitive.

Yeah, the man page is really where all the useful information has come from.

Ok, so it's not possible, that's all I was asking. It does make sense in my context, but I can adapt to work without it.

Since you ask what home directory has to do with anything... I have several web pages which use includes off of relative paths. I want to run some of these locally using a CLI version of my PHP interpretter. These relative paths are very useful when deploying one script in multiple environments.

So, it sounds like my solution is to
a) Modify all the relative paths to absolute paths
b) Have cron run a script which does a CD to the right directory, then run the php-cli against the script.

Both are perfectly acceptable options of course, but you can see why it would be nice if I could set a working directory (which the home command in cron acts as) directly in the crontab file and avoid the extra script.
 
Not necessarily, on the relative to absolute paths...

You can pass the start directory (better term than "home dir", as that already means something very spedific) as a parameter to the script, or a list of them even, you can just iterate over them, cd to that directory, then run your php that is written to use paths relative the the current dir.

Write a wrapper script that does something like this:

Code:
#!/bin/bash -p

for dir in "$@"
do
    cd $dir
    /run/your/program.php 
done

then you can put call the script like this in your crontab:

00 4 * * * /full/path/to/the/wrapper.sh /dir1 /dir2 /dir3 /etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top