Shell脚本练习

Shell实现输入数组,排序

read -a arr
echo "input arr ("${arr[@]}")"

for ((i=0;i<${#arr[@]};i++)) do
        for ((j=i+1;j<${#arr[@]};j++)) do
                if (( ${arr[j]}<${arr[i]} ))
                then
                        let temp=${arr[j]}
                        arr[j]=${arr[i]}
                        arr[i]=${temp}
                fi
        done
done;
echo "sorted arr ("${arr[@]}")"

Shell安装单机redis

#!/bin/bash
echo =================================
echo  自动化部署Redis脚本启动
echo =================================
redis_name="redis-5.0.14"
src_redis_path="/home/software/"
dest_redis_path="/usr/local/"
redis_conf_path="/home/software/config/redis.conf"
if [ ! -d ${dest_redis_path}${redis_name} ]
then
	if [ ! -d ${src_redis_path}${redis_name} ]
	then
		echo ${src_redis_path}${redis_name}" 文件夹路径不存在"
		exit
	fi
	cp -r ${src_redis_path}${redis_name} ${dest_redis_path}${redis_name}
fi

rm -f ${dest_redis_path}${redis_name}"/redis.conf"
cp -r ${redis_conf_path} ${dest_redis_path}${redis_name}"/redis.conf"

REDIS_PIDS=$(ps -ef | grep redis-server | grep -v grep | awk '{print $2}')
if [ "$REDIS_PIDS" = "" ]
then
	cd ${dest_redis_path}${redis_name}"/src"
	make
	make install
	while [[ ! -f ${dest_redis_path}"redis/bin/redis-server" ]]
	do
		echo "redis正在安装....."
	done;
	cd ${dest_redis_path}"redis/bin"
	./redis-server ${dest_redis_path}${redis_name}"/redis.conf"
	sleep 15s
else
	cd ${dest_redis_path}"redis/bin"
	./redis-cli shutdown
	./redis-server ${dest_redis_path}${redis_name}"/redis.conf"
	sleep 15s
fi
echo =================================
echo  自动化部署Redis脚本结束
echo =================================

Shell脚本实现tomcat启动和停止

Shell安装redis集群

posted @ 2023-05-10 17:05  sunpeiyu  阅读(3)  评论(0编辑  收藏  举报