Computing.Net > Forums > Unix > help on Crontab utility

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

help on Crontab utility

Reply to Message Icon

Name: dips
Date: September 23, 2007 at 22:13:45 Pacific
OS: sunos.5.8/8.7
CPU/Ram: 512 MB
Product: Pentium (4)
Comment:

I have a Korn Shell script which I want to automatically run on every Thursday of every week of every month of every year! I tried making a Cron file with command-
$export EDITOR=vi
$crontab -e
$50 7 * * 4 /ms/user/d/dips/bin/myscript.sh dips@domain.com
In myscript.sh (requires email id as an argument so the csv report is mailed to that id) I am checking if a directory named "Mydirectory" exists in the path or not, if not then create it so that the csv report getting created in the script can reside there.

I got error mail to my inbox saying -
Your "cron" job on unixconn1
/ms/user/d/dips/bin/myscript.sh dips@domain.com
produced the following output:

mkdir: Failed to make directory "Mydirectory"; Permission denied
/ms/user/d/dips/bin/myscript.sh: [[: not found
/ms/user/d/dips/bin/myscript.sh: Mydirectory/Report_09-20-07.csv: cannot create

There can be no issue of Permissions as I am the owner of the script and cron job is in same path as the script. I am giving the full path so that if other users want to execute this script they can as a file which this script reads is in my path only,so accordingly I have changed the script so that it requires full path to be given(I cannot simply write ./myscript.sh).But if I execute this script manually it works fine!!

please can anyone resolve this issue?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 24, 2007 at 19:20:45 Pacific
Reply:

based on this error:

[[: not found

I would say part of your problem is that you haven't included the korn shell invocation on line one of your script:

#!/bin/ksh

If you don't include that, every cron I've worked with assumes the bourne shell, and [[ is syntax not allowed in bourne.

Also, you really should define the PATH variable in your script. cron's default PATH probably is different from yours.


0

Response Number 2
Name: dips
Date: September 25, 2007 at 03:14:32 Pacific
Reply:

Thanks nails....but there's one thing.....
How can I define the PATH variable in the script? I did echo $PATH and the first line was /ms/user/d/dips/bin:......so on
were myscript.sh resides. Isn't that enough?
guide me........

I opened /etc/default/cron file it has only one entry.
CRONLOG=YES
But unfortunately I cannot edit this file its read-only for me. Now what should I do?


0

Response Number 3
Name: nails
Date: September 25, 2007 at 07:50:31 Pacific
Reply:

I'm not certain why you are trying to change a system file like /etc/default/cron. Only root can change these files. In this case, I don't know why you want to.

When a script works from the command line, but fails from cron, generally it's because of the two reasons I stated above. When the script executes, and a command can not be found, it's because cron's default PATH is different from your user's PATH.

Set your PATH like you set any other script variable. For example, if your PATH from the command line looks like this:

/bin:/usr/bin/:/usr/otherpath

set it in the scipt:

PATH=/bin:/usr/bin:/usr/otherpath


0

Response Number 4
Name: dips
Date: September 25, 2007 at 23:20:22 Pacific
Reply:

Thanks for your patience...I am new to UNIX so didn't know that I am not authorised to set PATH in this file /etc/default/cron or even more that it is not reqd!!

I have done both the things you stated.
1)set !/usr/bin/ksh (actually this line was already there in my script.)
2)set the PATH variable in myscript.sh (I have done that as follows:
PATH=/ms/user/d/dips/bin:/ms/dist/aurora/bin:/usr/local/bin:/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/ms/dist/perl5/bin:/ms/dis
t/fsf/bin:/ms/dist/afs/bin:/usr/dt/bin:/usr/openwin/bin:.

But then too I am getting the same error mail message.
Your "cron" job on unixconn1
/ms/user/d/dips/bin/myscript.sh dips@domain.com
produced the following output:

mkdir: Failed to make directory "Mydirectory"; Permission denied
/ms/user/d/dips/bin/myscript.sh: [[: not found
/ms/user/d/dips/bin/myscript.sh: Mydirectory/Report_09-26-07.csv: cannot create

???



0

Response Number 5
Name: nails
Date: September 26, 2007 at 17:21:53 Pacific
Reply:

Without seeing your script and your cron entry, it's impossible to tell what the problem is. It sounds like the script is trying to make a directory in a location where it doesn't have permissions.

Is the script using a full path to the diretory it is trying to create:

mkdir /fullpath/to/MyDirectory

If it isn't, then the script needs to change directory, cd, to a location where it does have permissions.

/ms/user/d/dips/bin/myscript.sh


0

Related Posts

See More



Response Number 6
Name: dips
Date: September 27, 2007 at 00:43:00 Pacific
Reply:

I cannot send you the script....policy thing..
But I'll explain the problem I am facing.
I created another script just to check if a directory exists in the current path if not then create it.
here's the script: <cron_dir_test.ksh>
script_path: /ms/user/d/dips/training/cron_dir_test.ksh

#!/usr/bin/ksh

PATH=/ms/user/d/dips/bin:/ms/dist/aurora/bin:/usr/local/bin:/usr/bin:/bin:/usr/ccs/bin:/usr/ucb:/ms/dist/perl5/bin:/ms/dis
t/fsf/bin:/ms/dist/afs/bin:/usr/dt/bin:/usr/openwin/bin:.

#path=`echo $PATH | cut -d':' -f1`

pwd=`pwd`
echo $pwd
cd $pwd/training

if [ ! -d cron_dir_test ]
then
mkdir $pwd/training/cron_dir_test
fi

There is one strange thing when I run the script from command line value of pwd variable is /ms/user/d/dips/training (which is right)
but when i wrote a script just to echo pwd and run it thro' cron it showed: /ms/user/d/dips (i.e. my $HOME path)??

There's no question of NO PERMISSIONS coz I have all the permission on this path. I'm trying to create dir in my path only!!
Following is the crontab entry:
27 08 * * * /ms/user/d/dips/training/cron_dir_test.ksh

NOTE: I have tried all sorts of combination, given full path to MyDirectory then too cron output says Permission denied!
Now where I am wrong?


0

Response Number 7
Name: nails
Date: September 27, 2007 at 07:56:22 Pacific
Reply:

I must disagree. It is a question of permissions. A script run from cron works differently than run from the command line.

When a script executes from the command line, the pwd is the directory where ever you happen to reside.

When a script executes from cron, the pwd is generally undetermined unless within the script, you cd to a diretory thus making it the pwd.

It's my experience a script like yours executed from cron, the beginning pwd is the root directory. And nobody but a user with root permissions creates directoes in root.


0

Response Number 8
Name: dips
Date: September 28, 2007 at 07:59:09 Pacific
Reply:

I tried to know who is actually running the "cron" so... from the below "ps" output do you get the user who runs "cron" on my unixconn1?

cwxceed18 /ms/user/d/dips/training/142$ ps -aef | grep cron
root 1348 1 0 Apr 08 ? 0:46 /usr/sbin/cron
dips 19258 656 0 15:52:00 pts/117 0:00 grep cron
dips 19254 1348 1 15:52:00 ? 0:00 sh -c /ms/user/d/dips/training/myscript.sh dips@domain.com


0

Response Number 9
Name: nails
Date: September 28, 2007 at 11:29:14 Pacific
Reply:

Any unix user can set up a cron job provided the system administrator has not denied permission.

In your original post, you stated that you had set up user "dips" to run a cron job. Where I think you are making a mistake is assuming that when the job executes from cron that it starts from user dips come directory. It probably doesn't.



0

Sponsored Link
Ads by Google
Reply to Message Icon

Which shell is running my... string to integer



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: help on Crontab utility

Help on SCO Unix Network www.computing.net/answers/unix/help-on-sco-unix-network/2193.html

need help on SED script www.computing.net/answers/unix/need-help-on-sed-script/7487.html

plz help me, stuck on grep prob www.computing.net/answers/unix/plz-help-me-stuck-on-grep-prob/4876.html