Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: system command is not working

by je44ery (Hermit)
on Dec 08, 2011 at 15:13 UTC ( #942460=note: print w/ replies, xml ) Need Help??


in reply to system command is not working

I can recreate your problem now.

me@mybox:/home/me/sandbox $ cat 1.pl #!/usr/bin/perl system('echo bob >/tmp/blarney.out'); me@mybox:/home/me/sandbox $ ./1.pl me@mybox:/home/me/sandbox $ cat /tmp/blarney.out bob me@mybox:/home/me/sandbox $ rm /tmp/blarney.out me@mybox:/home/me/sandbox $ at -f 1.pl now Job me.1323356661.a will be run at Thu Dec 8 10:04:21 EST 2011. me@mybox:/home/me/sandbox $ at -l me@mybox:/home/me/sandbox $ ls -l /tmp/blarney.out ls: 0653-341 The file /tmp/blarney.out does not exist.

When I check my mail, I see the problem. Notice the "command not found" message. This means you must supply full path to the script.

me@mybox:/home/me/sandbox $ mail Mail [5.2 UCB] [AIX 5.X] Type ? for help. "/var/spool/mail/me": 2 messages 1 new 2 unread U 1 daemon Thu Dec 8 10:02 32/950 "Output from at job +1.pl, me" >N 2 daemon Thu Dec 8 10:04 31/940 "Output from at job +1.pl, me" ? 1 Message 1: From daemon Thu Dec 8 10:02:08 2011 Date: Thu, 8 Dec 2011 10:02:08 -0500 From: daemon To: me Subject: Output from at job 1.pl, me@mybox, exit status 127 Cron Environment: SHELL = /opt/freeware/bin/bash PATH=/usr/bin:/etc:/usr/sbin:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/ +usr/java14/bin:/usr/local/bin CRONDIR=/var/spool/cron/crontabs ATDIR=/var/spool/cron/atjobs LOGNAME=me HOME=/home/me Your "at" job executed on mybox on Thu Dec 8 10:02:08 EST 2011 1.pl produced the following output: bash: line 3: 1.pl: command not found ***************************************************************** cron: The previous message is the standard output and standard error of one of the cron commands.

Now with full path supplied.

me@mybox:/home/me/sandbox $ ls -l /tmp/blarney.out ls: 0653-341 The file /tmp/blarney.out does not exist. me@mybox:/home/me/sandbox $ at -f /home/me/sandbox/1.pl now Job me.1323356887.a will be run at Thu Dec 8 10:08:07 EST 2011. me@mybox:/home/me/sandbox $ at -l me@mybox:/home/me/sandbox $ ls -l /tmp/blarney.out -rw-r----- 1 me users 4 Dec 08 10:08 /tmp/blarney.out


Comment on Re: system command is not working
Select or Download Code
Re^2: system command is not working
by Anonymous Monk on Dec 08, 2011 at 15:20 UTC

    Kudos for running it all down, aren't logs magical?

    :D

Re^2: system command is not working
by gulla (Initiate) on Dec 09, 2011 at 02:31 UTC

    Thanks for the detailed analysis and step by step walk through.

    I tried the way you have advised. However, this time my error file says that "/sbin/sh: system: not found". Below is the code I tried,

    -------- #a.pl #!/usr/bin/perl system('ls -lrt > a.out'); -------- Comand $ at -f /tmp/a.pl now commands will be executed using /sbin/sh job 1323397408.a at Fri Dec 9 13:23:28 2011 Error: /sbin/sh: system: not found

    I am wondering why the external system command is not recognized in the perl.

    Any thoughts my friend. When the perl script is executed with "At" command, it invokes a shell to execute the script. However, that shell is unable to recoginse the system command. Is that correct??

    Please let me know what else I can try to resolve this issue.

    Thanks In Advance

      I am wondering why the external system command is not recognized in the perl.
      The error is reported by /bin/sh, not perl. For some reason, the shell tries to interpret the script. Is the #!/usr/bin/perl line really the first one in your script?

        I do agree with you that the error is reported by /bin/sh not the perl. The perl script has just two lines; first line is

         #!/usr/bin/perl

        and second line is

         system('ls -lrt > c.out');

        Thanks, Anand

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-23 19:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls