Perl Script output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Script output
# 1  
Old 06-07-2014
Perl Script output

Hi All,
I have an expect script that I would like a perl script to call in order to login to a node and run in a single command.

The command being running is a log of events so has lots of data that will be output. I would like to output that data to a file.

Would anyone be kind enought to help me out please.

The expect script (below) is very basic as its used for several other scripts I have.

Code:
#!/usr/bin/expect
set timeout 20
set ip [lindex $argv 0]
set password [lindex $argv 1]
set cmd [lindex $argv 2]
spawn ssh -qo StrictHostKeyChecking=no sublookup@$ip
expect "password: "
send "$password\r"
expect -re "test14> "
send "$cmd\r"
expect -re "test24> "
send "exit\r"


I just need to understand how to print all the output text to a file as previously I have been selecting single bits of data.

the command used is 'show event history verbose' as yo can see below.

Code:
for my $target (keys %targets) {
        print "A $target\n" if (DEBUG);
        for (`../test/Scripts/lookup/ssh_run_cmd.exp $target $password "show event history verbose"`) {

# 2  
Old 06-09-2014
Code:
my $line = "";
open FH, "> output.log";
for $line (`<command>`) {
    print FH "$line";
}
close FH;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to find process and exclude strings from the output

Hi team, I'm a newbie of Perl Script and looking to create a simple perl script that will run in the Linux system: 1) to find process, such as ps -ef | grep process name 2) to exclude strings from the output if it found, for instance if i see abc from usr process, then will exclude it from... (1 Reply)
Discussion started by: hoffman2503
1 Replies

2. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

3. Shell Programming and Scripting

Output after a perl script gives a file with size zero.

Hi, I have a unix shell script which generates a flat file after connecting to Teradata servers to fetch tables and views and also picks up modified unix scripts from the specified paths. Later on the script calls a perl script to assign a value based on the type of object in the flat file which... (2 Replies)
Discussion started by: yohasini
2 Replies

4. Shell Programming and Scripting

Perl script to parse output and print it comma separated

I need to arrange output of SQL query into a comma separated format and I'm struggling with processing the output... The output is something like this: <Attribute1 name><x amount of white spaces><Atribute value> <Attribute2 name><x amount of white spaces><Atribute value> <Attribute3... (2 Replies)
Discussion started by: Juha
2 Replies

5. Shell Programming and Scripting

Perl CGI. no output until backend script is done

It is a basic Perl CGI question, I want to print out "Processing ... " while backend script /script/wait.pl is still running. But acctually, nothing appeared in browser untill /script/wait.pl finished. print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print... (4 Replies)
Discussion started by: honglus
4 Replies

6. Shell Programming and Scripting

Using output of perl script in shell

Hi, I have a perl script which prints the epoch value of given date. I want to use its output in a shell script.Can someone suggest me how to do it. Thanks and Regards Jyothi (4 Replies)
Discussion started by: jyothi_wipro
4 Replies

7. Shell Programming and Scripting

Help need to write a script on column separation for syslog output in perl

HI Pros, I have a issue.I need to write a script to parse the logs got from syslog server and update the same in my database.I need the following output.I donot know perl and I heard it very easy to write in perl I have the sample log I need each column seperated by commas and all equals... (0 Replies)
Discussion started by: iron_michael86
0 Replies

8. Shell Programming and Scripting

how to get split output of a file, using perl script

Hi, I have file: data.log.1 ### s1 main.build.3495 main.build.199 main.build.3408 ###s2 main.build.3495 main.build.3408 main.build.199 I want to read this file and store in two arrays in Perl. I have following command, which is working fine on command prompt. perl -n -e... (1 Reply)
Discussion started by: ashvini
1 Replies

9. Shell Programming and Scripting

wrong output in perl script

Hi, Here is my piece of code-- #!/usr/bin/perl my $Time_Stamp ; my $User_Name; my $Success; my $Failure; my $ErrorCode; my $ErrorMsg; my $logDir = $ARGV; my $logPrefix = $ARGV; die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. Shell Programming and Scripting

error in output of perl script

Hi, This is my piece of code. my $logFile = $ARGV; die "usage: $0 <logFile>" unless $logFile; die "Logfile $logFile doesn't exist" unless -f "$logFile"; open(my $log, "<", $logFile) or die "Can't open $logFile for reading."; print "Processing file $logFile...\n"; #my $authenticates... (2 Replies)
Discussion started by: namishtiwari
2 Replies
Login or Register to Ask a Question