copy command and lib 2 ``` #!/bin/bash #copy command and lib #lm ROOTDIR=/mnt/sysroot cplib() { for lib in `ldd $1 |grep -o "/.*lib\(64\)\{0,1\}.*[[:space:]]"`; do libdir=${lib%/*} [ ! -d $ROOTDIR${libdir} ] && mkdir -p $ROOTDIR${libdir} [ ! -f $ROOTDIR${lib} ] && cp $lib $ROOTDIR${libdir} && echo "copy $lib is finish." done } cpcommand() { dir=${1%/*} [ ! -d $ROOTDIR${dir} ] && mkdir -p $ROOTDIR${dir} [ ! -f $ROOTDIR${1} ] && cp $1 $ROOTDIR${dir} && echo "$1 copy finish." cplib $1 } while :; do read -p "please input command:" command [ $command == "q" ] && echo "exit." && exit which $command >&/dev/null [ $? == "1" ] && echo "$command not exisit,please try again!" && continue cmddir=`which $command |grep -v "alias" |grep -o "[^[:space:]]*"` cpcommand $cmddir echo "$command copy finish." done ``` shell脚本 2017-03-10 评论 1650 次浏览
copy command and lib ``` #!/bin/bash #copy command and lib #Auther:stone PATHDIR=/tmp/sysroot cplib() { libdir=${1%/*} [ ! -d $PATHDIR$libdir ] && mkdir -p $PATHDIR$libdir [ ! -e $PATHDIR${1} ] && cp $1 $PATHDIR${libdir} && echo "copy lib $1 finish." } cpcommand() { commanddir=${1%/*} [ ! -d $PATHDIR$commanddir ] && mkdir -p $PATHDIR$commanddir [ ! -e $PATHDIR${1} ] && cp $1 $PATHDIR$commanddir && echo "copy $1 finish." for lib in `ldd $1 |grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{1,\}"`; do cplib $lib done } command=a while [ $command != "quit" ]; do read -p "please input command:" command ! which $command && echo "$command is not exisit,please try again." && continue cmddir=`which $command |grep -v "alias" |grep -o "[^[:space:]]\{1,\}"` cpcommand $cmddir echo "copy $command finish." && exit done ``` shell脚本 2017-03-09 评论 1593 次浏览
set yum address ``` #!/bin/bash #set yum address #Auther:stone echo -e "\033[31m######################################\033[0m" echo -e "\033[31m###########\033[32mset yum address\033[31m############\033[0m" echo -e "\033[31m#######\033[32mThanks you using scripts\033[31m#######\033[0m" echo -e "\033[31m######################################\033[0m" DIR=/etc/yum.repos.d/ read -p "please input repoFILE:" REPOFILE if [ -e ${DIR}${REPOFILE} ]; then echo-e "\033[31m$REPOFILE is exists.\033[0m" exit 11 fi FILE=${DIR}${REPOFILE}.repo until [ $REPOFILE == "quit" ]; do echo "[$REPOFILE]" >$FILE read -p "please input Repository name:" REPONAME echo "name=$REPONAME" >>$FILE read -p "please input baseurl:" REPOURL echo "baseurl=$REPOURL" >>$FILE echo -e "enabled=1\ngpgchk=0" >>$FILE read -p "please input 'quit' exit.:" REPOFILE done ``` shell脚本 2017-03-08 评论 1686 次浏览
分区脚本 ``` #!/bin/bash #分区脚本 #Auther:stone #列出系统上挂载的所有硬盘 echo -e "\033[31m`fdisk -l |grep '^Disk /dev/[sh]d[a-z]'`\033[0m" #统计已挂载硬盘数量 c=`fdisk -l 2>/dev/null |grep '^Disk /dev/[sh]d[a-z]' |wc -l` echo `fdisk -l |grep '^Disk /dev/[sh]d[a-z]' |cut -d ' ' -f 2 |cut -d : -f 1` >/tmp/list.txt #模块化减少代码 function change() { read -p "input a hard disk number:" hdnum number=`echo $hdnum |sed -r 's/[0-9]+//g'` if [[ $hdnum -gt $c ]] || [[ $hdnum -lt 1 ]] || [[ $number ]]; then echo -e "\033[31mplease try again(0-3).\033[0m"; continue fi hdw=`cat /tmp/list.txt |cut -d ' ' -f $hdnum` echo $hdw return } while :; do cat << EOF ############format sctipt############ ## a choice hard disk ## ## d delete hard disk parttion ## ## quit quit the script ## ##################################### EOF read -p "input your choice:" optiona case $optiona in a|A) for i in `seq 1 $c`; do echo -e "\033[32mThis is $i Hard Disk: `cat /tmp/list.txt |cut -d ' ' -f $i`\033[0m" done while :; do change read -p "you date will lose,sure to continue?(y|Y)" choose1 [ $choose1 != "y" ] || [ $choose1 != "Y" ] && echo -e "\033[32myou not change $hdw\033[0m"; break echo ' n p 1 +1G n p 2 +1G n p 3 +2G t 3 82 w' |fdisk $hdw &>/dev/null fdisk -l $hdw exit 0 done ;; d) for i in `seq 1 $c`; do echo -e "\033[32mThis is $i Hard Disk: `cat /tmp/list.txt |cut -d ' ' -f $i`\033[0m" done while :; do change echo -e "\033[310mare you sure clean the $hdw(y|n):" read choose [ $choose == "y" ] || [ $choose == "Y" ] && dd if=/dev/zero of=$hdw bs=512 count=1 echo -e "\033[32myou not clean the $hdw\033[0m" break done ;; q|quit) exit 0 ;; *) echo -e "\033[31mKnow option,please try again.\033[0m" ;; esac done ``` shell脚本 2017-03-07 评论 1675 次浏览
尝试ping命令判断主机的存活状态 ``` #!/bin/bash #ping.sh #Auther:stone #取起始IP read -p "please input start IPadr:" startip #判断输入的是否为IP地址 while :; do echo $startip |grep -E '\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>' && break read -p "please input IPadr(192.168.1.1):" startip done #结束IP read -p "please input end IPadr:" endip #判断结束IP的格式是否正确 while :; do echo $endip |grep -E '\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>' && break read -p "please input end IPadr(192.168.1.255)" endip done #分别将起始IP地址和结束IP地址的四段提取出来用于判断 head1=`echo $startip |cut -d . -f 1` head2=`echo $startip |cut -d . -f 2` head3=`echo $startip |cut -d . -f 3` head4=`echo $startip |cut -d . -f 4` tail1=`echo $endip |cut -d . -f 1` tail2=`echo $endip |cut -d . -f 2` tail3=`echo $endip |cut -d . -f 3` tail4=`echo $endip |cut -d . -f 4` #判断结束IP段是否大于起始IP段,有四种可能: if [ $tail1 -lt $head1 ]; then echo -e "\033[31mend IPadr smaller than start IPadr.\033[0m" exit 10 fi if [ $tail1 -lt $head1 ] && [ $tail2 -lt $head2 ]; then echo -e "\033[31mend IPadr smaller than start IPadr.\033[0m" exit 10 fi if [ $tail1 -lt $head1 ] && [ $tail2 -lt $head2 ] && [ $tail3 -lt $head3 ]; then echo -e "\033[31mend IPadr smaller than start IPadr.\033[0m" exit 10 fi if [ $tail1 -lt $head1 ] && [ $tail2 -lt $head2 ] && [ $tail3 -lt $head3 ] && [ $tail4 -lt $head4 ]; then echo -e "\033[31mend IPadr smaller than start IPadr.\033[0m" exit 10 fi #以下为ping命令循环 while :; do if [ $head1 -eq $tail1 ]; then if [ $head2 -eq $tail2 ]; then if [ $head3 -eq $tail3 ]; then for ((d=$head4;d<=$tail4;d++)); do ping -c 1 -W 1 $head1.$head2.$head3.$d &>/dev/null [ $? == 0 ] && echo -e "\033[32m$head1.$head2.$head3.$d is up.\033[0m" [ $? == 1 ] && echo -e "\033[31m$head1.$head2.$head3.$d id down.\033[0m" done exit 0 else for ((d=$head4;d<=255;d++)); do ping -c 1 -W 1 $head1.$head2.$head3.$d &>/dev/null [ $? == 0 ] && echo -e "\033[32m$head1.$head2.$head3.$d is up.\033[0m" [ $? == 1 ] && echo -e "\033[31m$head1.$head2.$head3.$d id down.\033[0m" done declare c=$head3 let c++ while (($tail3-$c>0)); do for ((d=1;d<=255;d++)); do ping -c 1 -W 1 $head1.$head2.$c.$d &>/dev/null [ $? == 0 ] && echo -e "\033[32m$head1.$head2.$c.$d is up.\033[0m" [ $? == 1 ] && echo -e "\033[31m$head1.$head2.$c.$d id down.\033[0m" done done if [ `expr $tail3 - $c` -eq 0 ]; then for ((d=0;d<=$tail4;d++)); do ping -c 1 -W 1 $head1.$head2.$c.$d &>/dev/null [ $? == 0 ] && echo -e "\033[32m$head1.$head2.$c.$d is up.\033[0m" [ $? == 1 ] && echo -e "\033[31m$head1.$head2.$c.$d id down.\033[0m" done exit 0 fi fi fi fi done ``` shell脚本 2017-03-06 评论 1720 次浏览
choise.sh ``` #!/bin/bash #choise.sh #Auther:stone cat << EOF d|D) show disk usages m|M) show memory usages s|S) show swap usages *) quit EOF read -p "please input your choice:" CHOICE while [ $CHOICE != 'quit' ]; do case $CHOICE in d|D) echo "disk usages:" df -h ;; m|M) echo "memory usages" free -m |grep 'Mem' ;; s|S) echo "swap usages" free -m |grep 'Swap' ;; *) echo "UNknow.." ;; esac read -p "please input again your choice:" CHOICE done ``` shell脚本 2017-03-05 评论 2053 次浏览