|
|
| Robert Hicks 2006-12-21, 8:08 am |
| My Tcl scripts refuse to run under cron.
I have done:
#!/usr/bin/sh
# Restart as tclsh \
exec tclsh "$0" "$@"
#!/usr/bin/env tclsh
#!/path/to/tclsh
The files are executable and have root permission. I know that cron
uses /usr/bin/sh to run stuff on my system and using the first version
I can do "sh program.tcl" and it runs but not if I put it in cron to do
so.
Any ideas that I can try?
Robert
| |
| Robert Hicks 2006-12-21, 8:08 am |
| I should note that I am using:
HP/UX 11.11
ActiveTcl 8.4.14
root account
| |
| Andrew Mangogna 2006-12-21, 8:08 am |
| Robert Hicks wrote:
> My Tcl scripts refuse to run under cron.
>
> I have done:
>
> #!/usr/bin/sh
> # Restart as tclsh \
> exec tclsh "$0" "$@"
>
> #!/usr/bin/env tclsh
>
> #!/path/to/tclsh
>
> The files are executable and have root permission. I know that cron
> uses /usr/bin/sh to run stuff on my system and using the first version
> I can do "sh program.tcl" and it runs but not if I put it in cron to do
> so.
>
> Any ideas that I can try?
>
> Robert
Just a couple of experiences running Tcl executables from cron (in my case
pixie cron).
1. I usually explicitly set the PATH variable to insure it contains the
directory where "tclsh" is installed.
2. I usually explicitly set TCLLIBPATH to pick up any site local or custom
packages.
3. I rely on "cron" sending email with any abortive error messages.
4. Double and triple check file execute permissions and other such detail
that "just has to be right".
Hope this gives you something to try.
--
Andrew Mangogna
| |
| suchenwi 2006-12-21, 8:08 am |
| I've heard for a long time that cron jobs have an extremely limited set
of environment variables. Try a cron job with just the command "export"
to see what you can expect.
| |
| Alexandre Ferrieux 2006-12-21, 8:08 am |
|
Robert Hicks wrote:
> I should note that I am using:
>
> HP/UX 11.11
> ActiveTcl 8.4.14
> root account
Yup, this is the well-known cron gotcha: basically, cron jobs are
spawned with the proper userid, but not through the user's shell. It's
just fork();setuid();exec(); -- and it is customary to set PATH & other
env vars from within the .whatever-shell-rc...
My usual workaround is to have crontab entries starting
/bin/sh -c "actual command and args"
(pick your preferred shell)
-A
| |
| Robert Hicks 2006-12-21, 8:08 am |
| Thanks guys, I will try those. This only happens with Tcl and not Perl,
which is weird.
Robert
| |
| Cameron Laird 2006-12-21, 7:08 pm |
| In article <1166707434.215941.4370@48g2000cwx.googlegroups.com>,
Robert Hicks <sigzero@gmail.com> wrote:
>Thanks guys, I will try those. This only happens with Tcl and not Perl,
>which is weird.
>
>Robert
>
Now you've got me curious. Please narrow down that comparison.
I'll bet there's an interesting explanation. What precisely
happens with Tcl but not Perl?
| |
| Robert Hicks 2006-12-21, 10:07 pm |
|
Cameron Laird wrote:
> In article <1166707434.215941.4370@48g2000cwx.googlegroups.com>,
> Robert Hicks <sigzero@gmail.com> wrote:
>
> Now you've got me curious. Please narrow down that comparison.
> I'll bet there's an interesting explanation. What precisely
> happens with Tcl but not Perl?
I have a Perl script that scoops up some env info and mails it off to
me. I have a Tcl script that does the exact same thing.
I start the Perl scripts with "#!/usr/bin/env perl" and I put those in
as a cron job and it works. I get the email. I do the same thing with
Tcl (using the various ways to do the shebang) and put those in as cron
jobs and nada. I can launch both from the command line without a
problem. It is only when I put the Tcl scripts in cron that they don't
work.
I am going to try some of the suggestions givin here tomorrow.
Do you need anything specific?
Robert
| |
| Alexandre Ferrieux 2006-12-22, 8:07 am |
|
Robert Hicks wrote:
> I start the Perl scripts with "#!/usr/bin/env perl" and I put those in
> as a cron job and it works. I get the email. I do the same thing with
> Tcl (using the various ways to do the shebang) and put those in as cron
> jobs and nada. I can launch both from the command line without a
> problem. It is only when I put the Tcl scripts in cron that they don't
> work.
In addition to trying to solve the problem (eg with /bin/sh -c or
/bin/csh -c), and to satisfy Cameron's well-founded curiosity, you
could try to get the stderr of the job. In some setups, cron gives it
back as e-mail messages to the user (here, root). It may need some
configuration work though. A simpler approach would be to write a glue
script launching your command with a 2> redirection to a file of your
choice. I expect to see a message like
tclsh: Command not found.
or
tclsh: error while loading shared libraries: libwhatever.so:
cannot open shared object file: No such file or directory
or yet
(some other Tcl-related env var not set properly)
And if nothing obvious appears, what about
strace -f -o /tmp/myfile tclsh myscript
-Alex
|
|
|
|