几个SHELL实例

新建user01-user20用户 随机六位数 密码取值a-zA-Z0-9

adduser(){
pw_txt=`mktemp pw.XXXXX`
for i in seq -s '' -w 1 20
do
   useradd user$i
done 
cat /dev/urandom | string -6 |egrep "^[a-zA-Z0-9]{6}$"|head -20 >$pw_txt
for i in seq -s '' -w 1 20;do
pw=`head -n $i $pw_txt|tail -1 `
echo $pw|passwd --stdin user $i
echo -e "user$i\t\t$pw">> user_add_result.txt
done
clear
echo"用户创建成功,密码文件是:user_add_result.txt"
cat user_add_result.txt
rm -rf $pw_txt
}
adduser

cpu&&memory前十的进程

memory(){
temp_file=mktemp memory.XXXX
top -b -n 1>$temp_file
tail -n +8 $temp_file|awk`{array[&NF]+=$6}END{for(i in array) print array[i],i}`|sort -k 1 -n -r |head -10
rm -f $temp_file
}
cpu(){
temp_file=mktemp cpu.XXXX
top -b -n 1>$temp_file
tail -n +8 $temp_file|awk`{array[&NF]+=$9}END{for(i in array) print array[i],i}`|sort -k 1 -n -r |head -10
rm -f $temp_file
}

nginx一键

nginx_pkg="nginx-1.16.0.tar.gz"
nginx_source_doc=`echo$nginx_pkg|cut -d "." -f1-3`
nginx_install_doc="/usr/local/nginx"
nginx_user="www"
nginx_group="www"
check(){
["$USER ! ='root']"&&echo"need to be root so that"&&exit 1
[! -x /usr/bin/wget]&&echo"not found wget"&&exit 1
}
install_pre(){
if !(yum -y install gcc-* ocre-devel zlib-devel elinks 1>/dev/null);then
echo"ERROR:yum install error" 
 exit 1
fi
if wget http://nginx.org/downlaod/$nginx_pkg &>/dev/null;then
tar xf $nginx_pkg
   if[! -d $nginx_source_doc];then
   echo"ERROR not fond $nginx_source_doc"
    exit 1
    fi
else
   echo"ERROR :wget file $nginx_pkg failed"
   exit 1
fi
}
install(){
useradd -r -s /sbin/nologin www
cd  $nginx_source_doc
if ./configure --prefix=$nginx_install_doc --user=$nginx_user --group=$nginx_group;then
echo"nginx make..."
  if make 1>/dev/null;then
  echo"nginx insatll..."
     if make install 1>/dev/null;then
     echo"nginx install success"
     else
     echo"ERROR make install failed" ;exit 1
     fi
  else
  echo"ERROR make failed";exit 1
  fi
echo"ERROR  configure failed";exit 1
fi
}
nginx_test(){
if $nginx_install_doc/sbin/nginx;then
echo"nginx start success"
elinks http://localhost -dump
else
echo"nginx stop fail"
fi
}
echo"this is nginx install script"
read -p "press Y install,press C cancel" ch
if[$ch == 'Y'];then
check;install_pre;install;nginx_test
elif[$ch =='C'];then
 exit 1
fi

内存使用率

memory_usr(){
memory_used=head -2 /proc/meminfo |awk 'NR==1{t=$2}NR==2{f=$2;print(t-f)*100/t"%"}'
memory_cache=head -5 /proc/meminfo|awk 'NR==1{t=$2}NR==5{c=$2;print c*100/t"%"}'`
memory_buffer=head -4 /proc/meminfo|awk 'NR==1{t=$2}NR==4{b=$2;print b*100/t"%"}'`
}
echo -e"memory_used:$memory_used\tmemory_cache:$memory_cache\tmemory_buffer:$memory_buffer"
}
memory_use

lamp(部分)

PACKAGES="../soft"
NOW=pwd
APR=apr-1.5.2.tar.bz2
APR_UTIL=apr-util-1.5.4.tar.bz2
APR_ICONV=apr-iconv-1.2.1.tar.gz
APACHE=httpd-2.4.12.tar.bz2
D_PATH="/usr/local"
S_PATH="/usr/src"
MYSQL=mysql-5.5.29.tar.gz
LIBICONV=libiconv-1.14.tar.gz
LIBMCPYPT=libmcrypt-2.5.8.tar.gz
MCRYPT=mcrypt-2.6.8.tar.gz
MHASH=mhash-0.9.9.9.tar.gz
PHP=php-5.6.9.tar.bz2
check(){
[$UID -ne 0]&&echo"need to root is that"&&exit 1
yum search elinks &>/dev/null
if[&? -eq 0];then
yum -y install gcc gcc- c++ openssl-devel pcre=devel ncurses-devel libtool libxm12-devel bzip2-devel net-snmp- devel crul-devel libpng-devel freetype-devel libjpeg-devel
zlib-devel camke
 [$? -ne 0]&&echo"YUM:ERROR"&&exit 1
else
  echo"YUM ERROR";exit 1
fi
}
apr(){
if[-f $PACKAGES/$APR];then
tar xf $PACKAGES/$APR -C  $S_PATH
CUR_PACKAGE=echo $APR|awk -F ".tar"'{print $1}'
 if[-d $S_PATH/$CUR_PACKAGE];then
cd $S_PATH/$CUR_PACKAGE
./configure --prefix=$D_PATH/apr 1>/dev/null
   if[$? -eq 0];then
   make 1>/dev/null
      if[$? -eq 0];then
      make install 1>/dev/null
        if[$? -eq 0];then
        echo"APR Make install ERROR";exit 1
        else
        cd -;rm -rf $S_PATH/$CUR_PACKAGE
        fi
    else
    echo"APR make ERROR";exit 1
    fi
  echo"APR:configure ERROR";exit 1
  fi
 else
 echo"TAR COMMAND ERROR";exit 1
 fi
else
echo"APR:NOT FOUND $APR";exit 1
fi
}
apr_util(){
if[- f $PACKAGES/$UTIL];then
tar xf $PACKAGES/$UTIL -C  $S_PATH
CUR_PACKAGE=echo $UTIL|awk -F ".tar"'{print $1}'
 if[-d $S_PATH/$CUR_PACKAGE];then
cd $S_PATH/$CUR_PACKAGE
./configure --prefix=$D_PATH/apr-util --with-apr=$D_PATH/apr 1>/dev/null
   if[$? -eq 0];then
   make 1>/dev/null
      if[$? -eq 0];then
      make install 1>/dev/null
        if[$? -eq 0];then
        echo"APR-util Make install ERROR";exit 1
        else
        cd -;rm -rf $S_PATH/$CUR_PACKAGE
        fi
    else
    echo"APR-util make ERROR";exit 1
    fi
  echo"APR-util:configure ERROR";exit 1
  fi
 else
 echo"TAR COMMAND ERROR";exit 1
 fi
else
echo"APR:NOT FOUND $APR_UTIL";exit 1
fi
}
apr_iconv(){
if[- f $PACKAGES/$ICONV];then
tar xf $PACKAGES/$ICONV -C  $S_PATH
CUR_PACKAGE=echo $ICONV|awk -F ".tar"'{print $1}'
 if[-d $S_PATH/$CUR_PACKAGE];then
cd $S_PATH/$CUR_PACKAGE
./configure --prefix=$D_PATH/apr-iconv --with-apr=$D_PATH/apr 1>/dev/null
   if[$? -eq 0];then
   make 1>/dev/null
      if[$? -eq 0];then
      make install 1>/dev/null
        if[$? -eq 0];then
        echo"APR-util Make install ERROR";exit 1
        else
        cd -;rm -rf $S_PATH/$CUR_PACKAGE
        fi
    else
    echo"APR-iconv make ERROR";exit 1
    fi
  echo"APR-iconv:configure ERROR";exit 1
  fi
 else
 echo"TAR COMMAND ERROR";exit 1
 fi
else
echo"APR-iconv:NOT FOUND $APR_UTIL";exit 1
fi
}
apache(){
apr;apr_util;apr_iconv
[$? -ne 0]&&echo"ERROR:please check apr install"&&exit 1
if[! f $PACKAGES/$APACHE];then
tar xf $PACKAGES/$APACHE -C $S_PATH
CUR_PACKAGE=`echo $APACHE|awk -F ".tar"'print $1'`
if[-d $S_PATH/$CUR_PACKAGE];then
cd $S_PATH/$CUR_PACKAGE
./configure --prefix=$D_PARH/apache --with-apr=$D_PATH/apr --with-apr-util=$D_PATH/apr-util --enable-module=so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cach  --enable-disk-cache --enable-static-support --enable-static-ab --disable-userdir --with-mpm=prefork --enable-nonportable-autmics --disable-ipv6 --with-sendfile 1>/dev/null
  if[$? -eq 0];then
  make 1>/dev/null
   if[$? -eq 0];then
   make install  1>/dev/null
     if[$? -eq 0];then
     echo"APACHE:make install ERROR";exit 1
     else
     cd-;rm -rf $S_PATH/$CUR_PACKAGE
     fi
   else
   echo"APACHE:make ERROR";exit 1
   fi
  else
  echo"ERROR:configure ERROR";exit 1
  fi
 echo"ERROR:TAR COMMAND ERROR";exit 1
 fi
else
echo"APACHE:NOT FOUND $APACHE";exit 1
fi
}
mysql_install_psost_set(){
useradd -s /sbin/nologin -r mysql
mkdir -pv /usr/local/mysql/data
cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
cp support-files/mysql.server  /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chown mysql.mysql /usr/local/mysql -R
ln -s /usr/local/mysql/bin/* /usr/bin
ln -s /usr/lcoal/mysql/lib/* /usr/lib
ln -s /usr/local/mysql/libexec/* /usr/local/libexec
ln -s /usr/local/mysql/share/man/man1/*  /usr/share/man/man1
ln -s /usr/local/mysql/share/man/man8/*  /usr/share/man/man8
/usr/local/mysql --datadir=/usr/local/mysql/data 1>/dev/null
}
mysql(){
if[-f $PACKAGES/$MYSQL];then
tar xf $PACKAGES/$MYSQL -C  $S_PATH
CUR_PACKAGE=echo $MYSQL|awk -F ".tar"'{print $1}'
 if[-d $S_PATH/$CUR_PACKAGE];then
cd $S_PATH/$CUR_PACKAGE
cmake .-DCMAKE_INSTALL_PREFIX=/ust/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DWITH_INNODBBASE_STORAGE_ENGINE=1 -DENABLE_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf9_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DWITH_EMBEDED_SERVER=0 1>/dev/null
   if[$? -eq 0];then
   make 1>/dev/null
      if[$? -eq 0];then
      make install 1>/dev/null
        if[$? -eq 0];then
        echo"MYSQL Make install ERROR";exit 1
        else
        cd -;rm -rf $S_PATH/$CUR_PACKAGE
        fi
    else
    echo"MYSQL make ERROR";exit 1
    fi
  echo"MYSQL:configure ERROR";exit 1
  fi
 else
 echo"TAR COMMAND ERROR";exit 1
 fi
else
echo"MYSQL:NOT FOUND $MYSQL";exit 1
fi
}

猜数字

num=`echo $((RANDOM%100+1))`
count=1
while[$num -eq $num1 ]
do
   echo -n "请输入一个数字"
   read num1
   if[$num -eq $num1];then
     echo"对了 随机数是$num 共计$count次"
   elif[$num -gt $num1];then
     echo"小了"
     let count++
    else
    echo"大了"
    let count++
    fi
done

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇