IO redirection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thelevitator
    New Member
    • Dec 2007
    • 7

    IO redirection

    Im trying to execute a perl script from a shell script. I have to pass the path of a file in the command line when i execute the perl script (Automate the perl script execution). How do i feed the path to the perl script through the shell script?

    Details of the perl script execution:

    $perl sample.pl
    Enter the filename:

    Details of the unsuccessful shell script:
    #!bin/sh
    /usr/bin/perl /home/name/sample.pl<< "<pathname"

    I dont want to hardcode the path. But i tried passing the path of the file using << in the shell. It didnt work. Please help me.
  • thelevitator
    New Member
    • Dec 2007
    • 7

    #2
    Cronjob problem

    Ppl,

    please help me fix this problem. Its kind of urgent..I sat on it for more than 2 days. But im totally lost. Its a pretty dumb problem actually.

    Im trying to run a crontask on a remote system. I should execute a shell script at a given time.

    For ex: * * * * * bash /Users/name/sample.sh

    In the script ive included commands to perform database backup. It works fine. But the problem is that, ive to run a perl script prior to the execute of mysqldump. For some dumb reason, it wouldnt execute.
    Details of the file sample.sh:

    /usr/bin/perl /Users/name/chumma.pl

    If i run this command it should update some tables in my local database. Then i should run mysqldump to import it to a remote database, which works fine.

    I dont know why the crontask wouldnt execute. I dont know if there is a problem with the shell syntax or the perl syntax.

    Please not that, i SSH into a remote system to run the cronjob..
    thelevitator is online now Report Post Edit/Delete Message

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Okay a few things:
      Does the perl script run without being in the cronjob? What happens if you cd to /Users/name/ and do a './chumma.pl' ? Also, If you are running a cronjob, you should nto have to remote in to execute this. FYI your example cronjob is not set to run at a specific time. I don't know if that means is runs constantly, or never, but my guess would be never.

      Comment

      • thelevitator
        New Member
        • Dec 2007
        • 7

        #4
        Hi,

        I couldnt get the script to run by giving ./chumma.pl, it executes if i'd give perl chumma.pl. I didnt give the specific time. Please ignore that part. I just want the crontask to execute. So as of now, im just testing it for the next minute.

        If i'd try executing using ./chumma.pl it throws the bash error permission denied.

        Does it have anything to do with setting the permissions? Is that why it is not executing? But i tried to execute mysqldump command and it does work. Any suggestions??

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by thelevitator
          Hi,

          I couldnt get the script to run by giving ./chumma.pl, it executes if i'd give perl chumma.pl. I didnt give the specific time. Please ignore that part. I just want the crontask to execute. So as of now, im just testing it for the next minute.

          If i'd try executing using ./chumma.pl it throws the bash error permission denied.

          Does it have anything to do with setting the permissions? Is that why it is not executing? But i tried to execute mysqldump command and it does work. Any suggestions??
          Since you are on a Unix system, and the script won't run when you just give "./chumma.pl", then you need to edit it and ensure that the first line reads:

          [code=perl]
          #!/usr/bin/perl
          [/code]

          The shebang line needs to be the first line in the script and should contain the above (with your path to the perl interpreter of course).


          Either way, if you run that shell script (that runs the Perl script), does the Perl script run? If it doesn't then you have an issue there that needs to be resolved before Cron can do its job.

          Regards,

          Jeff

          Comment

          • arne
            Recognized Expert Contributor
            • Oct 2006
            • 315

            #6
            Originally posted by thelevitator
            Im trying to execute a perl script from a shell script. I have to pass the path of a file in the command line when i execute the perl script (Automate the perl script execution). How do i feed the path to the perl script through the shell script?

            Details of the perl script execution:

            $perl sample.pl
            Enter the filename:

            Details of the unsuccessful shell script:
            #!bin/sh
            /usr/bin/perl /home/name/sample.pl<< "<pathname"

            I dont want to hardcode the path. But i tried passing the path of the file using << in the shell. It didnt work. Please help me.

            If you do not have control over sample.pl yopu could try

            Code:
            echo "pathname" | /usr/bin/perl /home/name/sample.pl
            If you have written sample.pl yourself, make the
            pathname you want to pass a parameter, so that
            you can use

            Code:
            /usr/bin/perl /home/name/sample.pl pathname
            in your shell script. For this the sample.pl script
            should use the @ARGV array instead of reading
            from STDIN.

            HTH,
            arne

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              This is the SAME question that you asked in your other thread, which still needs an answer(s) from you from my last post to your thread.

              I am merging the two threads as we don't need two of the same questions floating around out here.

              Regards,

              Jeff

              Comment

              Working...