Operating System - HP-UX
1831559 Members
4100 Online
110025 Solutions
New Discussion

Using "at" to run a perl script (does'nt seem to work?)

 
SOLVED
Go to solution
Joel Shank
Valued Contributor

Using "at" to run a perl script (does'nt seem to work?)

I am trying to submit a perl script via an at command, but I am getting shell errors (mostly things like: sh[30]: =: not found.

The script works fine if I just run it via ./pgm, but not when I run it as:
at -f /home/root/pgm now

I am using HP_UX 11.00 and perl v5.6.0

Does anyone know if I can run a perl script via the at command? I know it works via cron as I have scheduled several perl scripts using crontab.

Any assistance would be greatly appreciated.
jls
8 REPLIES 8
RAC_1
Honored Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

Yes you can run any script with at.

Make sure you have #!/opt/perl/bin/perl or what ever is the perl path at the start of the script.
Also make sure all required variables are defined and exported in script file.

Anil
There is no substitute to HARDWORK
Pete Randall
Outstanding Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

Joel,

Make sure you use the full path names of any commands in your script.


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

Yes you can but you have to play by a few rules. Make sure that you have a "shebang" as the very first line of your Perl script.

#!/usr/bin/perl -w


Almost all problems stem from the intentionally very sparse environment under which cron spawns new processes. You may also need to add -I arguments to tell Perl where to look for modules.

Probably the easist way to to let cron invoke a shell script which in turn sets and exports any needed enviroment variables like PATH and then let this shell script actually launch the Perl script.
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor
Solution

Re: Using "at" to run a perl script (does'nt seem to work?)

If I'm not mistaken, all of the above answers are wrong.

both at and cron only take SHELL scripts, and disregard the header line, which is pretty counterintuative

Look at this:
--8<---
a5:/u/usr/merijn 111 > tty
/dev/ttyp2
a5:/u/usr/merijn 112 > cat xx.pl
#!/pro/bin/perl

use strict;
use warnings;

open STDOUT "> /dev/ttyp2";
print "Hello, world\n";
a5:/u/usr/merijn 113 > at -f xx.pl now
warning: commands will be executed using /usr/bin/sh
job 1084814691.a at Mon May 17 19:24:51 2004
a5:/u/usr/merijn 114 >
-->8---

look at the warning at gives!

The difference with cron is that you enter the executable perl script as a name in the cron line. The cron line is evaluated by /usr/bin/sh, and thusly nicely interprets the shebang line

Enjoy, Have FUN! H.Merijn [ leaving extending this knowledge to call perl in at to the user ]
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

And I forgot to add the mail I got:

--8<---
sh[55]: use: not found.
sh[56]: use: not found.
sh[58]: open: not found.
Hello, world



*************************************************
Cron: The previous message is the standard output
and standard error of one of your at commands.


-->8---

It prooves I'm right :)

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Joel Shank
Valued Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

I know to use the shebang. It seems procura is correct, the at command ignores the header and runs it via the shell regardless as to the header setting.

I found that if I write a shell script that calls the perl script it works without error.

This is a pain, since the shell SHOULD interpret the shebang!

At any rate, I can get it to work properly even it is an ugly way to do it.

Thanks to all for quick responses.

jls
Fred Ruffet
Honored Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

Ooops :)

/tmp#cat test.pl
#!/opt/perl/bin/perl

$var=2;
$var+=2;
printf "$var\n";
/tmp#crontab -l
44 19 * * * /tmp/test.pl > /tmp/test.log 2>&1
/tmp#cat test.log
4

Seems that it works for me...

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Fred Ruffet
Honored Contributor

Re: Using "at" to run a perl script (does'nt seem to work?)

re-Ooops ;)

Didn't saw the at/crontab problem. works with cron, don't with at.
You're absolutly right procura

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)