In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "installation of expect environment under linux and simple script testing". In daily operation, I believe that many people have doubts about the installation of expect environment under linux and simple script testing. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "installation of expect environment under linux and simple script testing". Next, please follow the editor to study!
First, install expect and tcl
(1) extract the tcl, enter the tcl directory, and then go to the unix directory to compile and install
[root@slient tmp] # tar-xzvf tcl8.4.11-src.tar.gz
..
[root@slient tmp] # cd tcl8.4.11/unix/
[root@slient unix] #. / configure
..
[root@slient unix] # make & & make install
..
(2) install expect
[root@slient tmp] # tar-xzvf expect-5.43.0.tar.gz
..
[root@slient tmp] # cd expect-5.43
[root@slient expect-5.43] # / configure-- with-tclinclude=/tmp/tcl8.4.11/generic-- with-tclconfig=/usr/local/lib/
..
[root@slient expect-5.43] # make & & make install
..
(3) testing after installation is completed
[root@slient expect-5.43] # expect
Expect1.1 >
Expect1.1 >
Second, let's do a simple test with shell script.
Example: automatically log in to the remote machine 192.168.56.12 from the local machine (port 22, password: oracle)
After logging in to the remote machine, do the following:
1) useradd wangshibo
2) mkdir / opt/test
3) exit automatically exits
[root@slient ~] # cat test-ssh.sh
#! / bin/bash
Passwd='oracle'
/ usr/local/bin/expect
Expect "password:"
Send "oracle\ n"
Expect "sftp >"
Send "lcd / home/oracle/dmp\ n"
Expect "sftp >"
Send "cd / home/oracle/soft\ n"
Expect "sftp >"
Send "put tb_pt.dmp\ n"
Expect "sftp >"
Send "exit\ n"
Interact
!
[oracle@slient ~] $
[oracle@slient ~] $chmod + x sftp.sh
-- execute:
[oracle@slient ~] $sh sftp.sh
Spawn sftp oracle@192.168.56.12
Connecting to 192.168.56.12...
Oracle@192.168.56.12's password:
Sftp > lcd / home/oracle/dmp
Sftp > cd / home/oracle/soft
Sftp > put tb_pt.dmp
Uploading tb_pt.dmp to / home/oracle/soft/tb_pt.dmp
Tb_pt.dmp 100% 216KB 216.0KB/s 00:00
Sftp > [oracle@slient ~] $
[oracle@slient ~] $
-- verify:
[oracle@one soft] $pwd
/ home/oracle/soft
[oracle@one soft] $
[oracle@one soft] $ls
[oracle@one soft] $pwd
/ home/oracle/soft
[oracle@one soft] $ls
Tb_pt.dmp
[oracle@one soft] $
IV. Example explanation
Example:
#! / usr/bin/expect
# set timeout 20 # set the timeout
Spawn ssh root@192.168.43.131
Expect "* password:"
Send "123\ r"
# expect "*"
Interact
Explanation:
1. Please install the software first and then explain how to execute it with expect.
2.spawn ssh root@192.168.43.131: spawn is an internal expect command that can be executed after entering the expect environment to execute the commands that follow it.
3.expect "* password:": is also the internal command of expect, which is used to solve the key strings. If there is any, it will immediately return the content set below. If not, it depends on whether the timeout is set.
4.send "123\ r": the interactive action is performed at this time, which is equivalent to manually entering the password. After expect intercepts the keyword, it will enter the content after the send.
5.interact: hold the interaction state after execution, turn the console, and then you can do what you want to do. Without this sentence, it will exit after the login is completed, rather than leaving it on the remote terminal.
At this point, the study on "installation of the expect environment under linux and simple script testing" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.