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 ...
- 06-04-2008 #1Just 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.
- 06-04-2008 #2
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.plLinux and me it's a love story
- 06-05-2008 #3Just 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.
- 06-05-2008 #4
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
for the mail command have a look at its man pageCode:#! /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 fiLinux and me it's a love story
- 06-06-2008 #5Just Joined!
- Join Date
- Jun 2008
- Posts
- 8
Thanks, i will try and i got any problem i will ask you.
- 06-06-2008 #6Just 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.
- 06-06-2008 #7
- 06-06-2008 #8Just 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?
- 06-06-2008 #9
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.
NOTE- setting PERL_PATH is not mandatory , it is just good scripting way of doingCode:PERL_PATH=/home/chandubabu_v/
Linux and me it's a love story
- 06-06-2008 #10
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


Reply With Quote
