shell脚本

来源:互联网 发布:众筹行业数据报告 编辑:程序博客网 时间:2024/06/03 13:51
#!/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 ] && [ -flogical ];then
rm logical
mkdir logical
echo "remove file ==>logical"
echo "and make directory logical"
exit 1
elif [ -e logical ] && [ -dlogical ];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 bedetect!"
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 canreceive 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 yourselection."
 echo "please press your selectone,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 aslog

for i in $log_path  #log_path is an stringarray 
do
`rm -rf $i`# remove the single log file
result=$?  # get the result lastexecution
if [ $result = 0 ];then
echo "$i has removed successful "#$?=0 means rmsuccessfully
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
------------------------------------------------------------------------------




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

 
阅读(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:'' }
{ifx.visitorName==visitor.userName} ${x.visitorNickname|escape} {else}${x.visitorNickname|escape} {/if}
{if x.moveFrom=='wap'}   {elseifx.moveFrom=='iphone'}   {elseifx.moveFrom=='android'}   {elseifx.moveFrom=='mobile'}   {/if}${fn(x.visitorNickname,8)|escape}
{/if} {/list}
${a.selfIntro|escape}{ifgreat260}${suplement}{/if}
 
{/if}
0 0