linux 常用shell
来源:互联网 发布:绿榴莲网络班价格 编辑:程序博客网 时间:2024/06/16 23:05
#!/bin/bash
#这个脚本用于判断服务是否正常启动
#作者:xuehen
port=$(nmap -sT 10.0.1.99|grep tcp|grep http |awk '{print $2}')
if [ "$port" == "open" ]
then
echo "$(date) apache is running" > /root/log_acc
else
service httpd restart
echo "$(date) service httpd restart" > /root/log_err
read -p "please choice yes/no :" -t 30 cho
case $cho in
"yes")
echo "your choose is yes"
;;
"no")
;;
*)
echo "your choose is wrong"
;;
#该脚本为多分支if案例
#-p:提示用户输入信息
#-s:用于加密,输入的内容不显示
#-t:等待用户输入的时间
read -p "please input a file_name:" file
if [ -z "$file" ]
then
echo "your put is empty"
elif [ -f "$file" ]
then
echo "your put is regeular file"
elif [ -d "$file" ]
then
echo "your put is document"
elif [ ! -e "$file" ]
then
echo "your put is not exist"
date=$(date +%y%m%d)
size=$(du -sh /etc )
if [ -e /tmp/dbbak ]
then
echo "Date:$date" > /tmp/dbbak/db.txt
echo "Size:$size" >> /tmp/dbbak/db.txt
cd /tmp/dbbak
tar -zcf etc_"$date"_tar.gz /etc /tmp/dbbak/db.txt &>/dev/null
rm -rf /tmp/dbbak/db.txt
else
mkdir /tmp/dbbak
echo "Date:$date" > /tmp/dbbak/db.txt
echo "Size:$size" >> /tmp/dbbak/db.txt
tar -zcf etc_"$date"_tar.gz /etc /tmp/dbbak/db.txt &>/dev/null
rm -rf /tmp/dbbak/db.txt
s=0
for ((i=1;i<=100;i++))
do
s=$(($s+$i))
done
for time in moring noon after evening
do
echo "Now is $time"
done
#!/bin/bash
for time in morning noo afternoon evening
do
echo "Now is $time!"
rate=$(df -h |grep /dev/sda5|awk '{print $5}'|cut -d"%" -f1)
if [ $rate -ge 4 ]
then
echo "warining !!! Date:$(date) is full"
mail -s " rate is used " xuehen < /etc/passwd
exit 1
read -p "please input four parameters that is number:"
for x in "$*"
do
echo "$*"
done
for y in "$@"
do
echo $y
#字符串判断
#-z:为空返回真
read -p "please input your name:" $name
if [ -z = $1 ] ;then
echo -e "\e[1;34m the put is empty \e[0m"
fi
#这个脚本用于判断服务是否正常启动
#作者:xuehen
port=$(nmap -sT 10.0.1.99|grep tcp|grep http |awk '{print $2}')
if [ "$port" == "open" ]
then
echo "$(date) apache is running" > /root/log_acc
else
service httpd restart
echo "$(date) service httpd restart" > /root/log_err
fi
##########################################
#!/bin/bashread -p "please choice yes/no :" -t 30 cho
case $cho in
"yes")
echo "your choose is yes"
;;
"no")
;;
*)
echo "your choose is wrong"
;;
esac
#####################################
#!/bin/bash#该脚本为多分支if案例
#-p:提示用户输入信息
#-s:用于加密,输入的内容不显示
#-t:等待用户输入的时间
read -p "please input a file_name:" file
if [ -z "$file" ]
then
echo "your put is empty"
elif [ -f "$file" ]
then
echo "your put is regeular file"
elif [ -d "$file" ]
then
echo "your put is document"
elif [ ! -e "$file" ]
then
echo "your put is not exist"
fi
######################################
#!/bin/bashdate=$(date +%y%m%d)
size=$(du -sh /etc )
if [ -e /tmp/dbbak ]
then
echo "Date:$date" > /tmp/dbbak/db.txt
echo "Size:$size" >> /tmp/dbbak/db.txt
cd /tmp/dbbak
tar -zcf etc_"$date"_tar.gz /etc /tmp/dbbak/db.txt &>/dev/null
rm -rf /tmp/dbbak/db.txt
else
mkdir /tmp/dbbak
echo "Date:$date" > /tmp/dbbak/db.txt
echo "Size:$size" >> /tmp/dbbak/db.txt
tar -zcf etc_"$date"_tar.gz /etc /tmp/dbbak/db.txt &>/dev/null
rm -rf /tmp/dbbak/db.txt
fi
###############################################
#!/bin/bashs=0
for ((i=1;i<=100;i++))
do
s=$(($s+$i))
done
echo "the result is:" $s
###################################
#!/bin/bashfor time in moring noon after evening
do
echo "Now is $time"
done
#!/bin/bash
for time in morning noo afternoon evening
do
echo "Now is $time!"
done
###############################################
#!/bin/bashrate=$(df -h |grep /dev/sda5|awk '{print $5}'|cut -d"%" -f1)
if [ $rate -ge 4 ]
then
echo "warining !!! Date:$(date) is full"
mail -s " rate is used " xuehen < /etc/passwd
exit 1
fi
#################################
#!/bin/bashread -p "please input four parameters that is number:"
for x in "$*"
do
echo "$*"
done
for y in "$@"
do
echo $y
done
####################################
#!/bin/bash#字符串判断
#-z:为空返回真
read -p "please input your name:" $name
if [ -z = $1 ] ;then
echo -e "\e[1;34m the put is empty \e[0m"
fi
0 0
- Linux Shell常用技巧
- Linux常用shell命令
- Linux常用shell命令
- linux SHELL常用技巧
- linux shell常用快捷键
- linux shell常用快捷键
- Linux常用shell快捷键
- Linux Shell 常用快捷键
- Linux Shell常用技巧
- Linux Shell常用技巧
- Linux Shell常用技巧
- Linux Shell常用技巧
- Linux shell 常用技巧
- Linux常用Shell命令
- linux常用shell脚本
- Linux 常用Shell
- Linux Shell常用技巧
- Linux Shell常用技巧
- php访问mysql数据库
- Asp.net 移动开发
- uva 11478 Halum (差分约束+二分+SPFA判负环)
- cocos2dx3.2 工程的目录结构(cpp+lua)
- (2)SSL —— SSL与TLS区别
- linux 常用shell
- Android自动化打包之一:aapt的用法
- mongodb数组写操作
- 关于win7 x64 连接oracle 客户端 VS2010调试 提示“ORA-12154: TNS: 无法解析指定的连接标识符 ”
- SQL 数据类型:MySQL 数据类型
- Netty 权威指南之Google protobuf 编解码
- 看大型的支付系统如支付宝等如何实现风控的!
- 关于按键扫描程序
- [VIM]Linux下打造自己的IDE