automate systems using linux and windows program called expect

Go down

automate systems using linux and windows program called expect Empty automate systems using linux and windows program called expect

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

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
jamied_uk
jamied_uk
Admin

Posts : 2471
Join date : 2010-05-09
Age : 36
Location : UK

http://address-shortner.co.uk

Back to top Go down

Back to top


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