Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a perl script running o.k. on unix machines and manually from root user but not from crontab on linux machine:

the problematic command is: su - $user

system("su - togui103 -c \"/home/togui103/RunEnv/scripts/tomcatkill.csh\"");

command on crontab:

23 59 * * * /home/togui103/RunEnv/scripts/tc-rotate.pl > /home/togui103/RunEnv/scripts/tc-rotate.log

please advise.

share|improve this question

2 Answers 2

The first thing to do is to capture the stderr from your script

23 59 .../tc-rotate.pl 2>/tmp/script.log >/home/...

and then examine the log for error messages

EDIT: Responding to the comment:

Entries in crontab have a fairly restricted environment so the environment variables that you list aren't available, You can though set them in your crontab file e.g.

APACHE_HOME=/some/path
CATALINA_HOME=/some/other/path
RUN_ENV=someValue
23 59 * * * /home/togui103/RunEnv/scripts/tc-rotate.pl > /home/togui103/RunEnv/scripts/tc-rotate.log 
share|improve this answer
    
APACHE_HOME: Undefined variable. CATALINA_HOME: Undefined variable. RUN_ENV: Undefined variable. RUN_ENV: Undefined variable. it happen since 'su' is not execute and the script apachekill.csh requires these variables –  Ronen Peer Jun 13 '12 at 8:46

If the variables are set in the scope of your perl script you should try su -m

-m, --preserve-environment do not reset environment variables

Your command can be:

system("su -m togui103 -c \"/home/togui103/RunEnv/scripts/tomcatkill.csh\"");
share|improve this answer
    
hi, I have the same result I tried also: system("su -s \"/home/$user/.cshrc\" -c \"/home/$user/RunEnv/scripts/apachekill.csh\" $user"); it seems that it initialize the variables but don't run the *.csh script –  Ronen Peer Jun 13 '12 at 12:13
    
Does it work outside the perl script if you enter it manually? And could you add the output from "ls -l /home/$user/RunEnv/scripts/apachekill.csh" ? –  macrojames Jun 13 '12 at 12:23
    
yes, if I run the script manually from the root it works (it also works on solaris sparc from the crontab and also on my local linux machine), maybee the problem is related to the machine crontab definitions. –  Ronen Peer Jun 13 '12 at 12:47
    
anyone can help? –  Ronen Peer Jun 21 '12 at 12:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.