728x90
리눅스에서 shell script telnet을 자동 접속하는 방법
Link : http://knamhun.blogspot.kr/2008/04/telnet.html?m=1
Install telnetd server
$ sudo apt-get install telnetdRestart inetd service:
$ sudo /etc/init.d/openbsd-inetd restart
You should now be able to telnet to the server from Windows or Linux desktop system to Ubentu Linux telnet server. Type the following command to connect to Telnet server:
Install "expect"
# sudo apt-get -y install expect
Install "spawn"
# sudo apt-get -y install spawn-fcgi
Telnet 자동 접속 쉘 프로그래밍
#!/usr/bin/expect
spawn telnet aaa.co.kr
expect -re "login: "
sleep 1
send "아이디\r"
expect -re "password: "
sleep 1
send "패스워드\r"
interact
=================================================================
먼저 spawn 이란 넘이 telnet 명령을 실행합니다.
expect -re "login: " 은 login: 이란 단어가 나올때 까지 기다리는 거죠.
telnet 을 실행하면 login 이란 단어가 출력이 됩니다.
이때 아이디를 보내줍니다. (send)
그 다음 또 password 란 단어를 기다립니다. (expect -re "password: ")
그러면 비밀번호를 보줍니다. (send)
그 다음 expect 가 제어를 종료합니다. (interact )
man expect 하시면 더 많은 정보를 얻을 수 있습니다.
그리고 expect가 /usr/bin/expect에 없는경우도 있습니다.
그럴경우 which expect 라고 명령을 실행하면 경로가 나옵니다...
하지만 설치가 안됬을경우는 설치하시면됩니다..^^;
spawn telnet aaa.co.kr
expect -re "login: "
sleep 1
send "아이디\r"
expect -re "password: "
sleep 1
send "패스워드\r"
interact
=================================================================
먼저 spawn 이란 넘이 telnet 명령을 실행합니다.
expect -re "login: " 은 login: 이란 단어가 나올때 까지 기다리는 거죠.
telnet 을 실행하면 login 이란 단어가 출력이 됩니다.
이때 아이디를 보내줍니다. (send)
그 다음 또 password 란 단어를 기다립니다. (expect -re "password: ")
그러면 비밀번호를 보줍니다. (send)
그 다음 expect 가 제어를 종료합니다. (interact )
man expect 하시면 더 많은 정보를 얻을 수 있습니다.
그리고 expect가 /usr/bin/expect에 없는경우도 있습니다.
그럴경우 which expect 라고 명령을 실행하면 경로가 나옵니다...
하지만 설치가 안됬을경우는 설치하시면됩니다..^^;
728x90
'OS > Linux' 카테고리의 다른 글
vi에서 호출 함수 찾아가기 (0) | 2014.10.23 |
---|---|
vim 환경 변수 설정 (1) | 2014.10.22 |
Linux grep 명령어 (0) | 2014.10.22 |
Linux find 명령어 (0) | 2014.10.22 |
Package List of Ubuntu (3) | 2012.10.30 |