第一个脚本:

1、使用函数实现:
   判断一个用户是否存在,用户名通过参数传递而来;
   如果存在,就显示此用户的shell和UID
   如果不存在,就说此用户不存在;
2、提示用户输入用户名,而后将其传递给上面的函数;
3、判断结束后不退出,而是提示用户可继续输入其它用户名,或输入(q)退出;

#!/bin/bash

##Author: Yang Jing
##time: 2014-10-17
##description:  for judge the user exists or not
user_exists() {
        read -p "please input a user name: " User
        [ $User == "q" ] && exit 0
        cat /etc/passwd | grep "^$User:" &> /dev/null
        RETRAL=$?
        if [ $RETRAL -ne 0 ];then
                echo " no such user $User"
        else
                echo "$User uid is `id -u $User`"
                echo "$User shell is `echo $RETRAL | cut -d: -f 7`"
        fi
}
while true;do
        user_exists
done

第二个脚本:

新购买的服务器往往没有格式化磁盘,写一个脚本,能够自动格式化自动挂载到特定目录

#!/bin/bash

##Author: YangJing
##time: 2014-10-17
##description: for new server to mkfs disk and mount /data0
##
echo "Warnging!!!,next operation will clean $DISK data,please take careful !!!"
read -p "please input your disk like '/dev/sda' or '/dev/xvdb': " DISK
if [ ! -e $DISK ];then
        echo " $DISK not exists."
        exit 1
fi
read -p "input the mount index: " DIR
        if [ -d $DIR ] ;then
                read -p "$DIR exists,continue ?? " dir_select
                        if [[ $dir_select == 'y' ]] ;then
                                mkdir /tmp/`date +%Y%m%d`
                                mv $DIR/* /tmp/`date +%Y%m%d/`
                        else
                                exit 2
                        fi
        else
                mkdir $DIR
        fi
read -p "Do you want to mkfs $DISK and mount $DIR ?? " choise
case $choise in
y|Y)
/sbin/mkfs.ext3 $DISK
mount $DISK $DIR
;;
n|N)
exit 2 ;;
*)
echo "please check your choice." ;;
esac

第三个脚本、redis启动脚本(多个redis同时开启服务

#!/bin/bash

#Author: yangjing
#2014-10-19
#redis-this scripts starts and stops the redis daemon
#processname: redis
#
re_path=/usr/local/services/redis
bin_path=${re_path}/bin/redis-server
prog=$(basename ${bin_path})
echo "${bin_path}"
echo "$prog"
start() {
        re_pid=`ps -ef  | grep redis | grep -v grep | awk '{print $2}'`
        redisconf=`ls ${re_path}/etc/`
        for i in $redisconf;do
                nohup ${bin_path} ${re_path}/etc/$i &  &> /dev/null
                retval=$?
                [ $retval -eq 0 ] && echo "Starting $i Success !!"|| echo "Starting $i Faild !!"
        done
}
stop() {
        re_pid=`ps -ef | grep redis | grep -v grep | awk '{print $2}'`
        for i in $re_pid;do
                redisconf=`ps -ef | grep $i | grep -v grep | awk -F"/" '{print $NF}'`
                kill -9 $i
                retval=$?
                [ $retval -eq 0 ] && echo "Stoping $redisconf Success !!" || echo "Stoping $redisconf Faild !!"
        done
}
restart() {
        stop
        start
}
case "$1" in
        start|stop|restart)
                $1
                ;;
        *)
                echo $"Usage: $prog {start|stop|restart|help}"
                exit 1
                ;;
esac
exit $retval

第四个脚本、redis启动脚本(指定端口开启服务

#!/bin/bash

#Author: yangjing
#2014-10-20
#redis-this scripts starts and stops the redis daemon
#processname: redis
#
re_path=/usr/local/services/redis
bin_path=${re_path}/bin/redis-server
prog=$(basename ${bin_path})
#echo "${bin_path}"
#echo "$prog"
start() {
        read -p "which port of redis do you want to start ? " port
        redisconf=${re_path}/etc/redis$port.conf
        echo "redis$port.conf"
        nohup ${bin_path} $redisconf & &>/dev/null
        retval=$?
        [ $retval -eq 0 ] && echo "Starting $redisconf Success !!"|| echo "Starting $redisconf Faild !!"
}
stop() {
        read -p "Do you want to kill which port of redis ? "  port
        redisconf=${re_path}/etc/redis$port.conf
        echo "redis$port.conf"
        re_pid=`ps -ef | grep $redisconf | grep -v grep | awk '{print $2}'`
        if [ -z ${re_pid} ];then
                echo "redis$port.conf server not exists "
        else
                kill -9 ${re_pid}
        fi
        retval=$?
        [ $retval -eq 0 ] && echo "Stoping $redisconf Success !!" || echo "Stoping $redisconf Faild !!"
}
restart() {
        stop
        start
}
case "$1" in
        start|stop|restart)
                $1
                ;;
        *)
                echo $"Usage: $prog {start|stop|restart|help}"
                exit 1
                ;;
esac
exit $retval