expect script to telnet into a router
I have a Thomson TG784 router, where I would like to log in automatically and execute dhcp server lease flush command.
When I log in using telnet, the process is following: Code:
martin@martin-desktop:~$ telnet 192.168.1.254 Code:
root@martin-desktop:/home/martin# cat expect_script.sh Code:
root@martin-desktop:/home/martin# ./expect_script.sh |
Have you considered using `autoexpect` to try the session, and have the script generated automatically?
Example: Code:
$ autoexpect telnet 192.168.1.254 If interested, check the man page for autoexpect. (P.S. - maybe you're pretty good with expect :) but I'm not - I found autoexpect to be really handy.) Good luck! |
GrapefruiTgirl, thanks! This autoexpect is very handy indeed. The problem with my expect_script.sh was, that I didn't wait for asterisk characters from 192.168.1.254 :)
However, I would like to make an expect script, which asks for username and password when script is executed. Password query from user should be in following manner: Code:
stty_orig=`stty -g` So far I have come up with this, but it's not quite what I want: Code:
#!/usr/local/bin/expect -f |
The "plain passwords in scripts" is a somewhat common query for which I don't have a known-good suggestion. Try an LQ search for "plain text password script" and look at the first half-dozen results or so, and see if anything looks appealing.
I like what it appears you are doing above there in post #3 -- but that still requires human interaction, yes? Of course, if I'm understanding this whole situation correctly, you (a human) are actually executing this script somehow manually anyway, aren't you? If so, what would be wrong with having to input the password upon script execution, rather than store it inside the script? (I'm thinking of Bash's `read` command in silent mode -- does expect have such a thing?) |
Quote:
|
Martin,
from the `expect` man page: Code:
expect_user [expect_args] |
All times are GMT -5. The time now is 03:35 AM. |