Do you know Linux? Are you a Linux system application? If you want to learn Linux, you may encounter the Linux Shell automatic interaction problem, here will introduce the Linux Shell automatic interaction solution, here to share with you. First, the background shell script can save a lot of time in dealing with automatic loops or large tasks. By creating a list of commands for processing tasks, using variables, conditions, arithmetic, and loops to quickly create scripts to complete the work, this is better than It takes a lot of time and effort to type commands one by one on the command line. But sometimes we may need to implement interaction with interactive programs such as ftp, telnet server, etc. At this time we need to use the shell's automatic interaction function, this article collects three commonly used automatic interaction methods, and compares them. And summary. Second, the demand Demand 1: From a Linux machine ftp login to another Linux machine, after a series of operations closed, too lazy to manually enter the password each time. Requirement 2: Change the login user password, too lazy to enter new and old passwords every time. Requirement 3: I want su to log in to the root account automatically. I am too lazy to enter the root password every time. Third, the debugging environment terminal: SecureCRT system: WinXP, CentOS 4.4 (VmWare)
Shell: bash Note: There are many kinds of shell, B class SHELL (sh, bash, ksh) behavior is similar; C class SHELL (csh, tcsh) behavior is similar, there are shells such as zsh and rc, the debugging environment of this article is bash. Fourth, the automatic interaction method The most critical part of the automatic interaction is the automatic input of interactive information, first think of file redirection, there is such a usage in shell programming (refer to Linux and UNIX SHELL programming guide chapt 5.7): "command < ;< delimiter reads from standard input until it encounters the delimiter delimiter. The " redirection operator command << delimiter is a very useful command, the shell will take all the content before the delimiter delimiter until the next same delimiter as input, encounter the next delimiter, the shell will I know that the input is over. The most common delimiter delimiter is EOF, and of course you can customize it to other characters. For the automatic login ftp required by requirement 1, and for a series of operations, this method can be used for automatic interaction. The code is as follows: 1. #!/bin/bash 2. ftp -i -n 192.168.167.187 << EOF 3. user hzc 123456 4. pwd 5. cd test 6. pwd 7. close 8. bye 9. EOF Tests can be found, the above code uses the account name hzc, password 123456 successfully logged into the ftp server, and entered the directory, printed out pwd. V. Automatic Interaction Method 2 Requirement 2 requires a non-interactive way to change the login user password. Try Method 1 and cannot be implemented. This is another automatic input method that associates interactive information, pipeline, via echo + sleep +
Linux supports sharing open files between different processes. To illustrate file sharing, lets firs
◆ Installation and Login: login, shutdown, halt, reboot, install, mount, umount, chsh, exit, last◆ F
Enterprise customers install SCOM2012 behind the constantly generated alarms, performance, informat
In the era of virtualization and cloud computing and the container, we migrated all the application
Current sinking, current sinking, sinking current, pull-up resistor, high resistance state analysis
Linux tar, gz, bz2 and other decompression file usage methods
How to solve the problem that the Linux operating system can't find the network card
Linux forced delete non-empty directory command
Basic tutorial on flexible use of RPM tools under Linux
Linux does not start properly. Solution
Modify the time zone using the command line in Linux
Neighbor subsystem of linux protocol stack (related process 5)
Tenth Anniversary of Red Hat Enterprise Linux
Virtualbox command line sharing CentOS directory
Five Linux simple commands to help you solve performance problems
People abroad, how to use the win8 system to see the domestic Asian Cup?
How to set win8 to close the touchpad? Win8.1 disable touchpad tutorial
Flat solution for game screens under Windows 7
Photoshop CS5 advanced features control deformation tutorial [group map]
How does Windows 7 turn off system protection?
Microsoft changes Windows support policy New CPU must install Win10
The right medicine to let Win7 dual hard drive no longer automatically shut down