Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
Hi, I want to write a Shell script for caliing some perl scripts. Ex: I have 4 Perl scripts like abc.pl xyz.pl aaa.pl bbb.pl I want to call those perl ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8

    How to write a Shell script for calling Perl scripts.

    Hi,

    I want to write a Shell script for caliing some perl scripts.

    Ex: I have 4 Perl scripts like

    abc.pl
    xyz.pl
    aaa.pl
    bbb.pl

    I want to call those perl scripts from Shell script using cronjob.

    If any of the 4 perl scripts was down we have to send a mail xyz@gmail.com.

    Give me your suggestions.

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    if you want just a script that calls those 4 Perl script you can open a file (say caller.sh)
    and put the following instructions in, close the file and call the script(caller.sh) with cron

    Code:
    #! /bin/sh
    
    PERL_PATH=/path/to/perl/
    
    ${PERL_PATH}abc.pl
    ${PERL_PATH}xyz.pl
    ${PERL_PATH}aaa.pl
    ${PERL_PATH}bbb.pl
    Linux and me it's a love story

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8
    Thanks for your suggestions. But if any of the 4 perl scripts doen how can I send a mail to xyz@gmail.com rergarding the script down alarm.

  4. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    ok. i thought you just needed something to begin with.


    you can do as follows

    in each of those Perl scripts you return 0 if successful and 1 otherwise(for that i let you do it. as a hint you can use exit inside the Perl script).

    then you change the above script to look like this

    Code:
    #! /bin/sh
    
    PERL_PATH=/path/to/perl/
    
    RET1=$(${PERL_PATH}abc.pl)
    RET2=$(${PERL_PATH}xyz.pl)
    RET3=$(${PERL_PATH}aaa.pl)
    RET4=$(${PERL_PATH}bbb.pl)
    
    RET=$(( $RET1 + $RET2 + $RET3 + $RET4))
    
    if [ $RET -gt 0 ]
    then
    here you use the mail command to send the mail
    fi
    for the mail command have a look at its man page
    Linux and me it's a love story

  5. #5
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8
    Thanks, i will try and i got any problem i will ask you.

  6. #6
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8
    #! /bin/sh

    PERL_PATH=D:/ABC/XYZ/Conf/perl


    ${PERL_PATH}abc.pl
    ${PERL_PATH}xyz.pl
    ${PERL_PATH}aaa.pl
    ${PERL_PATH}bbb.pl


    After running the above script i am getting the error like "No such file or directory". But i have those perl scripts in the same path. Give your suggestions.

  7. #7
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    Quote Originally Posted by chandubabu_v View Post
    #! /bin/sh

    PERL_PATH=D:/ABC/XYZ/Conf/perl


    ${PERL_PATH}abc.pl
    ${PERL_PATH}xyz.pl
    ${PERL_PATH}aaa.pl
    ${PERL_PATH}bbb.pl


    After running the above script i am getting the error like "No such file or directory". But i have those perl scripts in the same path. Give your suggestions.
    hi,

    what is this ?
    Code:
    D:/ABC/XYZ/Conf/perl
    are you sure this is a valid path in your Linux system?
    it looks like some M$ way of handling partitions to me
    you need to know where are your PERL scripts
    Linux and me it's a love story

  8. #8
    Just Joined!
    Join Date
    Jun 2008
    Posts
    8
    Which path i have to give there at PERL_PATH, the path to the perl scripts or anything?

  9. #9
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    Quote Originally Posted by chandubabu_v View Post
    Which path i have to give there at PERL_PATH, the path to the perl scripts or anything?
    yeah you give the path to the PERL scripts. suppose that your login name is chandubabu_v and that you perl scripts are under your home directory. this means your perl scripts will be under /home/chandubabu_v/
    and you set PERL_PATH as next.
    Code:
    PERL_PATH=/home/chandubabu_v/
    NOTE- setting PERL_PATH is not mandatory , it is just good scripting way of doing
    Linux and me it's a love story

  10. #10
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I was confused as well. There are basically two approaches here:

    If the scripts are themselves executable, then you can just give the full path to the script. In this case, I think that the variable is unnecessary, as it's quite possible that you would have scripts in several different directories (and furthermore, those locations are unlikely to change, and even if they were, the variable would only be useful if multiple scripts were to be moved together).

    If the scripts are not executable, you can pass the full path to the Perl interpreter. In this case, you need to use the full path to the "perl" command (you cannot just say "perl"). This is because the cronjob may not have the same $PATH as the user. In this case, using a variable is Best Practices (TM), because it becomes very easy to change the path to the Perl interpreter.
    DISTRO=Arch
    Registered Linux User #388732

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...