shell脚本 案例
2, 9*9乘法表
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
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跳板机(触发信号后屏蔽信号)
#!/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
;;
done
#!/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脚本 案例的更多相关文章
- shell脚本案例分享 - 业务系统日志自定义保留或删除需求
需求说明: 线上某些业务系统的日志不定期产生, 有的每天产生, 有的好几天才产生, 因为系统只有在用的时候才产生日志,日志文件均存放在以当天日期命名的目录下. 当日志目录越来越多时就需要处理, 由此 ...
- shell脚本案例
1.MySQL数据库备份脚本,下面的脚本是Mysql全量备份+异地备份 一般Mysql数据库备份会采用在MYSQL从库上执行全量备份+增量备份方式.在从库备份避免Mysql主库备份的时候锁表造成业务影 ...
- 非交互式shell脚本案例-实现自主从oracle数据库获取相关数据,并在制定目录生成相应规则的文件脚本
get_task_id 脚本内容 #!/usr/bin/expect#配置登陆数据库的端口set port 22#配置登陆数据库的ip地址set oracleip 10.0.4.41#配置数据库实例名 ...
- 30个关于Shell脚本的经典案例(下)
本文目录 21.从FTP服务器下载文件 22.连续输入5个100以内的数字,统计和.最小和最大 23.将结果分别赋值给变量 24.批量修改文件名 25.统计当前目录中以.html结尾的文件总大 26. ...
- 采用shell脚本定时清理Tomcat日志
1 Shell脚本案例 删除超过30天的日志文件 #!/bin/bash log_path=/mnt/software/apache-tomcat-.M22/logs d=`date +%Y-%m-% ...
- shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断
case判断 • 格式 case 变量名 in value1) command ...
- 30个关于Shell脚本的经典案例(上)
对于初学者而言,因为没有实战经验,写不出来Shell脚本很正常,如果工作了几年的运维老年还是写不出来,那就是没主动找需求,缺乏练习,缺乏经验.针对以上问题,总结了30个生产环境中经典的Shell脚本, ...
- shell脚本编程——生产实战案例
生产实战案例 在日常的生产环境中,可能会遇到需要批量检查内网目前在线的主机IP地址有哪些,还可能需要检查这些在线的主机哪些端口是开放状态,因此依靠手工来检查是可以实现,但比较费时费力,所以需要 ...
- shell脚本的函数介绍和使用案例
#前言:今天我们来聊聊shell脚本中的函数知识,看一下函数的优势,执行过程和相关的使用案例,我们也来看一下shell和python的函数书写方式有什么不同 #简介 .函数也具有别名类似的功能 .函数 ...
随机推荐
- 对Jquery中的ajax再封装,简化操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- WPF 中模拟键盘和鼠标操作
转载:http://www.cnblogs.com/sixty/archive/2009/08/09/1542210.html 更多经典文章:http://www.qqpjzb.cn/65015.ht ...
- 【转载】CSS3 Transitions, Transforms和Animation使用简介与应用展示
文章转载自 张鑫旭-鑫空间-鑫生活 http://www.zhangxinxu.com/wordpress/ 原文链接:http://www.zhangxinxu.com/wordpress/?p=1 ...
- 基于nginx搭建简易的基于wcf集群的复杂均衡
很多情况下基于wcf的复杂均衡都首选zookeeper,这样可以拥有更好的控制粒度,但zk对C# 不大友好,实现起来相对来说比较麻烦,实际情况下,如果 你的负载机制粒度很粗糙的话,优先使用nginx就 ...
- VIM文本替换命令
在VIM中进行文本替换: 1. 替换当前行中的内容: :s/from/to/ (s即substitude) :s/from/to/ : 将当前行中的 ...
- 常用的HTTP状态码
成功的状态码: 200 – 服务器成功返回网页 304 – 未修改 失败的状态码: 404 – 请求的网页不存在 503 – 服务器暂时不可用 500 – 服务器内部错误 下面的不是很常用,记住上面那 ...
- Django(二)
QuerySet与惰性机制: 所谓惰性机制:Publisher.objects.all()或者所谓惰性机制:Publisher.objects.all()或者.filter()等都只是返回了一个Que ...
- 使用bitset实现毫秒级查询(二)
在上一篇中我们了解了bitset索引的基本用法,本篇开始学习bitset索引更新及一些复杂查询. 1.bitset索引更新 因为我们的数据是在系统启动时全部加载进内存,所以当数据库数据发生变化时要 ...
- 【NOIP模拟】的士碰撞(二分答案)
Description
- Servlet 笔记-Cookie 处理
Cookie 是存储在客户端计算机上的文本文件,并保留了各种跟踪信息. 识别返回用户包括三个步骤: 服务器脚本向浏览器发送一组 Cookie.例如:姓名.年龄或识别号码等. 浏览器将这些信息存储在本地 ...