Problem with Cron job

Hi ,
I have a TCL script which i am supposed to run as a cron job..
The script works fine from command line , but when run as a cron job , its unable to find a package,,
my crontab is as follows.
---------------------------
#!/usr/bin/ksh

          • PATH=/cm8/auto/Automation/Library/TclLib

0,10,20,30,40,50 * * * * /home/users/sudharss/bin/tclsh /home/users/sudharss/AUTO/ontDownload.tcl

my tcl script is as follows
-----------------------------

#!/usr/bin/ksh
# \
exec tclsh8.3 "$0" ${1+"$@"}
global env
global auto_path
if { [info exists env(arch)] && $env(arch) == "linux" } {
lappend auto_path "/cm8/auto/Automation/Library/TclLib-Linux"
} elseif {[info exists env(arch)] && $env(arch) == "sunos" } {
lappend auto_path "/cm8/auto/Automation/Library/TclLib"
} else {
puts "arch type not known, defaulting to sunos"
lappend auto_path "/cm8/auto/Automation/Library/TclLib"

}

package require mysqltcl

the o/p of cron is as follows
------------------------------
Your "cron" job on inchesfttu003-c1
/home/users/sudharss/bin/tclsh /home/users/sudharss/AUTO/ontDownload.tcl

produced the following output:

arch type not known, defaulting to sunos
hi
can't find package mysqltcl
while executing
"package require mysqltcl"
(file "/home/users/sudharss/AUTO/ontDownload.tcl" line 17)

can someone please help.....

Environment when called from cron is different to when called from a shell. These questions regarding cron are so often asked, you might want to use the forum's search function and have a look here:

Ok check these

  1. line ---> exec tclsh8.3
    ->> Is the complete path required here also ?
  2. add PATH to your crontab. Just add PATH=Bla BLA ... (whatever your path is)
  3. Incase you dont like add PATH to crontab ... then add to your script (different script using different paths in cron) ..
    ->> Add a line export PATH= BLA BLA (whatever your path is)

Hi , I have added the path also in my crontab...
But still it doesnt work. I have tried out numerous solutions from related posts, but nothing seems to work.

how about 1 & 3 suggested ... have you tried these also ?

Yes i have tried but in vain

---------- Post updated at 07:07 AM ---------- Previous update was at 07:03 AM ----------

I have this auto_path, a global TCL variable(not an ordinary env variable) in my tcl script, and i have set it to the path where the mysql files are located.
lappend auto_path "/cm8/auto/Automation/Library/TclLib"

But I feel the cron is unable to see that variable!!! I am confused how to make cron identify where to look for the mysqltcl lib files.Because its throwing error at that point where i call "package requires mysqltcl "

---------- Post updated at 07:09 AM ---------- Previous update was at 07:07 AM ----------

It can also be seen that normal TCL commands like puts etc are working..
only when it comes to the "package requires mysqltcl" , its showing error.. The variable auto_path holds the PATH to this lib

I have not done much TCL ... but do you have something similar to path for package like @INC or PERL5LIB on env.

example:
set dir /path/to/specific/version/of/extension ....

like on URL: Tcl Modules

Another solution I would try ..
When everything fails and I am only one in prod incharge :slight_smile: (try at your own risk)

take all the environment variables and put it in a file and source that in shell script
set > ~/allenvvar.sh

and in script
source ~/allenvvar.sh

Then once it starts to work ... remove one variable at a time..

try adding the profile line below:

#!/usr/bin/ksh

#
# This will source your environment into the script. Assuming ksh is your default shell.
# Note there is space between the 1st "." and the "~"
#
. ~/.profile