CentOS uses expect to execute scripts and commands remotely in batches
We may sometimes operate the server in batches, such as uploading a file on the server in batches, installing software, executing a command and script, restarting the service, restarting the server, etc., which is particularly cumbersome and a waste of manpower if we go to one server by hand.
At this point, we can use expect to send instructions to the target server to implement batch operations.
The following example will bulk copy a file to another service provider on centos and execute the corresponding command
1. Install expectyum install expect2. Net on centos. Write expect script copyfilebatch.sh
The following script will copy a rc.local file to the server whose intranet IP is 192.168.0.102 to 192.168.0.112 respectively. After the copy is successful, execute the chmod command to restart the server respectively.
#! / usr/bin/expect-fset password rootpasswordfor {set I 102} {$I