Name: dips Date: September 23, 2007 at 22:13:45 Pacific Subject: help on Crontab utility OS: sunos.5.8/8.7 CPU/Ram: 512 MB Model/Manufacturer: 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!!
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?
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:
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
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.
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
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?
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.
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.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE