1,写一个循环,ping整个子网的ip。
 
使用while循环
#!/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))
done
 
使用for循环(推荐)
#!/bin/bash
for 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.txt
done
 

2, 9*9乘法表

#!/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
 
[root@shell 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 = 12 4 x 4 = 16 
5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 
6 x 1 = 6 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36 
7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 
8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64 
9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81
 

3. shell跳板机(触发信号后屏蔽信号)

方法1:
1)首先做好ssh key验证,做ssh key免登陆验证
2)实现传统的远程连接菜单选择脚本
3)利用linux信号防止用户在跳板机上操作。
4)用户登陆后既调用脚本。
 
代码如下:
[root@shell practical_script]# cat tiaoban.sh 
#!/bin/bash

# function
function trapper ()
{
        trap ':' INT EXIT TSTP TERM HUP
}
while :
do
        trapper
                clear
                        cat <<menu
# This is a springboard machine, can only be through the springboard 
# machine landing the following system.

        Please select the server you 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 xxllen@126.201.20.132
                ;;
        2|*)
                exit
                ;;

esac

done

 
方法2: root链接服务器,expect 每次重新建立ssh key
 
###########################################################################################
4. Shell编程之LAMP一键安装脚本实战
[root@shell 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 "$1" ];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: {$0 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 install-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 $2}'|cut -d: -f2`
        echo "You can access http://$IP/"

cat >$H_PREFIX/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
fi
################################################################################################
 

shell脚本 案例的更多相关文章

  1. shell脚本案例分享 - 业务系统日志自定义保留或删除需求

    需求说明:  线上某些业务系统的日志不定期产生, 有的每天产生, 有的好几天才产生, 因为系统只有在用的时候才产生日志,日志文件均存放在以当天日期命名的目录下. 当日志目录越来越多时就需要处理, 由此 ...

  2. shell脚本案例

    1.MySQL数据库备份脚本,下面的脚本是Mysql全量备份+异地备份 一般Mysql数据库备份会采用在MYSQL从库上执行全量备份+增量备份方式.在从库备份避免Mysql主库备份的时候锁表造成业务影 ...

  3. 非交互式shell脚本案例-实现自主从oracle数据库获取相关数据,并在制定目录生成相应规则的文件脚本

    get_task_id 脚本内容 #!/usr/bin/expect#配置登陆数据库的端口set port 22#配置登陆数据库的ip地址set oracleip 10.0.4.41#配置数据库实例名 ...

  4. 30个关于Shell脚本的经典案例(下)

    本文目录 21.从FTP服务器下载文件 22.连续输入5个100以内的数字,统计和.最小和最大 23.将结果分别赋值给变量 24.批量修改文件名 25.统计当前目录中以.html结尾的文件总大 26. ...

  5. 采用shell脚本定时清理Tomcat日志

    1 Shell脚本案例 删除超过30天的日志文件 #!/bin/bash log_path=/mnt/software/apache-tomcat-.M22/logs d=`date +%Y-%m-% ...

  6. shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

    case判断 • 格式 case  变量名 in                       value1)                           command            ...

  7. 30个关于Shell脚本的经典案例(上)

    对于初学者而言,因为没有实战经验,写不出来Shell脚本很正常,如果工作了几年的运维老年还是写不出来,那就是没主动找需求,缺乏练习,缺乏经验.针对以上问题,总结了30个生产环境中经典的Shell脚本, ...

  8. shell脚本编程——生产实战案例

    生产实战案例     在日常的生产环境中,可能会遇到需要批量检查内网目前在线的主机IP地址有哪些,还可能需要检查这些在线的主机哪些端口是开放状态,因此依靠手工来检查是可以实现,但比较费时费力,所以需要 ...

  9. shell脚本的函数介绍和使用案例

    #前言:今天我们来聊聊shell脚本中的函数知识,看一下函数的优势,执行过程和相关的使用案例,我们也来看一下shell和python的函数书写方式有什么不同 #简介 .函数也具有别名类似的功能 .函数 ...

随机推荐

  1. 面向对象(OOP)--OOP基础与this指向详解

      前  言            学过程序语言的都知道,我们的程序语言进化是从“面向机器”.到“面向过程”.再到“面向对象”一步步的发展而来.类似于汇编语言这样的面向机器的语言,随着时代的发展已经逐 ...

  2. Ubuntu 16.04 LTS 下安装MATLAB2015b 以及Matlab system error解决办法

    下载MATLAB2015b破解版 操作系统:Ubuntu 16.o4 LTS 程序文件:Matlab2015b-glnxa64破解版 解压提取文件:在ubuntu系统下可以直接提取压缩文件,得到三个文 ...

  3. win10 uwp DataContext

    本文告诉大家DataContext的多种绑法. 适合于WPF的绑定和UWP的绑定. 我告诉大家很多个方法,所有的方法都有自己的优点和缺点,可以依靠自己喜欢的用法使用.当然,可以在新手面前秀下,一个页面 ...

  4. (@WhiteTaken)设计模式学习——组合模式

    下面来学习一下组合模式. 组合模式概念是什么呢.从别的地方抄来了一些理论. 理论:将对象组合成树形结构以表示"部分-整体"的层次结构.Composite模式使得用户对单个对象和组合 ...

  5. 【转】嵌入式C语言调试开关

    在调试程序时,经常会用到assert和printf之类的函数,我最近做的这个工程里就有几百个assert,在你自认为程序已经没有bug的时候,就要除去这些调试代码,应为系统在正常运行时这些用于调试的信 ...

  6. python分布式环境下的限流器

    项目中用到了限流,受限于一些实现方式上的东西,手撕了一个简单的服务端限流器. 服务端限流和客户端限流的区别,简单来说就是: 1)服务端限流 对接口请求进行限流,限制的是单位时间内请求的数量,目的是通过 ...

  7. 【译】Java中的字符串字面量

    原文地址:https://javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html 作者:Corey McGlone 让我们由一个简 ...

  8. linux学习(二)linux配置网卡以及常见网络问题排查

    实验环境环境:mac,vmware fusion 一.常用的虚拟机网络连接模式. NAT:推荐方式.它可以使你在切换网络环境(比如在工作中和家里)时,不需要修改虚拟主机的配置,而维持正常的上网功能. ...

  9. HDU1005 Number Sequence (奇技淫巧模拟)

    A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mo ...

  10. Again Stone Game

    Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains ...