1. Write a loop to ping the IP of the entire subnet. using the while loop#!/bin/bash ip=223 While ["$ip"-ne "239"]do ping 121.201.0. $ip-c1 && echo "121.201.0. $ip yes" >> Ip_list.txt | | echo "121.201.0. $ip No" >> ip_list.txt ((ip+=1)) doneuse for loop (recommended)#!/bin/bashfor IP in 192.168.1. {100..255} do ping $ip-C 1 && echo $ip Yes >>./check_ip_network.txt| | echo $ip no >>/check_ip_network.txtdone
2, 9*9 multiplication table
#!/bin/bash
For a in {1..9}
Do
For b in {1..9}
Do
[$a-ge $b] && echo-en "$a x $b = $ (expr $a \* $b)"
Done
echo ""
Done [[email protected]shell]# SH 9x9.sh
1 x 1 = 1
2 x 1 = 2 2 x 2 = 4
3 x 1 = 3 3 x 2 = 6 3 x 3 = 9
4 x 1 = 4 4 x 2 = 8 4 x 3 = 4 x 4 = 16
5 x 1 = 5 5 x 2 = 5 x 3 = 5 x 4 = 5 x 5 = 25
6 x 1 = 6 6 x 2 = 6 x 3 = 6 x 4 = 6 x 5 = 6 x 6 = 36
7 x 1 = 7 7 x 2 = 7 x 3 = 7 x 4 = 7 x 5 = 7 x 6 = 7 x 7 = 49
8 x 1 = 8 8 x 2 = 8 x 3 = 8 x 4 = 8 x 5 = 8 x 6 = 8 x 7 = 8 x 8 =
9 x 1 = 9 9 x 2 = 9 x 3 = 9 x 4 = 9 x 5 = 9 x 6 = 9 x 7 = 9 x 8 = 9 x 9 = 81
3. Shell springboard (shielding signal after triggering signal)
Method 1:1) First do SSH key authentication, do SSH key no login verification 2) to implement the traditional remote Connection menu selection script 3) Use the Linux signal to prevent users from operating on the springboard machine. 4) When the user logs in, both scripts are invoked. The code is as follows: [[email protected]practical_script]# Cat tiaoban.sh
#!/bin/bash
# function
function trapper ()
{
Trap ': ' INT EXIT TSTP term HUP
}
While:
Do
Trapper
Clear
Cat <<menu
# This was a springboard machine, can through the springboard
# machine landing the following system.
Please select the server want to log on:
1) Link 126.201.20.132 (TT3)
2) exit
Menu
Read-p "Pleas select:" num
Case ' $num ' in
1)
echo "126.201.20.132 (TT3) landing ..."
Ssh-p 26333[email protected]
;;
2|*)
Exit
;;
Esacdone
method 2:root The linked server, expect SSH key each time it is re-established ###########################################################################################
4. Shell Programming Lamp One-click installation Script Combat[[email protected]shell]# Cat autolamp.sh
#!/bin/bash
#auto make install LAMP
#by Auto LY 2015
# httpd Define Path varible
h_files=httpd-2.2.31.tar.bz2
h_files_dir=httpd-2.2.31
h_url=http://mirrors.cnnic.cn/apache/httpd/
h_prefix=/usr/local/apache2/
M_files=mysql-5.0.41.zip
m_files_dir=mysql-5.0.41
m_url=http://gyconfigfc.attogames.com/
m_prefix=/usr/local/mysql/
# PHP Define PATH variable
p_files=php-5.3.28.tar.bz2
p_files_dir=php-5.3.28
p_url=http://mirrors.sohu.com/php/
p_prefix=/usr/local/php5/
If [-Z "$"];then
Echo-e "\033[36mplease Select Install Menu follow:\033[0m"
Echo-e "\033[32m1) Compile and install Apache server:\033[1m"
echo "2) Compile and install MySQL server"
echo "3) Compile and install PHP server"
echo "4) Configure index.php and start the LAMP service"
Echo-e "\033[31musage: {$ 1 | 2 | 3 | 4 | Help}\033[0m "
Exit
Fi
If [$1-eq 1];then
Wget-c $H _url/$H _files && tar-jxvf $H _files && cd $H _files_dir;. /configure--prefix= $H _prefix
If [$?-eq 0];then
Make && make install
Echo-e "\033[32mthe $H _files_dir Server Install successfully!\033[0m"
Else
Echo-e "\033[31mthe $H _files_dir Server Install failed,please check ... \033[0m"
Fi
Fi
# Auto Install Mysql
If [$1-eq 2];then
Wget-c $M _url/$M _files && unzip $M _files && cd $M _files_dir; chmod +x Configure && chmod +x Insta Ll-sh;. /configure--prefix= $M _prefix
If [$?-eq 0];then
Make && make install
Echo-e "\033[32mthe $M _files_dir Server Install successfully!\033[0m"
Else
Echo-e "\033[31mthe $M _files_dir Server Install failed,please check ... \033[0m"
Fi
Fi
# Auto Install PHP Server
If [$1-eq 3];then
Wget-c $P _url/$P _files && tar-jxvf $P _files && cd $P _files_dir;. /configure--prefix= $P _prefix--with-config-file-path= $P _prefix/etc--with-mysql= $M _prefix--with-apxs2=/usr/local /apache2/bin/apxs
If [$?-eq 0];then
Make && make install
Echo-e "\033[32mthe $P _files_dir Server Install successfully!\033[0m"
Else
Echo-e "\033[31mthe $P _files_dir Server Install failed,please check ... \033[0m"
Fi
Fi
If [$1-eq 4];then
Sed-i '/directoryindex/s/index.html/index.php index.html/g ' $H _prefix/conf/httpd.conf
$H _prefix/bin/apachectl Restart
echo "AddType application/x-httpd-php. php" >> $H _prefix/conf/httpd.conf
ip= ' ifconfig eth0|grep "bcast" |awk ' {print $} ' |cut-d:-f2 '
echo "You can access/HTTP $IP/"
Cat > $H _prefix/htdocs/index.php <<eof
<?php
Phpinfo ();
?>
Eof
Fi################################################################################################
Shell Script case