PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !
I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open())
I would like to run another PERL-script from first one, not exiting from the first one (as by exec()), not catching the STDOUT of the called script (as in the back tick processing,) but having it printed out, as in initial script (as it is by system().)
I do not need the return status (as by system()); but, - I would like to have the called script to set some variables, that will be accessible in the calling script (sure by the our @set_var;)
My attempt (that I am not able to make do what I need) is:
The 'script2' would have something like:
The proble in my code is that the do ... command is executing on beginning of the first script run and not in the place, where it is prepared for it (by set local .. vars!)
I did try to use the eval "do script2.pl" :
- now it is executed in the proper place, but it is not setting the @set_var into the first script process!
Is there any idea to do it as I would like to have it?
(I understand, that I can rewrite the script2.pl as a function and load it by require() and execute the function: that will do everything as I prefer it; but I would like to leave the second script as is to be executable from shell by itself, as it is now.)
The solution to my question is the command do EXPR;
, having as EXPR the script-2!
That way the script-2 will have defined in script-1 some variables;
it will process everything, printing on STDOUT what it should print (the script-2), and
it will set any variable that will be available in the script-1 after completing the script-2.
After finishing the script-2 control coming back to script-1
That is all I been looking for!
(Hmm, after review my question, surprizingly realizing that I have used the 'do ..'
How it happening that I have mislead myself to have it not enough, I am not sure!
--- My apologizes for all that mess!!!! )
Hi,
I am new to perl and have a script to which i want to ensure that no matter how many ever times i execute the script it should execute only once per day. Cronjob is not a safe method as I want to built in capability inside the script. (1 Reply)
Hello
Can some help with write part of perl script
I need something like this in perl
SSH="/bin/ssh -o BatchMode=yes -o"
USER="test"
SRV="server"
SCRIPT_TO_EXEC="/tmp/test.sh" -> shell script
OUT=/tmp/out.file
${SSH} -l ${USER} ${SRV} 'sudo /usr/bin/ksh -s' < ${SCRIPT_TO_EXEC} >> ${OUT}... (1 Reply)
Not sure what I am doing wrong here, but I can print the list with no issue. Just a blank screen with the 'do'.
#!/usr/bin/perl
open FILE, "upslist.txt";
while ($line=<FILE>){
if ($line=~/^(.*?),(.*?)$/){
#print "ups:$1 string:$2\n";
do 'check_snmp_mgeups-0.1.pl -H $1 -C $2';
} ... (1 Reply)
hi All,
i have to modify a shell script written in Perl. i have to use execute immediate within this. i have to create a temporary table but it should have name like ar_data_$mmyyyy , how can i achieve this?
any help on this would be highly appriciated. (6 Replies)
Hi all,
Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM.
Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers.
At the moment am... (3 Replies)
Hi Folks,
I have created a script last month to retrive files thru FTP and cronjob was running fine till yesterday. But the naming convention of the daily file is Filename_<date>.xml
where date is YYYYMMDD. But today i have received file name as Filename_20110232.xml :(
Part of my Perl... (4 Replies)
How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ?
Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
so in unix this command works works and shows me a list of directories
find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt
but when i try running a perl script to run this command
my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows:
$count = 0;
while ( $count < $#test )
{
`sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`;
`cat 0 >... (2 Replies)
Hello evreyone,
this is my first post, and to say i'm new to this is an understatement.
I know very little about perl scripts and hope some one can help me.
i'm looking to get a script that a cron job can execute.
what the script needs to to is
1) connect to a mysql database
2) go to a... (2 Replies)