Crontab works but does not execute script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Crontab works but does not execute script
# 1  
Old 07-09-2008
Crontab works but does not execute script

Hi guys, my first post time here, so hello to everyone Smilie

I've got a problem running one of my scripts at work. I can get crontab working on simple scripts (i.e. one that just outputs date to a temp file). but it won't correctly execute the script i want to use.

My script is a PHP script. It will log into different machines on the network, runs commands, then pipe the output to local files. This script works if executed manually, can't find any faults here. The script itself and the files it writes to have been set to +777 permissions.

The script calls a sub-script, which is an Expect script. I use this to SSH into the various machines on the network. It does not read/write to files. This script's permissions has been set to +777 as well. It runs correctly when manually executed.

Now when I set the crontab job to run, I know that it actually tries to call the script. This is because the call gets logged in the crontab logs (which is located in /var/log/cron). So it calls the script, but i'm not getting any output.

my crontab file looks something like this:

*/10 * * * * /usr/bin/php /absolute/path/to/script.php
0 * * * * /absolute/path/to/script.php

The first line is intended to call the script every 10 minutes. The second line is intended to call the script every hour. They're both the same script (i've just been experimenting with syntax which is why the calls to the script are different).


Any ideas? Thanks in advance for your help, guys!

Last edited by renegadeice; 07-09-2008 at 12:32 PM.. Reason: added crontab file contents
# 2  
Old 07-09-2008
I'm not too familiar with PHP but I think it was:
Code:
php -f file.php

to execute a file?

PN
# 3  
Old 07-09-2008
You should write a shell script that execute your php code...
And remember to set all the variables you need in that script including whole PATH to php...
# 4  
Old 07-09-2008
Hi PN8830,

It might be a syntax issue that you're talking about. '/usr/bin/php /absolute/path/to/script.php' actually works if you type it in a console window. But i'll give the '-f' tag a try and see how it goes (day off today at work, woo hoo!).

To vbe,

Are you referring to defining environment variables inside the PHP script itself? what sort of variables should be defined in the script? As for the whole path to the script, i use a PHP command 'getcwd()' which fetches the absolute path to the script. And I append that to the start of any exec() call.
i.e.
Code:
$cwd = getcwd(); 
exec("$cwd/scriptName.php");

# 5  
Old 07-09-2008
Doesn't the file have to be `chmod +x' 'ed to be PHP executable from the command line?

Regards.
# 6  
Old 07-10-2008
Question Take a look

Smilie
Quote:
Originally Posted by pn8830
I'm not too familiar with PHP but I think it was:
Code:
php -f file.php

to execute a file?

PN
# 7  
Old 07-11-2008
Fixed!

After some debugging I found out that my Expect script was encountering errors which looked like
- "unknown terminal type"

I added the two following lines to my PHP script:
Code:
putenv('SHELL=/bin/bash');
 putenv('TERM=vt100');

That pretty much solved everything. Thanks very much to everyone for their help!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Crontab scheduler to execute script every 45 days

Can someone please help me on how to schedule script to run every 45 days in crontab ? Thanks, Prince (5 Replies)
Discussion started by: prince1987
5 Replies

2. Shell Programming and Scripting

Why my git command has no output in crontab but works well run this script manually?

cat /home/lyang001/update.sh #!/bin/sh #shopt -s expand_aliases HOME_DIR=/home/lyang001/updates UPDATE_MAIL=${HOME_DIR}/updates.mail rm $UPDATE_MAIL -rf cd $HOME_DIR/wr-kernel git log --no-merges --since="20 day ago" --name-status --pretty=format:"%an %h %s %cd" origin/WRLINUX_5_0_1_HEAD >>... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

3. Shell Programming and Scripting

Crontab does not execute script within a script

Hello All, I have a crontab schedule and its executing a script that is calling another script and does not execute. Crontab : ***** /test.sh and in test.sh /usr/local/file.sh and in file.sh webproxy -l 192.168.1.151 But when I run the script (test.sh) directly it works. But using... (1 Reply)
Discussion started by: Shaan_Shaan
1 Replies

4. Red Hat

root crontab wont execute a script

Greetings/ I have a script listed in my roots crontab 07 9 * * * /opt/HLRSDATA_2010_OCT/HLRS_Scheduler_sp.sh > /opt/HLRSDATA_2010_OCT/logs/HLRTKJob.log This script contains the following #!/bin/bash echo HLRSData Scheduler cd /opt/HLRSDATA_2010_OCT /usr/bin/java -Xms32m -Xmx1024m -cp... (6 Replies)
Discussion started by: RedSpyder
6 Replies

5. Programming

SFTP fails from crontab but works from terminal

Dear community, I'm driving crazy with a strange issue. I have a simple script to transfer a file to a remote system:#!/bin/bash echo "put /tmp/server.log" > /tmp/server1_transfer.sftp sftp -b /tmp/server1_transfer.sftp user@10.99.1.2:Between client and server there is a SSH KEY, so if I run... (15 Replies)
Discussion started by: Lord Spectre
15 Replies

6. Red Hat

The crontab did not execute?

Dear! I've 2 scripts backup Oracle database in crontab environment, however, I found they did not execute. The cron is here $ crontab -l 30 2 * * 0 sh /cloudbck/level0/level0.sh 19 3 * * * sh /cloudbck/level1/level1.sh Then, I tried to find how did they not run by looking up... (8 Replies)
Discussion started by: trantuananh24hg
8 Replies

7. Shell Programming and Scripting

Script works fine but not with crontab

Hello All, This is driving me nuts. Wrote a very simple script (it's in csh so sorry about that). Just something very simple though. Here is the catch. Works great from command line sometimes. Other times it runs no errors or anything but I never receive an email. Never runs from crontab... (6 Replies)
Discussion started by: jacktay
6 Replies

8. UNIX for Advanced & Expert Users

Crontab can not execute

Hi, on AIX 6.1, I put in crontab ,execution of myscript. But it sends back the following error : myscript.sh: rman: not found And in myscript I have : rman catalog rman/**@rep target / LOG=file.log << EOF run { allocate channel t1 type disk; ......... } exit EOF... (1 Reply)
Discussion started by: big123456
1 Replies

9. UNIX for Dummies Questions & Answers

how to execute sh script in bash shell via crontab

hello. we are porting over from HPUX Shell to Linux. my default shell is bash so i can no longer schedule to execute a sh script in crontab. can anyone pls help me out? I searched the site but didnt find any details. thanks! (1 Reply)
Discussion started by: jigarlakhani
1 Replies

10. Programming

crontab ..sqlplus cannot execute

i have shell script. when i run in normail mode..it run ok but when i use crontab command to set that program run in certain time it give an error. error 'SQLPLUS cannot execute' what the problem.i already set all the correct path and use both root and normal id but still cannot execute properly. (1 Reply)
Discussion started by: zikronz
1 Replies
Login or Register to Ask a Question