First
set a small goal, first proficient in the shell say! --OLD boyUseShelldeveloping a Springboard function script case
example 17_6: Developing an Enterprise-class Shell springboard machine case. Requiring a user to log on to a springboard machine can only perform an administrator-given option action, and does not allow any form of interrupt script to execute any system commands on the board server.
Method 1:
1) First do SSH Key Verification (Springboard address 192.168.33.128).
The following operation commands operate on all machines:
[[Email protected]~]# useradd Jump #<== to be operated on all machines.] [[Email protected]~]# echo 123456|passwd--stdin jump #<== to be operated on all machines.] Changingpassword for user Jump.passwd:all authentication tokens updated successfully.
The following operation commands are only operated on a springboard machine:
[[EMAIL&NBSP;PROTECTED]~]#&NBSP;SU&NBSP;-&NBSP;JUMP[[EMAIL&NBSP;PROTECTED]~]$&NBSP;SSH-KEYGEN&NBSP;-T&NBSP;DSA -P ' -f ~/.ssh/id_dsa >/dev/null 2>&1 #<== generates a key pair. [[email protected]~]$ ssh-copy-id -i ~/.ssh/id_dsa.pub 192.168.33.130 #<== distributes the public key to other servers. theauthenticity of host ' 192.168.33.130 (192.168.33.130) ' can ' t be Established. rsa keyfingerprint is fd:2c:0b:81:b0:95:c3:33:c1:45:6a:1c:16:2f:b3:9a. are yousure you want to continue connecting (yes/no)? yesWarning: permanently added ' 192.168.33.130 ' (RSA) to the list of known Hosts. [email protected] ' spassword:now trylogging into the machine, with ' ssh ' 192.168.33.130 ' ", and check in: .ssh/authorized_keys to Makesure we haven 'T added extra keys that you weren ' t expecting. [[email protected] ~]$ ssh-copy-id -i ~/.ssh/id_dsa.pub 192.168.33.129 #<== distributes the public key to other servers. theauthenticity of host ' 192.168.33.129 (192.168.33.129) ' can ' t be Established. rsa keyfingerprint is fd:2c:0b:81:b0:95:c3:33:c1:45:6a:1c:16:2f:b3:9a. are yousure you want to continue connecting (yes/no)? yesWarning: permanently added ' 192.168.33.129 ' (RSA) to the list of known Hosts. [email protected] ' spassword:now trylogging into the machine, with ' ssh ' 192.168.33.129 ' ", and check in: .ssh/authorized_keys to Makesure we haven ' T added extra keys that you weren ' t expecting.
2) Implement the traditional Remote Connection menu selection script.
The menu script is as follows:
Cat <<menu 1) oldboy-192.168.33.129 2) oldgirl-192.168.33.130 3) Exi Tmenu
3) Use the Linux signal to prevent user interrupt signal operation on the springboard.
Functiontrapper () {trap ': ' INT EXIT tstp term HUP #<== Shield these signals. }
4) The user logs on to the board after the call script (not command line management Board), and only according to the administrator's request menu.
The following is the actual content.
The script is placed on a springboard machine:
[[email protected]~]# echo ' [ $UID -ne 0 ] && . / Server/scripts/jump.sh ' >/etc/profile.d/jump.sh [[email protected]~]# cat /etc/ profile.d/jump.sh[ $UID-ne 0 ] && . /server/scripts/jump.sh[[email Protected]]# cat /server/scripts/jump.sh#!/bin/sh#oldboy trainingtrapper () { trap ': ' int exit tstp term hup #<== defines a signal that needs to be masked, and a colon means nothing. }main () {while :d o trapper clear &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CAT<<MENU&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;1) WEB01-192.168.33.129&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2) web02-192.168.33.130menuread -p "Pls Input a num.: " numcase" $num " in 1) echo ' LOGIN&NBSP;IN&NBsp;192.168.33.129. ' ssh 192.168.33.129 ;; 2) echo ' login in 192.168.33.130. ' ssh 192.168.33.130 ;; 110) read -p "your Birthday: " char if [ " $char " = " 0926 "] ;then exit sleep 3 fi ;; *) echo "Select error." esacdone}maInch
The execution effect is as follows:
[[email protected]~]# su - jump #<== cut to the normal user is the pop-up menu, working directly with the jump login, that is, pop-up menu.] 1) web01-192.168.33.129 2) Web02-192.168.33.130Pls inputa num.: 1) web01-192.168.33.129 2) web02-192.168.33.130pls inputa num.:1 #<== Select 1 to enter the WEB01 server. login in192.168.33.129.lastlogin: tue oct 11 17:23:52 2016 from 192.168.33.128[[email protected]~]$ #<== Press Ctrl+d to exit to the Springboard Server popup menu again. 1) web01-192.168.33.129 2) Web02-192.168.33.130Pls inputa num.:2 #<== Select 2 to enter the WEB02 server. login in192.168.33.130.lastlogin: wed oct 12 23:30:14 2016 from 192.168.33.128[[email protected]~]$ #<== Press Ctrl+d to exit to the Springboard Server popup menu again. &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;1) web01-192.168.33.129&NBSP;&NBSP;&NBSP;&NBSP;2) web02-192.168.33.130pls inputa num.:110 #<= = Select 110 to enter the Springboard command prompt. yourbirthday:0926 #<== need to enter a special code to enter, where the Administrator channel, password to be confidential yo. [[email protected]]# #<== Board Management Command line.]
This article is from: "With the old boy learn Linux operations:Shell Advanced Programming Combat," the most understandable shell books in the country!
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/8F/D2/wKiom1js1P-jraZNAAYQu52RJ7k536.jpg "title=" Old boy shell Programming stereoscopic diagram. jpg "alt=" wkiom1js1p-jraznaayqu52rj7k536.jpg "/>
This article is from the "Old Boys Linux Training" blog, make sure to keep this source http://oldboy.blog.51cto.com/2561410/1915017
Using Shell to develop a springboard function script case