[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Add a 3rd step to this script or a seperate script

Posted on 2009-04-08
15
Medium Priority
?
180 Views
Last Modified: 2012-05-06
Hello, I have the below script

I need a 3rd step to run another CLI called entertemplate which will reference the files where it produces the .txt files in the 2nd step

The parameters would be  

entertemplate -u XxX -p Xxx -f ( which are the file names.txt  from the second step) This CLI entertemplate can only run one file at a time, so wee need to loop it.

If a seperate script is better to run after Steps 1 and 2 are done, that ok as well, more control
#!perl
use warnings;
use strict;
use Data::Dumper;
 
 
##### Run first program to generate list, first step
my @list_base = `gettemplst.exe -u Xxx -p Xxx`;
s/\s*[\r\n]$// for(@list_base);
 
##### Save to file
open(my $out, ">list.txt") or die "Could not open list.txt: $!\n";
print $out map{"$_.txt\n"} @list_base;
close($out);
 
##### Process each line second step
foreach (@list_base) {
    chomp;
    my $qip = `gettemplate.exe -U xx -P xx -n $_ -t -o orig`;
    $qip =~ s/($_)/$1.txt/;
    open(my $out, ">$_.txt") or die "Could not open '$_.txt': $!\n";
    print $out $qip;
    close($out);
 
##### 3rd step for wrapper of entertemplate
 
 
}

Open in new window

0
Comment
Question by:richsark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
15 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24099722
The output from gettemplate.exe is a bunch of lines, correct?
You want each line to be used in step 3 - so step 3 will end up being run a bunch of times for every line in step 2?
0
 
LVL 1

Author Comment

by:richsark
ID: 24100086
HI, Yes to all Adam
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24100516
Where do you want the output from step 3 to go?  This will put all of it in the file step3.txt.
foreach (@list_base) {
    chomp;
    my $qip = `gettemplate.exe -U xx -P xx -n $_ -t -o orig`;
    $qip =~ s/($_)/$1.txt/;
    open(my $out, ">$_.txt") or die "Could not open '$_.txt': $!\n";
    print $out $qip;
    close($out);
    
    ##### 3rd step for wrapper of entertemplate
    foreach my $line (split(/\n/, $qip)) {
        system("entertemplate -u XxX -p Xxx -f $line >> step3.txt");
    }
}

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:richsark
ID: 24100622
HI, there is no output to step 3

basically, they all will go back in. I would prefer a 3rd script in addition to once script does all, that way Steps 1 and 2 can run, I take the output files .txt and use a third script to put them back in



 
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24101331
Here it is as a new script
foreach my $filename (<*.txt>) {
    next if $filename eq 'list.txt';  #Skip output from step 1
    open(my $in, "<$filename") or die "Could not open '$filename': $!\n";
    while(<$in>) {
        system("entertemplate -u XxX -p Xxx -f $_");
    }
    close($in);
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24101356
Hi Adam, thanks, will test it out. So I will consider then a totally separate script then from the original that has the ability to pull out the contents, and this will bring them back in right

Thanks
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24101858
I'm not sure what the programs do... what this script does is run the entertemplate program for every line in every *.txt file (except list.txt, which comes from step 1).
0
 
LVL 1

Author Comment

by:richsark
ID: 24101954
ok. will test.

Thanks Adam
0
 
LVL 1

Author Comment

by:richsark
ID: 24106704
Hi, The scripts seems to be pulling in the contents of the .txt rather than the filename.txt

you can see the -f parameter is used to reference the a file name
 
E:\rich\template-wrapper-IN.pl  

template :template-name=template2.txt: Invalid File Name?!  
template :template-type=DHCP: Invalid File Name?!  
template :001=Same: Invalid File Name?!  
template :003=Same: Invalid File Name?!  
template :004=User: Invalid File Name?!  
template :004: Invalid File Name?!  
template :006=User: Invalid File Name?!  
template :006: Invalid File Name?!  
template :015=User: Invalid File Name?!  
template :015: Invalid File Name?!  


foreach my $filename (<*.txt>) {
    next if $filename eq 'list.txt';  #Skip output from step 1
    open(my $in, "<$filename") or die "Could not open '$filename': $!\n";
    while(<$in>) {
        system("entertemplate -u XxX -p Xxx -f $_");
    }
    close($in);
}

Open in new window

0
 
LVL 39

Expert Comment

by:Adam314
ID: 24108553
Should the entertemplate be called with the names of the .txt files, or the contents of each line of those files?  This calls it with the contents of those text files.
0
 
LVL 1

Author Comment

by:richsark
ID: 24108738
HI, Yes, be called with the names of the .txt files
0
 
LVL 1

Author Comment

by:richsark
ID: 24111545
Hi, is this correct?

foreach my $filename (*.txt>) {
    next if $filename eq 'list.txt';  #Skip output from step 1
    open(my $in, "$filename") or die "Could not open '$filename': $!\n";
    while(<$in>) {
        system("entertemplate -u XxX -p Xxx -f $_");
    }
    close($in);
}

Open in new window

0
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 24111936

foreach my $filename (<*.txt>) {
    next if $filename eq 'list.txt';  #Skip output from step 1
    system("entertemplate -u XxX -p Xxx -f $filename");
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24112205
Hi, I was way off :)

Will try and get back to you !

Thanks
0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31568137
Very smart person Adam is.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question