Shell supplemental tool-CT

Source: Internet
Author: User
In shell supplement tool-expectlinux, in shell programming, some program input must receive tty input rather than stdin input. if one implementation is required, it is always Ct. 1. install expect1yuminstallexpect 2, instance 1, and ssh for automatic login, and... shell supplement tool-except CT in linux, in shell programming, some program input is to receive tty input rather than stdin input, if you need an implementation, it is always Ct. 1. install expect1yum install login Ct 2, instance 1, and ssh to automatically log on and stop at the login server 01 #! /Usr/bin/CT-f02 set ip www. factj. com03 set password [lindex $ argv 0] // receives the first parameter, and set the password 04 set timeout 10 // set the timeout 05 spawn ssh root @ $ ip // send ssh requests? E06 exact Ct {// The Returned information matches 07 "* yes/no" {send "yes \ r"; exp_continue} // The First ssh connection will prompt yes/no, continue 08 "* password:" {send "$ password \ r"} // The password prompt is displayed. send the password 09} 10 interact // interaction mode, the user will stay on the remote server. the running result is as follows: 1root @ factj:/home/factj #. /test. exp factj2spawn ssh root @ w Last login: Fri Sep 7 10:47:43 2013 from www. factj. com3 [root @ linux ~] # This example has a unified interface, which can be connected to different machines based on the IP address and password. if you are too troublesome to enter the IP address and password, refer to the following example 01 #! /Usr/bin/CT-f02 set ip www. factj. com03 set password factj04 set timeout 1005 spawn ssh root @ $ ip06 exact Ct {07 "* yes/no" {send "yes \ r"; exp_continue} 08 "* password: "{send" $ password \ r "} 09} 10interact running result: 1root @ ubuntu:/home/zhangy #. /web. exp2spawn ssh factj@www.factj.com3Last login: Fri Agu 7 12:59:02 2013 from www. factj. com4 [root @ linux ~] #2. log on to the server remotely through ssh and run the command. after the command is executed, exit 01 #! /Usr/bin/CT-f02 set ip www. factj. com03 set password factj04 set timeout 1005 spawn ssh root @ $ ip06 exact Ct {07 "* yes/no" {send "yes \ r"; exp_continue} 08 "* password: "{send" $ password \ r "} 09} 10 your CT" # * "11 send" pwd \ r "12 send" exit \ r "13 your Ct eof running results: 01root @ ubuntu:/home/zhangy #. /test3.exp02spawn ssh root@www.factj.com03root @ www.factj.com's password: 04 Last login: Fri agu 7 14:05:07 2013 From 116.246.27.9005 [root @ localhost ~] # Pwd06/root07 [root @ localhost ~] # Exit08logout09 10 Connection to www.factj.com closed.3, remotely log on to ftp and download file 01 #! /Usr/bin/empty CT-f02 set ip [lindex $ argv 0] 03 set dir [lindex $ argv 1] 04 set file [lindex $ argv 2] 05 set timeout 1006 spawn ftp $ ip07 your CT "Name *" 08 send "zwh \ r" 09 your CT "Password: * "10 send" zwh \ r "11 keep CT" ftp> * "12 send" LCD $ dir \ r "13 keep Ct {14" * file "{send_user" local $ _ dir no such file or directory "; send "quit \ r"} 15 "* now *" {send "get $ dir/$ file \ r"} 16} 17 Failed Ct {18 "* Failed "{send_user" remote $ file No such file "; send "quit \ r"} 19 "* OK" {send_user "$ file has been download \ r"; send "quit \ r"} 20} 21 CT eof the following running results: 01root @ ubuntu:/home/zhangy #. /test2.exp www.factj.com/var/www aaa.html 02 spawn ftp www. factj. com03Connected to www.factj.com. 04220 (vsFTPd 2.0.5) 05 Name (www.factj.com: root): zwh06331 Please specify the password.07Password: 08230 Login successful.09Remote system type is UNIX.10Using binary mode to transfer files.11ftp> LCD/var/www/www12Local directory now/var/www/www13ftp> get/var/www/aaa.html/var /www/aaa.html 14 local: /var/www/aaa.html remote:/var/www/aaa.html 15200 PORT command successful. consider using PASV.16150 Opening BINARY mode data connection for/var/www/aaa.html (66 bytes ). 17226 File send OK .1866 bytes encoded Ed in 0.00 secs (515.6 kB/s) 19 quit aaa.html has been download20221 Goodbye.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.