automate systems using linux and windows program called expect

View previous topic View next topic Go down

automate systems using linux and windows program called expect

Post by jamied_uk on 17th May 2012, 14:19

http://www.youtube.com/watch?v=dlwqyMW5H5I&feature=relmfu



automate systems
http://expect.sourceforge.net/
example codes


ssh root@172.16.42.1
expect "password"
send "pinapplesareyunny\r"
expect "root@pinapple"
send "opkg install /tmp/*.1pk\r"
expect "root@pinapple"
send "tcpdump port 80 and not src 172.16.42.1\r"
interact



ls

cat tcpdump.exp

./tcpdump.exp




example

# Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier
# in the script.
# Open a telnet session to a remote server, and wait for a username prompt.
spawn telnet $remote_server
expect "username:"
# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"
expect "%"
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"
expect "%"
# Capture the results of the command into a variable. This can be displayed, or written to disk.
set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
expect eof
avatar
jamied_uk
Admin

Posts : 2260
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum