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. java通过shield链接Elasticsearch

    本文mark了springboot中集成elasticsearch,并且实现连接带有shield权限管理的elasticsearch的方法. tips:首先建议java client版本和elasti ...

  2. scala PartialFunction

    1.orElse和andThen的区别 源码如下,区别很明显,orElse是并列的关系,而andThen是调用者的结果作为k的输入. trait PartialFunction[-A, +B] ext ...

  3. adb获取Android性能数据

    环境:Android测试环境 搭建Android测试环境: 1.下载AndroidSDK: 2.配置环境变量: (1).ANDROID_HOME (2).ANDROID_HOME-TOOLS (3). ...

  4. WPF DataGrid复制单元格问题

    当复制出现 以下错误时:System.Runtime.InteropServices.COMException (0x800401D0),这是在WPF剪贴板程序错误. 解决方法:则在需要在App.xa ...

  5. JPA + SpringData 操作数据库原来可以这么简单 ---- 深入了解 JPA - 2

    原创播客,如需转载请注明出处.原文地址:http://www.cnblogs.com/crawl/p/7704914.html ------------------------------------ ...

  6. asp.net core2.0网站的环境搭建和网站部署

    使用到的软件和硬件 1.       centos7.3服务器一台 2.       xshell.xftp 3.       vs2017 4.       .NET Core   1. 安装 li ...

  7. python日记

    今天学习了Python的一些基本知识,就是简单的输入输出.因为我安装的Python环境是3.6版本的,因此我说的自己体会到的问题都是基于这个版本而得出的问题,说一下今天感觉要注意的要点吧. 1.首先是 ...

  8. 使用原生php读写excel文件

    最近在工作中遇到一个需求,需要将数据库中的数据导出到excel文件中,并下载excel文件.因为以前没做过,所以就百度了一下, 网上说的大多是使用PHPExcel类来操作excel文件,这还要去下载这 ...

  9. 解析 .Net Core 注入 (3) 创建对象

    回顾 通过前两节的学习,我们知道 IServiceCollection 以元数据(ServiceDescriptor)的形式存放着用户注册的服务,它的 IServiceCollection 的拓展方法 ...

  10. Python元祖

    本篇主要介绍另一种有序列表叫元祖:tuple.更多内容请参考:python学习指南 元祖是什么 tuple和list非常类似,但是tuple一旦初始化就不能修改,比如同样是列出同学的名字 >&g ...