Hello
I have a Zabbix Server were Linux kernel version 2.6.26-2-amd64 is running.
now my Question how can i make a script that does:
- connect with ssh to a device
- get the systeminfo (but only the interfaces, mac adresses, serialnumber and Software version)
- write the output in a file
Now i made this code but it doesnt work:
Code:
#!/bin/bash
#!/usr/bin/expect --
spawn ssh user@IP > /infoman/test/juniper/file.txt
expect password:
send "Password\r"
send "get system | include mac|Int|Ser|Software"
expect eof
Now when i start the script it says this:
Errormessage:
./ZAJOH01_IP.sh: line 3: spawn: command not found
couldn't read file "password:": no such file or directory
./ZAJOH01_IP.sh: line 5: send: command not found
./ZAJOH01_IP.sh: line 6: send: command not found
couldn't read file "eof": no such file or directory
If i tip the command by myself it work that means i write:
ssh user@IP > /infoman/test/juniper/file.txt
Password
get system | include mac|Int|Ser|Software
exit
then it write in the file /infoman/test/juniper/file.txt:
Remote Management Console
Device-> get system | include mac|Int|Ser|Soft
Serial Number: xxxxxxxxxxxxxx, Control Number: 00000000
Software Version: 5.xx.xrxx.x, Type: Firewall+VPN
Base Mac: 0010.db44.xxxx
Use interface IP, Config Port: 8005
User Name: ig-root
Interface ethernet1:
*ip 10.182.128.14/23 mac 0010.db44.xxxx
*manage ip 10.182.128.14, mac 0010.db44.xxxx
Interface ethernet2:
*ip 0.0.0.0/0 mac 0010.db44.xxxx
Interface ethernet3:
*ip 0.0.0.0/0 mac 0010.db44.xxxx
Interface ethernet4:
*ip 196.30.139.43/28 mac 0010.db44.xxxx
*manage ip 196.30.139.43, mac 0010.db44.xxxx
Device-> exit
This Shellscript is automated created with a PERL script that look like this:
Code:
#!/usr/bin/perl -w
#############################################
### Creator: Kim Nussbaumer ###
### Date: 19.04.2010 ###
### Version: 0.1 ###
### File: jun_createIP_sh.pl ###
#############################################
use Text::Trim;
### Include
require "/infoman/test/juniper_backup.conf";
### backup.sh leeren
open (BK, '>', 'jun_backup.sh');
print BK "#!/bin/bash\n";
close (BK);
### devices.txt auslesen und zeilen in @lines abfuellen
open (FILE,$devpath);
#my @lines = <FILE>;
### zeilen von @lines verarbeiten
while (<FILE>) {
### Nach ' ' spliten
@singleline = split(/ /,$_);
### Shellfile erstellen
my $filename = "/infoman/test/devices/".$singleline[0]."_IP.sh";
print $filename." added\n";
### Shellfile fuellen
open (MYFILE, '>', $filename);
print MYFILE "#!/bin/bash\n";
print MYFILE "#!/usr/bin/expect --\n";
print MYFILE "spawn ssh $singleline[2]\@$singleline[1] > $bkppath$singleline[0].txt\n";
print MYFILE "expect password:\n";
print MYFILE "send \"".trim($singleline[3])."\\r\"\n";
print MYFILE "send "get system | include mac|Int|Ser|Software"";
print MYFILE "expect eof";
close (MYFILE);
chmod 0755, $filename;
### Filename dem Backupfile hinzufuegen
open (BKFILE, '>>', 'jun_backup.sh');
print BKFILE "$filename\n";
close (BKFILE);
}
If you have any question just ask i'm avaible
Thanks!
I'm New at scripting with shell and perl so plz help i need it for my work