shell脚本

#!/bin/bash
#purpose:test for loop to calculate 
#date:2015-01-31
#author:lirongqiang
declare -i s #declare s as an integer number
for ((i=i; i<100; i=i+1 ))
do 
s=s+i
echo "current i=$i"
done
echo "The result is $s"

------------------------------------------------------------------------------
#!/bin/bash
#purpose:test the for loop as string
#date:2015-01-31
#author:lirongqiang
LIST="Tom cat java python linux ruby perl hadoop"

for i in $LIST
do
echo $i
done

------------------------------------------------------------------------------
#!/bin/bash
#todo: use shell script's parameter code
#date:2015-01-28
#edit: by lrq
echo "this script's name =>$0"
echo "parameters $1 $2 $3 $4 $5 "
------------------------------------------------------------------------------
#!/bin/bash
#TODO:check user is root or not
#DATE:2015-01-30
#AUTHOR:LRQ
if [ $UID -ne 0 ]; then
echo "Non root user. Please run as root."
else 
echo "Root uesr"
fi
------------------------------------------------------------------------------

#!/bin/bash
#todo use to calculate some number
#date 2015-01-28
#edit by lrq
declare -i a=2
declare -i b=3
declare -i c=5
declare -i d=13
declare -i e=32
declare -i f=25
declare -i result=$a*$b+$c*$d-$e+$f
echo "expect result is 64"
echo "the final result is $result"




------------------------------------------------------------------------------
#!/bin/bash
#purpose:test file exists if else -f -d -e and so on
#date:2015-01-31
#author:lirongqiang
if [ ! -e logical ];then
touch logical
echo "just make a file logical"
exit 1
elif [ -e logical ] && [ -f logical ];then
rm logical
mkdir logical
echo "remove file ==>logical"
echo "and make directory logical"
exit 1
elif [ -e logical ] && [ -d logical ];then
rm -rf logical
echo "remove directory recursive==>logical "
exit 1
else
echo "Does here have anything"
fi 
------------------------------------------------------------------------------

#!/bin/bash
#purpose:check the port is usable
#date:2015-01-31
#author:lirongqiang
#1.print the program's work in your screen
echo "now,the service of your linux system will be detect!"
echo "then www,tft,ssh and sendmail+pop3 will be detect"
echo " "
#2. www
  www='netstat -an|grep LISTEN|grep :80'
  if [ "$www" != "" ];then
echo "www is running "
  else
echo "www is NOT running "
  fi
#3. ftp
  ftp='netstat -an|grep LISTEN|grep :21'
  if [ "$ftp" != "" ];then
  echo "FTP is running"
  else
echo "FTP is not running"
  fi
#4 ssh
  ssh='netstat -an|grep LISTEN|grep :22'
  if [ "$ssh" != "" ];then
  echo "ssh is running"
  else
echo "ssh is out of service"
  fi
#5. sendmail+pop3
  smtp='netstat -an|grep LISTEN|grep :25'
  pop3='netstat -an|grep LISTEN|grep :110'
  if [ "$smtp" != "" ] && [ "$pop3" != "" ];then
  echo "smtp and pop3 is running,you can receive and send mail "
  elif [ "$smtp" != "" ] && [ "$pop3" = "" ];then
echo " receive mail has some problem "
  elif [ "$smtp" = ""   ] && [ "$pop3" != "" ];then
echo " send mail has some problem "
  else
echo "total mail is out of service "
  fi
------------------------------------------------------------------------------
#!/bin/bash
#todo show what you have input in the console
#date 2015-01-28
#edit by lrq
echo "please input your name:"
read name
echo "THIS IS YOU INPUT DATA-->$name"

------------------------------------------------------------------------------

#!/bin/bash
#purpose:test case esac 
#date:2015-01-31
#author:lirongqiang
#1 print this program
  echo "This program will print your selection."
  echo "please press your select one,two,three"
  read number
  case $number in
  one)
echo "your choice is one"
;;
  two)
echo "your choice is two"
;;
  three)
echo "your choice is three"
;;
  *)
echo "Usag {one|two|three}"
exit 1
  esac

         
------------------------------------------------------------------------------

#!/bin/bash
#purpose:test find directory 
#date:2015-01-31
#author:lirongqiang

log_path=`find /root/* -name "*.log"`#to find all named as log

for i in $log_path   #log_path is an string array 
do
`rm -rf $i`# remove the single log file
result=$?   # get the result last execution
if [ $result = 0 ];then
echo "$i has removed successful "#$?=0 means rm successfully
else echo "error"
fi 
done
------------------------------------------------------------------------------
#!/bin/bash
#purpose:test the for loop as string
#date:2015-01-31
#author:lirongqiang
LIST="Tom cat java python linux ruby perl hadoop"

for i in $LIST
do
echo $i
done
------------------------------------------------------------------------------




------------------------------------------------------------------------------

<script type="text/javascript" id="wumiiRelatedItems"> </script>
 
阅读(16) | 评论(0)
推荐 转载
历史上的今天
最近读者
热度
在LOFTER的更多文章
评论
#!/bin/bash
#purpose:test for loop to calculate 
#date:2015-01-31
#author:lirongqiang
declare -i s #declare s as an integer number
for ((i=i; i<100; i=i+1 ))
do 
\ts=s+i
\techo "current i=$i"
done
echo "The result is $s"
', blogTag:'', blogUrl:'blog/static/21727620920151103945369', isPublished:1, istop:false, type:0, modifyTime:1422767402451, publishTime:1422767402420, permalink:'blog/static/21727620920151103945369', commentCount:0, mainCommentCount:0, recommendCount:0, bsrk:-100, publisherId:0, recomBlogHome:false, currentRecomBlog:false, attachmentsFileIds:[], vote:{}, groupInfo:{}, friendstatus:'none', followstatus:'unFollow', pubSucc:'', visitorProvince:'', visitorCity:'', visitorNewUser:false, postAddInfo:{}, mset:'000', mcon:'', srk:-100, remindgoodnightblog:false, isBlackVisitor:false, isShowYodaoAd:false, hostIntro:'JAVA软件工程师,有扎实的Java基础,熟悉JavaEE技术,对框架的底层原理熟悉,学习能力强。', hmcon:'0', selfRecomBlogCount:'0', lofter_single:'' }
{if x.visitorName==visitor.userName} ${x.visitorNickname|escape} {else} ${x.visitorNickname|escape} {/if}
{if x.moveFrom=='wap'}   {elseif x.moveFrom=='iphone'}   {elseif x.moveFrom=='android'}   {elseif x.moveFrom=='mobile'}   {/if} ${fn(x.visitorNickname,8)|escape}
{/if} {/list}
${a.selfIntro|escape}{if great260}${suplement}{/if}
 
{/if}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值