Help with script, I get an error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script, I get an error
# 8  
Old 04-17-2009
Im thinking the problem is somewhere setting $dns in this section.
What is getzoneprof?

Code:
##### Step 2: run getzoneprof, and keep first 4 lines only
        my @getzoneprof = `getzoneprof -u Xxx -p Xxx -a $_ -o Orig`;
        @getzoneprof = @getzoneprof[0..3];
        
        ##### Find server name
        warn "Server not found for $_\n",next unless $getzoneprof[-1] =~ /dnsServers=(\S+)/;
        my $dns = $1;

# 9  
Old 04-17-2009
Hi getzoneprof is a cli ( command line interface) that runs and references the subnet.txt file

once it gets that there are list of primary and secondary dns servers, once that is found it will ssh to each of the dns servers and check for *.jnl file is present. If so I log it and got to the next set and so one...
# 10  
Old 04-20-2009
I got a little further Smilie

After looking further, I see this right after my perl excution

$ perl test.pl
SSHAuthenticationError Login timed out. The input stream currently has the contents bellow:
*** IT IS AN OFFENSE TO CONTINUE WITHOUT THE CORRECT AUTHORIZATION ***
Individuals using this computer system with or without proper.....

Thanks!
# 11  
Old 04-20-2009
Hi All, seems like I am the only one here today Smilie

I got the report to work by adding the > to the log.txt line ( open(my $out, ">log.txt") or die "Could not open log: $!\n";

I am still having 2 minor issues that I hope I can get a response.
Seems like my dnsServers= line is only pulling 1 DNS server from that line, In some cases I have 20 of them. looks like it only grabbing the first server from that line.

Issue 2: In some cases, the ssh does not login, I have to run the script 2x and it will go, but when I get to a new server, it stops. If I run it agian, I get to the same point, as soon as it does a new set, It dies.

Something has to be wrong with a string its expecting??

Please advice
# 12  
Old 04-20-2009
Anyone what to give a shot to help a broth'a out?
# 13  
Old 04-21-2009
Hi, This is the code I am working with thus far. My wish is that an expert can see why I have two issues:

1. the script is only seeing 1 dns server from dnsServers= line

2. If a dns server is repeated, there is no need to ssh to it again.

3. when I ssh, the sessions remain open, so after 4 logins, I cant login anymore, but I think that can be fixed if we can solve issue 2.


Code:
#!perl -w
use strict;
use warnings;
use Net::SSH::Expect;

open(my $out, ">log.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnet.txt
open(my $in, "<subnet.txt") or die "Could not open subnet.txt: $!\n";
while(<$in>) {
        chomp;
        
        ##### Step 2: run getzoneprof.exe, and keep first 4 lines only
print        my @getzoneprof = `./getzoneprof.exe -u 123 -p 123 -a $_ -o origid`;
        @getzoneprof = @getzoneprof[0..3];
        
        ##### Find server name
print        warn "Server not found for $_\n",next unless $getzoneprof[-1] =~ /dnsServers=(\S+)/sm;
        my $dns = $1;
        
        ##### ssh to server
        my $ssh = Net::SSH::Expect->new (
        host => $dns,
          password=> 'me',
          user => 'help'
            
          );
        
print        my $login_output = $ssh->login();
        unless($login_output =~ /Total/) {
                warn "Login has failed. Login output was $login_output";
                next;
        }
        
        ##### run ls to look for files
print        my $ls = $ssh->exec("ls /opt/rich/named/*.jnl");
        my $found='no';
print        $found='yes' if $ls =~ m|/opt/rich/named/|;
        print $out "From zone $_ containing dnsserver \"$dns\" found=$found of presense of \"jnl\" files\n\n";
        
        $ssh->close;
}
 
close($out);


Last edited by richsark; 04-21-2009 at 09:06 AM.. Reason: spelling
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script with sql script error

Hi All when I execute from psql prompt, I get the result, when I try to automate using a shell script, the query is not working # `/usr/bin/psql -U postgres -d coba1 -c "select name from users where "Date" > current_date - 30;"` ERROR: column "Date" does not exist LINE 1: select... (2 Replies)
Discussion started by: srilinux09
2 Replies

2. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

3. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

4. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

5. UNIX for Dummies Questions & Answers

Re: Script Error [syntax error at line]

Hi , I Have Written A Simple Script To Check Greatest Of '2' Number When Execuating The Script I Am Getting The Below Error SP11: if:not found SP11: line 4:syntax error at line 5:'then' unexpexted And The Program I Have Wrriten For This #!bin/ksh echo "Enter Two Numbers"... (3 Replies)
Discussion started by: anudeepkumar123
3 Replies

6. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

7. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

8. Windows & DOS: Issues & Discussions

Error opening script file - location error

Hello, I know nothing about UNIX, ftp, etc. I am building an excel VBA macro which calls a .bat file. I've taken a pre-existing batch file and am trying to modify it to fit my purposes. I would be very grateful for some assistance. Here is my .bat file: echo off set... (9 Replies)
Discussion started by: starcraftbud
9 Replies

9. Shell Programming and Scripting

Script with error output but continuation in script?

I have written a basic fetching script. The script logs into an FTP site, downloads a .zip file, then unzips and moves the files to the necessary folders, then deletes them, etc. The problem I have is if one of the files no longer exists on the FTP site or another part of the script fails, then... (3 Replies)
Discussion started by: daem0n
3 Replies

10. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies
Login or Register to Ask a Question