Sponsored Content
Top Forums Shell Programming and Scripting Script which telnets to a device, runs commands and prints output to a file Post 302788801 by samantha123 on Tuesday 2nd of April 2013 01:45:00 PM
Old 04-02-2013
Script which telnets to a device, runs commands and prints output to a file

I am connecting to a device using telnet, I want my script to perform certain commands : ie- show device , show inventory..etc and write the output it sees from the terminal to a file.
this is what I have got :
Code:
#!/usr/bin/expect -- 

set running 1 
spawn telnet <ip address> 
expect  {'^]'.} 
expect "login:"    
send "admin\r"    
expect "Password:"    
send "********\r"  


set fh [open master1.txt w]    
set fh1 [open master2.txt w]  
expect "master>" 
send "show device\r"  

while $running { 
expect {      
"\n" { puts $fh "$expect_out(buffer)"}      
eof {set running 0}          
timeout {set running 0}         
}         
} 


close $fh 
puts done  

expect "master>" 
send "show status\r"  
while $running { 
expect {      
"\n" { puts $fh1 "$expect_out(buffer)"}  
eof {set running 0}      
    timeout {set running 0}       
  }       
  } 
close $fh1 
puts done    

expect -re {# $}   
exit


So what is happening now is after the first loop it is printing the data of the result to master1.txt file...but after the execution it comes to:
master>
and stops.. I tried modifying the second loop to say:
expect "master>" send "exit\r"
just to see if it exits out but its not reading the command and not exiting, I have to manually exit out. Please help me on what I am doing wrong. This is my first time with "expect" so "expect-ing" to learn here Smilie
Thanks..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output of 2 commands into 1 file

How could you put the output of two commands into one file using a single command? For example put the output of a grep command and a sort command into one file together. Here is another rough explanation of what I am trying to do; output of $ grep pattern file1 plus output of $ sort file... (8 Replies)
Discussion started by: enuenu
8 Replies

2. Shell Programming and Scripting

command runs, no output

I have a script that searches for specific information from log files. #!/bin/sh sed -n '/*C/,/END/p' /sn/log/OMlog* > crit.out sed -n '/REPT INITIALIZATION/,/err:/p' /sn/log/OMlog* > switchcc.out ./start.awk /sn/log/OMlog* > ARs.out ./end.awk /sn/log/OMlog* > ARe.out cat crit.out... (1 Reply)
Discussion started by: grinds
1 Replies

3. Shell Programming and Scripting

Script Runs fine but not giving any output

Hi, My script is running with no erros but not giving any output can anyonehelp. #!/bin/ksh . /home/application/bin/application.env OUTFILE=Result.txt PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}` echo "1)To get the book last loaded details " read... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

4. Shell Programming and Scripting

[bash] run a shell who runs commands

Hi all. On X11 I'm on a shell ...shell_1 (/bin/bash). From here I want to open another shell window shell_2 who executes commands like "ls -l" or programs like ". /program"... so the "result" of commands shows in shell_2 window and not in shell_1. Is that possible ? (4 Replies)
Discussion started by: jerold
4 Replies

5. Shell Programming and Scripting

script - multiple telnets with logging

We had a system outage, and now I am trying to figure out how to get raw data to store in a log file. I have a flat file that has multiple IP port line. I want to telnet to each and log each. But as soon as I connect to the first, it stays there. This is on an HPUX 11.23 system. I dont think... (1 Reply)
Discussion started by: lhradowy
1 Replies

6. Shell Programming and Scripting

Script to compare 2 files and prints difference as output sidebyside

Hi All, Am trying script to compare 2 files and print the difference found from old file to new file on line by line basis on side by side display. Basically line by line comparision and files may contain blank line as well I know we have compare/diff commands but i don't how to make... (10 Replies)
Discussion started by: Optimus81
10 Replies

7. Shell Programming and Scripting

awk runs but output is empty

The awk below runs, however the output file is 0 bytes. It is basically matching input files that are 21 - 259 records to a file of 11,137,660 records. Basically, what it does is use the input files of which there are 4 to search and match in a large 11,000,000 record file and output the... (4 Replies)
Discussion started by: cmccabe
4 Replies

8. Shell Programming and Scripting

Same sed code prints(p) correct, but writtes(w) wrong output

Dear all, I am using sed as an alternative to grep in order to get a specific line from each of multiple files located in the same directory. I am using sed because it prints the lines in the correct order (unlike grep). When I write sed code that prints out the output I get it correct, but... (1 Reply)
Discussion started by: JaNaJaNa
1 Replies

9. Shell Programming and Scripting

awk runs and produces output but with error

When I run the awk below, I get an error message awk -v OFS='\t' '$(NF-1)=="Benign" || ($(NF-2) OFS $(NF-1))=="Likely Benign" {$(NF)=$(NF-2) OFS $(NF-1)} {print $0 }' input awk: cmd. line:1: (FILENAME=VUS FNR=8) fatal: attempt to access field -1 input Chr Start End Ref ... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. UNIX for Beginners Questions & Answers

How can i create a script that will ssh a device and type some commands?

Hi Guys, this is the scenario: ubuntu pc and I have 10 wireless devices that I need to check their firmware version. I would like to create a script that it will ask me IP, after I enter it, I hit enter then it will show me the version of the firmware. this is what i do. ssh... (9 Replies)
Discussion started by: gabak
9 Replies
CONNTRACKD(8)															     CONNTRACKD(8)

NAME
conntrackd - netfilter connection tracking user-space daemon SYNOPSIS
conntrackd [options] DESCRIPTION
conntrackd is the user-space daemon for the netfilter connection tracking system. This daemon synchronizes connection tracking states between several replica firewalls. Thus, conntrackd can be used to deploy highly available stateful firewalls. The daemon supports Primary- Backup and Multiprimary setups. The daemon can also be used as statistics collector. OPTIONS
The options recognized by conntrackd can be divided into several different groups. MODES These options specify the particular operation mode in which conntrackd runs. Only one of them can be specified at any given time. -d Run conntrackd in daemon mode. CLIENT COMMANDS conntrackd can be used in client mode to request several information and operations to a running daemon -i [ct|expect]" Dump the internal cache, i.e. show local states -e [ct|expect]" Dump the external cache, i.e. show foreign states -x Display output in XML format. This option is only valid in combination with "-i" and "-e" parameters. -f [|internal|external] Flush the internal and/or external cache -F [ct|expect] Flush the kernel conntrack table (if you use a Linux kernel >= 2.6.29, this option will not flush your internal and external cache). -c Commit external cache to conntrack table. -B Force a bulk send to other replica firewalls. With this command, you will ask conntrackd to send the state-entries that it owns to others. -n Request resync with other node (only FT-FW and NOTRACK modes). -k Kill the daemon -s [|network|cache|runtime|link|rsqueue|process|queue|ct|expect] Dump statistics. If no parameter is passed, it displays the general statistics. If "network" is passed as parameter it displays the networking statistics. If "cache" is passed as parameter, it shows the extended cache statistics. If "runtime" is passed as param- eter, it shows the run-time statistics. If "process" is passed as parameter, it shows existing child processes (if any). If "queue" is passed as parameter, it shows queue statistics. If "ct" is passed, it displays the general statistics. If "expect" is passed as parameter, it shows expectation statistics. -R [ct|expect] Force a resync against the kernel connection tracking table -t Reset the in-kernel timers (See PurgeTimeout clause) -v Display version information. -h Display help information. -C config file Configuration file path. DIAGNOSTICS The exit code is 0 for correct function. Errors cause an exit code of 1. EXAMPLES
The following example are illustrative, for a real use in a firewall fail-over, check the primary-backup.sh script that comes with the sources. conntrackd -d Runs conntrackd in daemon and synchronization mode conntrackd -i Dumps the states held in the internal cache, i.e. those handled by this firewall conntrackd -e Dumps the states held in the external cache, i.e. those handled by other replica firewalls conntrackd -c Commits the external cache into the kernel connection tracking system. This is used to inject the state so that the connections can be recovered during the failover. DEPENDENCIES
This daemon requires a Linux kernel version >= 2.6.18. TCP window tracking support requires >= 2.6.22, otherwise you have to disable it. Helpers are fully supported since >= 2.6.25, however, if you use any previous version, depending on the protocol helper and your setup (e.g. if you setup performs NAT sequence adjustments or not), your help connection may be successfully recovered. There are several unsupported stateful iptables matches such as recent, connbytes and the quota matches which gather internal information to operate. Since that information does not belong to the domain of the connection tracking system, connections affected by those matches may not be fully recovered during the takeover. The daemon requires a Linux kernel version >= 2.6.26 to support kernel-space event filtering. Otherwise, all the event filtering is done in userspace with the corresponding extra overhead. If you are not using the Filter clause in the configuration file, ignore this notice. INCOMPATIBILITIES
During the 0.9.9 development, some important changes in the replication message format were introduced. Therefore, conntrackd >= 0.9.9 will not work appropriately with conntrackd <= 0.9.8. This should not be a problem if you use the same conntrackd version in all the firewall replica nodes. SEE ALSO
conntrack(8),iptables(8) See http://conntrack-tools.netfilter.org BUGS
Please, report them to netfilter-devel@vger.kernel.org or file a bug in Netfilter's bugzilla (https://bugzilla.netfilter.org). AUTHORS
Pablo Neira Ayuso wrote and maintains the conntrackd tool Please send bug reports to <netfilter-devel@lists.netfilter.org>. Subscription is required. Man page written by Pablo Neira Ayuso <pablo@netfilter.org>. Oct 21, 2008 CONNTRACKD(8)
All times are GMT -4. The time now is 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy