Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

help on Crontab utility

Original Message
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!!

please can anyone resolve this issue?


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: September 24, 2007 at 19:20:45 Pacific
Subject: help on Crontab utility
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 2
Name: dips
Date: September 25, 2007 at 03:14:32 Pacific
Subject: help on Crontab utility
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 3
Name: nails
Date: September 25, 2007 at 07:50:31 Pacific
Subject: help on Crontab utility
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 4
Name: dips
Date: September 25, 2007 at 23:20:22 Pacific
Subject: help on Crontab utility
Reply: (edit)
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

???



Report Offensive Follow Up For Removal

Response Number 5
Name: nails
Date: September 26, 2007 at 17:21:53 Pacific
Subject: help on Crontab utility
Reply: (edit)
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


Report Offensive Follow Up For Removal


Response Number 6
Name: dips
Date: September 27, 2007 at 00:43:00 Pacific
Subject: help on Crontab utility
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 7
Name: nails
Date: September 27, 2007 at 07:56:22 Pacific
Subject: help on Crontab utility
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 8
Name: dips
Date: September 28, 2007 at 07:59:09 Pacific
Subject: help on Crontab utility
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 9
Name: nails
Date: September 28, 2007 at 11:29:14 Pacific
Subject: help on Crontab utility
Reply: (edit)
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.



Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: help on Crontab utility

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12

help mandriva install last straw!

Icon Scaling in Explorer Bar


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

All content ©1996-2007 Computing.Net, LLC