Script won't fails when running from crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script won't fails when running from crontab
# 1  
Old 07-17-2013
Script won't fails when running from crontab

Hi,

My script runs fine from the command line, but when crontab tries to launch it encounters lack of permissions:

could not open /dev/kbd to get keyboard type US keyboard assumed
could not get keyboard type US keyboard assumed
split: Permission denied

This is the head of the script:
Code:
#!/bin/ksh

if [ $# -ne 1 ]
then
echo "File needed as a parameter"
exit 0
fi
dos2unix $1 $1


hour=`date "+%H:%M:%S"`

/usr/bin/split -l 2000 $1
archi=`ls xa*|xargs`
...

Rest of the script skipped, it fails when trying to run a simple "split". Any ideas?

Sorry for the misleading title, I can't seem to edit it

Last edited by Cvg; 07-17-2013 at 02:41 PM.. Reason: wrong thread title
# 2  
Old 07-17-2013
There is no terminal when you run a cron job. You get the output - normally - in an email.

$1 if it is a file name, should be a fully qualified file name: /path/to/my/filename.
Either that or add a line before split:

Code:
cd /path/to/my

# 3  
Old 07-18-2013
Quote:
Originally Posted by jim mcnamara
There is no terminal when you run a cron job. You get the output - normally - in an email.

$1 if it is a file name, should be a fully qualified file name: /path/to/my/filename.
Either that or add a line before split:

Code:
cd /path/to/my

Completely agree. The same thing happened to me not too long ago. The explanation is simple: cron "needs to know" where to look to find the argument for the script. And it needs an absolute pathname (beginning with / down to its specific location in the filesystem tree).
On the other hand, when you run the script manually, you can either specify an absolute or relative pathname (a relative pathname starts with your current working directory), and that's why it's working when you run it from the command line and not from cron.
Quote:
Originally Posted by Cvg
Hi,

My script runs fine from the command line, but when crontab tries to launch it encounters lack of permissions:

could not open /dev/kbd to get keyboard type US keyboard assumed
could not get keyboard type US keyboard assumed
split: Permission denied

This is the head of the script:
Code:
#!/bin/ksh

if [ $# -ne 1 ]
then
echo "File needed as a parameter"
exit 0
fi
dos2unix $1 $1


hour=`date "+%H:%M:%S"`

/usr/bin/split -l 2000 $1
archi=`ls xa*|xargs`
...

Rest of the script skipped, it fails when trying to run a simple "split". Any ideas?

Sorry for the misleading title, I can't seem to edit it
Adding another 2 cents here:
If the number of arguments is not equal to 1, the script should exit with error status (exit 1 instead of exit 0, which is used to indicate success).
If you're getting a "Permission denied" message, try adding your user name to your crontab (crontab -e):
Code:
USER=gacanepa

right before the cron jobs entry section.
Let us know how it goes.
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. 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

4. 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

5. Shell Programming and Scripting

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: #!/usr/bin/ksh flag=n export flag typeset -i quant=0 (...) When running it I'm getting the following 2 errors: /tmp/tstscript/testfail.ksh:... (9 Replies)
Discussion started by: Cvg
9 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. Shell Programming and Scripting

crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command: /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessagesFrom a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it? /usr/bin/syslogMailer... (4 Replies)
Discussion started by: jelloir
4 Replies

9. 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

10. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies
Login or Register to Ask a Question