MaMu
MaMu

Reputation: 1869

Not able to execute script from crontab

I am able to execute scrip from command line. I'm executing it like this:

/path/to/script run

But while executing it from cron like below, the page is not comming:

55     11 * * 2-6   /path/to/script.pl run   >> /tmp/script.log              2>&1

The line which is getting a webpage uses LWP::Simple:

my $site = get("http://sever.com/page") ;

I'm not modyfing anything. The page is valid and accessible. I'm getting enpty page only when I execute this script from crontab. I am able to execute itfrom command line! Crontab is owned by root. And job is executed as root.

Thanks in advance for any clue!

Upvotes: 1

Views: 110

Answers (2)

ikegami
ikegami

Reputation: 385496

If it's not a difference in environment variables (e.g. those that specify a proxy to use), I believe you are running afoul of SElinux. Among other things, it prevents background applications (e.g. cron jobs) from accessing the internet unless you explicitly allow them to do so. I don't know how to do so, but you should be able to find out quite easily.

Upvotes: 0

Michael
Michael

Reputation: 3729

It's difficult to say what might be causing this, but there are differences between your environment, and the environment created by crontab.

You could try running it through a shell with appropriate args to construct your user environment:

55 11 * * 2-6 /bin/tcsh -l /path/to/script.pl run >> /tmp/script.log 2>&1

I'm assuming you are running it by cron with your own user ID of course. If you aren't, then obviously you should try running it manually with the user ID that cron is using to run it.

Upvotes: 1

Related Questions