生成随机时间,用于测试正则语法 ``` #!/bin/bash #Version:0.0.1 #Author:stone #Discription:get random date. #获取指定的数字用于循环 while :; do read -p "please input number:" number if [ "$(echo $number |sed "s/[0-9]//g")" != "" ]; then echo -e "\033[31minput not number!please try again!\033[0m" continue #不是数字就继续下次输入循环 else break #为数字时退出循环 fi done i=1 while [ $i -le $number ]; do #随机的年 dateY=$((${RANDOM}%19)) #随机的月 dateM=$((${RANDOM}%13)) #随机的日,大月 dateD1=$((${RANDOM}%32)) #随机的日,小月 dateD2=$((${RANDOM}%31)) #随机的日,闰二月 dateD3=$((${RANDOM}%30)) #随机的日,平二月 dateD4=$((${RANDOM}%29)) #随机的小时 dateh=$((${RANDOM}%24)) #随机的分钟 datem=$((${RANDOM}%60)) #随机的秒 dates=$((${RANDOM}%60)) #判断月份决定日期,大月 if [ $dateM -eq 1 -o $dateM -eq 3 -o $dateM -eq 5 -o $dateM -eq 7 -o $dateM -eq 8 -o $dateM -eq 10 -o $dateM -eq 12 ]; then if [ $dateY -lt 10 ]; then dateY="0$dateY" fi if [ $dateM -eq 0 ]; then dateM=1 #月份如果结果为0,赋值为1 fi if [ $dateM -lt 10 ]; then dateM="0${dateM}" #月份如果小于10,在数值前加0 fi if [ $dateD1 -eq 0 ]; then dateD1=1 #日子如果等于0,赋值为1 fi if [ $dateD1 -lt 10 ]; then dateD1="0$dateD1" fi #时分秒的随机 if [ $dateh -eq 0 ]; then dateh=1 fi if [ $dateh -lt 10 ]; then dateh="0$dateh" fi if [ $datem -lt 10 ]; then datem="0$datem" fi if [ $dates -lt 10 ]; then dates="0$dates" fi date -s "${dateh}:${datem}:${dates}" date -s "20${dateY}${dateM}${dateD1}" date +%F-%T >>./date.txt date +%D-%T >>./date.txt date >>./date.txt fi #判断月份决定日期,小月 if [ $dateM -eq 4 -o $dateM -eq 6 -o $dateM -eq 9 -o $dateM -eq 11 ]; then if [ $dateY -lt 10 ]; then dateY="0$dateY" fi if [ $dateM -eq 0 ]; then dateM=1 #月份如果结果为0,赋值为1 fi if [ $dateM -lt 10 ]; then dateM="0${dateM}" #月份如果小于10,在数值前加0 fi if [ $dateD2 -eq 0 ]; then dateD1=2 #日子如果等于0,赋值为1 fi if [ $dateD2 -lt 10 ]; then dateD2="0$dateD2" fi #时分秒的随机 if [ $dateh -eq 0 ]; then dateh=1 fi if [ $dateh -lt 10 ]; then dateh="0$dateh" fi if [ $datem -lt 10 ]; then datem="0$datem" fi if [ $dates -lt 10 ]; then dates="0$dates" fi date -s "${dateh}:${datem}:${dates}" date -s "20${dateY}${dateM}${dateD2}" date +%F-%T >>./date.txt date +%D-%T >>./date.txt date >>./date.txt fi #判断二月份决定日期 if [ $dateM -eq 2 ]; then if [ $dateY -lt 10 ]; then dateY="0$dateY" fi year="20$dateY" if [ $(($year%4)) -ne 0 ]; then if [ $dateM -eq 0 ]; then dateM=1 #月份如果结果为0,赋值为1 fi if [ $dateM -lt 10 ]; then dateM="0${dateM}" #月份如果小于10,在数值前加0 fi if [ $dateD3 -eq 0 ]; then dateD3=1 #日子如果等于0,赋值为1 fi if [ $dateD3 -lt 10 ]; then dateD3="0$dateD3" fi #时分秒的随机 if [ $dateh -eq 0 ]; then dateh=1 fi if [ $dateh -lt 10 ]; then dateh="0$dateh" fi if [ $datem -lt 10 ]; then datem="0$datem" fi if [ $dates -lt 10 ]; then dates="0$dates" fi date -s "${dateh}:${datem}:${dates}" date -s "20${dateY}${dateM}${dateD3}" date +%F-%T >>./date.txt date +%D-%T >>./date.txt date >>./date.txt else if [ $dateM -eq 0 ]; then dateM=1 #月份如果结果为0,赋值为1 fi if [ $dateM -lt 10 ]; then dateM="0${dateM}" #月份如果小于10,在数值前加0 fi if [ $dateD4 -eq 0 ]; then dateD4=1 #日子如果等于0,赋值为1 fi if [ $dateD4 -lt 10 ]; then dateD4="0$dateD4" fi #时分秒的随机 if [ $dateh -eq 0 ]; then dateh=1 fi if [ $dateh -lt 10 ]; then dateh="0$dateh" fi if [ $datem -lt 10 ]; then datem="0$datem" fi if [ $dates -lt 10 ]; then dates="0$dates" fi date -s "${dateh}:${datem}:${dates}" date -s "20${dateY}${dateM}${dateD4}" date +%F-%T >>./date.txt date +%D-%T >>./date.txt date >>./date.txt fi fi let i++ done ``` shell脚本 2017-03-11 评论 1724 次浏览
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 评论 1643 次浏览
copy command and lib 2 ``` #!/bin/bash #copy command and lib #Auther:stone 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 评论 1709 次浏览
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 评论 1588 次浏览
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 评论 1682 次浏览
分区脚本 ``` #!/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 评论 1670 次浏览