Crontab not running a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab not running a script
# 1  
Old 02-24-2011
Crontab not running a script

Hi, I posted this in the Solaris forum but I think this one would be more appropriate.

I created a script starting with the following lines:
Code:
#!/usr/bin/ksh

flag=n
export flag
typeset -i quant=0
(...)

When running it I'm getting the following 2 errors:
Code:
/tmp/tstscript/testfail.ksh: typeset: not found
/tmp/tstscript/testfail.ksh: function: not found

crontab uses /bin/sh (Bourne shell in Solaris, if I'm not mistaken), it looks like it's not recognising the shebang (first line of the scripts, with no blank lines before).

Any help on this?

Last edited by Franklin52; 02-24-2011 at 07:14 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-24-2011
Are you capturing the output of script in any log?

If not , capture it and you can see the erros from log.

Cron will run the with whatever shell you mentioned in the first line.
# 3  
Old 02-24-2011
Yes, the error output is what I pasted in the previous message:

/tmp/tstscript/testfail.ksh: typeset: not found
/tmp/tstscript/testfail.ksh: function: not found
/tmp/tstscript/testfail.ksh: syntax error at line 29: `}' unexpected

Bourne shell doesn't recognise typeset, that's why I thought that maybe it's not using the korn shell. Other than that I don't know what could be wrong.
# 4  
Old 02-24-2011
Please can you send us the output of crontab -l please.



Robin
Liverpool/Blackburn
UK
# 5  
Old 02-24-2011
Quote:
Originally Posted by Cvg
Code:
#!/usr/bin/ksh

To be honest i suppose this has nothing to do with scripting but is a Solaris-specific problem.

I'm by no means a Solaris expert, so i may be mistaken, but: isn't the ksh in Solaris residing in /bin/ksh or in /usr/xpg4/bin/sh?

Might it be that cron simply doesn't know which shell to start and hence reverts back to sh?

I hope this helps.

bakunin
# 6  
Old 02-24-2011
Quote:
Originally Posted by bakunin
To be honest i suppose this has nothing to do with scripting but is a Solaris-specific problem.

I'm by no means a Solaris expert, so i may be mistaken, but: isn't the ksh in Solaris residing in /bin/ksh or in /usr/xpg4/bin/sh?

Might it be that cron simply doesn't know which shell to start and hence reverts back to sh?

I hope this helps.

bakunin
I've tried both (didn't know about the second one, thanks) and it still gives the same error. I also think it's a problem with Solaris, but I'm not sure anymore. It's frustrating, I can't seem to find any info in google.
# 7  
Old 02-24-2011
Many years ago I found a way to force the shell for a cron job. It's probably not the best way to do it and it may be as bakunin has suggested. What I coded within cron (and it was running some 15 years before we moved platform Smilie) was something like this mess:
Code:
00 07 * * * /usr/bin/ksh %/usr/bin/my_ksh_script

I can't remember how I worked this out or why I thought it was a good idea, but it seemed to work. The % marker did something special and it worked, but the machine it was on is now gone by 2 years, so I can't be sure. I remember thinking that /usr/bin was a great place to put my code, seeing as it was in everyone's path. I think I'd recommend against that now!

I must say that what you have all looks to be in order. Perhaps a quick test script could be knocked together along the lines of:
Code:
#!/bin/ksh
ps -f>/tmp/ps-f
ps -l>/tmp/ps-l

Have a look at the processes listed to see if that gives you more hints.



Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CRONTAB - one python script is not running

Hi! I'm using a RaspberryPi with standard Raspbian. Currently I'm working on some sort of weather station. For now I have three python scripts - one which is updating txt files for website - update1m.py ( it will not be necessary in few next days so I'll delete it) , second one for updating... (4 Replies)
Discussion started by: bartocham
4 Replies

2. Solaris

Script problem when running on crontab

Hi guys! I created a backup script that works fine when I run manually, but when I put a crontab job to execute it the result are not the expected. (not a time problem). Here is my script: bash-3.00# cat /bk_tool/backup2.sh #!/usr/bin/csh clear set DIR_HOST='SCP08' ... (3 Replies)
Discussion started by: andredemartini
3 Replies

3. Shell Programming and Scripting

Delay in running script from crontab

I am facing an issue where sometimes crontab is running script with some delay. Below is the stmt in script and it is the only stmt in script. echo "running at `date` " >> CRONCHECK.log Below is the cron entry. 0 11 * * * CRONCHECK.sh Below is the time of run each day. running at Fri... (8 Replies)
Discussion started by: Nishant Singh
8 Replies

4. UNIX for Dummies Questions & Answers

crontab not running script

Hi All, I am having the below script to be run from crontab, it it doesnt run. 1 * * * * /home/cobr_ext/test.sh > /home/cobr_ext/temp.txt when i run i manally it runs without any issues. Could please help me as to why doesnt it run the script.:( (7 Replies)
Discussion started by: abhi_123
7 Replies

5. UNIX for Advanced & Expert Users

Particular script not running through crontab

Hi, I have created the below script, set -x # Set the Path of Environment file ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log export ENV_FILE_DIR export LOG_DIR # Set Audit Environment . ${ENV_FILE_DIR}/QDM.env... (8 Replies)
Discussion started by: yohasini
8 Replies

6. Shell Programming and Scripting

Problem with crontab running a script

I am trying to use the CRON utility in Fedora 11 & CentOS... I intend to run a script which pops up a warning message every hour and i made the following entry using "CRONTAB -e " * * * * * sh /bin/myscript.sh But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

7. Red Hat

Problems with script running with crontab

Hi, I'm trying the backup a few information commands of my Check Point FW (it's on a SPLAT linux machine). This is the script I wrote: #!/bin/bash cd /var/tmp/ file1=netstat_`/bin/date +%d%m%y`.txt file2=ifconfig_`/bin/date +%d%m%y`.txt file3=cpstatos_`/bin/date +%d%m%y`.txt... (2 Replies)
Discussion started by: nirsh
2 Replies

8. UNIX for Dummies Questions & Answers

Getting error when running script through crontab

Hi all, I wrote small script for Solaris and when I am running it through command prompt its ok, but when I trying to run it using crontab, i am getting error like: ld.so.1: dbloader: fatal: libACE.so: open failed: No such file or directory /tmp/file.sh: line 5: 8304 Killed ... (4 Replies)
Discussion started by: nypreH
4 Replies

9. Shell Programming and Scripting

issue with running script with crontab

I am facing a strange issue while running a script(eg A) from the crontab entry the script calls one more script(eg B) within it now when i run the script A manually(with nohup) it also executes the script B (embedded inside it) as expected. but when i run the script A from the crontab entry... (7 Replies)
Discussion started by: mad_man12
7 Replies

10. UNIX for Dummies Questions & Answers

A command in a script not running in Crontab.

Hi, I made this script for TRU Unix 5.1 OS based Node. When the script was run manually all the commands were running properly. But when it was run from Crontab, one command is not running. This command is not running when the script is running from Crontab: #... (2 Replies)
Discussion started by: mystition
2 Replies
Login or Register to Ask a Question