On Sat, May 1, 2010 at 5:52 AM, hadi motamedi motamedi24@gmail.com wrote:
Thank you for your reply. I am trying like the followings: #expect
set name 172.16.17.160 set user id set password pwd set cmd1 "cd /tmp" set cmd2 "cp log.cap /export/home" set cmd3 "logout" spawn telnet $name expect "login:" send "$user" expect "Password:" send "$password" send "$cmd1" send "$cmd2" send "$cmd3" exit
Several things are wrong with this:
1. DO NOT EVER USE TELNET. Seriously. Don't do this. It sends your user/pass in plain text. It's a horrendous security risk. I don't care what excuse you have to try to defend it. DO NOT DO IT. Use ssh keys instead.
2. Use ssh keys instead of setting a password in the script.
3. You don't need to use expect to set the PWD to /tmp. You can do this with basic scripting. Pick up a bash scripting guide and read through it. I see almost nothing in your example that requires expect. This can be done with a simple bash script.