shell脚本
1,nginx服务管理脚本
使用源码包安装Nginx不含带服务管理脚本,也就是不能使用"service nginx start"或"/etc/init.d/nginxstart",所以写了以下的服务管理脚本。
#!/bin/bash program=/apps/nginx/sbin/nginx pid=/apps/nginx/logs/nginx.pid function start { if [ -f $pid ];then echo "nginx 服务已经处于开启状态" else $program fi } function stop { if [ ! $pid ];then echo "nginx 服务已经关闭" else $program -s stop echo "关闭服务 ok" fi } function status { if [ -f $pid ];then echo "服务正在运行..." else echo "服务已经关闭" fi } case $1 in start) start;; stop) stop;; restart) stop sleep 1 start;; status) status;; *) echo "你输入的语法格式错误" esac
2,apt install sshpass
root@ubuntu20:/apps/harbor# cat ssh.sh #!/bin/bash #目标主机列表,需要自己修改成自己需要的ip #IP=" #192.168.50.171 #" #for node in ${IP};do for node in 192.168.80.{202..204};do sshpass -p 123456 ssh-copy-id ${node} -o StrictHostKeyChecking=no if [ $? -eq 0 ];then echo "${node} 秘钥copy完成" else echo "${node} 秘钥copy失败" fi done