-RFXargs construct the parameter list and run the commandSh-x Debug ScriptsAutomatically unzip the ZIP packet scriptThe following script for the Automatic decompression zip package script, for reference only, can be modified according to the actual situation, can be extrapolate, applied to other applications.awk-f. ' {print $ #awk} ' Column Operations-F. with. As a delimiterPrint Input $ represents every 2 columnsActual combat: Expect enables n
written in front: currently in the company is a person a virtual machine, most of the work to be done on the virtual machine, to do so many times a day to perform the "ssh xxx@xxxxxx" instructions to log on to the virtual machine, there are many ways to solve this problem, such as the use of Xshell, SecureCRT and other tools to record commonly used connections, I wrote a simple script to achieve one-click Login ~
The contents of the login.sh script are as follows:
#!/usr/bin/
To achieve a highly automated system resource monitoring and implementation of the log file upload (FTP) When monitoring data anomalies, the following script is implemented (script name: autofileupload):#!/usr/local/bin/expect
Set file [lindex $argv 0];#set Date [lindex $argv 1];Set timeout-1;While {1} {Spawn FTP 218.108.xxx.xxx;Expect "Name";Send "TEST/R";Expect
A previous use of rancid to configure Cisco's equipment compared, but apparently rancid is not very friendly to Huawei, has not supported Huawei devices (including H3). Therefore, because I still a little clever, know Rancid is expect and CVS to achieve, so he wrote some more stupid script to the Huawei equipment to do configuration comparison.
1) to Huawei Equipment grab configuration
#!/usr/local/bin/expect
The core of expect is that spawn expect send set Spawn:spawn is the expect internal command that can be executed after entering the expect environment, equivalent to the built-in command in the shell, through which the command to execute is called expect: capture hint Send:
The previous two posts have explained how to back up the configuration file, the function of the expect script is to provide interaction, log in each switch to perform a backup command to copy it to the TFTP server. But in our normal work, the general backup method is to dis cu or sh run and then copy the information on the screen, in fact, the previous script can be slightly modified to use this method to back up the configuration, of course, this me
Tags: Linux ops linux cloud Linux Essentials Linux Basicsexpect is based on Tcl's relatively simple one freeof theThe Scripting tool language, a software suite for automating interactive functions. Like SSH .,ftp And so on, these programs normally need to be manually andits interaction, and the use of expect can simulate the process of human interaction, automatic program interaction, to achieve the purpose of automation. C, Perl, and so on, but
Another small trick, using the expect scripting language to implement SSH automatic connection to the server, you can automatically enter the password. Because every time using SSH root@xx.xx.xx.xx connection server, you have to manually enter the password, there is no way to automatically enter the password it?
Search on the Internet, there is a way, there is a script language expect, its role is to inter
Recently, the Linux batch execution of the script is very interested in looking around the Internet for expect batch execution script, today to share a batch password modification script.
Script content:
Copy Code code as follows:
#!/usr/bin/expect
If {$ARGC Send_user "Usage: $argv 0 Exit
}
# machine List data format: IP port old password new password
Set hostfile [Open [lindex $argv 0
Expect non-switched command test example: non-switched login to a server, usually the first time to log on to a server, you need to click Yes, and then enter the password, we aim to pass the expect analog input[[emailprotected] ~]# ssh 10.3.151.31The authenticity of host ‘10.3.151.31 (10.3.151.31)‘ can‘t be established.RSA key fingerprint is 08:1e:93:79:5c:0f:6c:de:68:d5:e8:57:8c:44:a5:57.Are you sure you w
A user name password is required in the most recently used script, so expect is used to summarize the points of use and attention
First, the expect needs to be installed after installation, the installation method is very simple, using the Yum install expect to complete the installation.
The script is roughly as follows:
#!/bin/bash
/usr/bin/
Required Files:Password #远程主机的ip password fileExpect #执行远程登录, script file to execute the commandlogin.sh #shell Footsteps Call these two files to perform the operation#!/bin/bashforiin$ (awk ' {print$1} ' Passwd.txt) # For loop out host IP information dop=$ (awk-vi= "$i" ' {if (i==$1) print$2} ' passwd.txt) # Remove the password for the corresponding IP host expect/root/login $i $p #传递ip和密码信息到expectdone #!/usr/bin/
When you use a shell to write a program, you sometimes have to confront the problem of interaction--unfortunately, the shell can't automatically complete the interaction. If the interactive content is many, it is convenient to apply expect script directly, if the content of interaction is very small, and considering the usability of shell, it is more convenient and flexible to create a expect here document
The development of a Linux Ubuntu system, there is no similar securecrt tools, every time you log on to the Linux system need to enter a password,It's a waste of time. A script is then made to log in to the Linux system each time they enter a server alias directly. Followingis the specific operation steps:
1.vim/root/expect_ssh.exp#!/usr/bin/expect-fset Timeout 99set host [lindex $argv 0]set Port [lindex $argv 1]set username [lindex $argv 2]set P
Pexpect is an automated Python module that can be used for automatic interaction in SSH, FTP, passwd, Telnet, and other command lines. The official website is http://www.noah.org/. With it, you can implement a similar expect operation.
For example, we can use it to write Python scripts that implement bulk operations on a series of Linux servers with the same configuration.
If you are not familiar with expect
1. Edit copycgi.sh, the main user to filter the files to be transmitted, as follows:
#!/bin/bashPath= "./"If [$#-eq 1]; ThenPath=$1if [!-d $path]; Thenecho "Please input valid dir."ExitFiFi
Ls-al ${path}/*.cgi|while Read LineTodoFilename= ' echo $line | awk ' {print $} '#!echo "Start Send" $filename./expect_scp_one.sh $filenameecho "Send ${filename} Finish"Done
2. Edit the expect_scp_one.sh file, mainly used to transfer the specified file to the specified machine, the contents are as follows
#!/
#!/bin/bashlocal_dir= '/tmp/test_huadan ' ip= ' 192.168.0.221 ' password= ' Lhm0125 ', des_dir= '/tmp/test_huadan ' list=$ ( Find $Local _dir-cmin-60) for i in $List do#echo $i if [-f $i] then expect This article is from the "Python" blog, so be sure to keep this source http://9473814.blog.51cto.com/9463814/1652385Shell example of skipping password authentication with expect
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.