记shell--expect发布脚本
By skyshappiness Posted 2023-01-02 16:24:22 In

一、deploy源码
      #!/bin/bash
      ipList=()
      filePath='/home/hd/newDomain2url/domain2url'

      for i in ${ipList[*]};do
      ##远程执行php安装命令
      # expect <<EOF
      # spawn ssh root@${i}
      # expect "Last login" {send "php74 -v\n"}
      # expect "未找到命令" {send "yum list installed epel-release\n"}
      # expect {
      # "没有匹配的软件包可以列出" {send "yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \n";exp_continue}
      # "y/d/N" {send "y\n";exp_continue}
      # "完毕" {send "yum list installed epel-release\n"}
      # }
      # expect "installed" {send "yum list installed remi-release\n"}
      # expect {
      # "没有匹配的软件包可以列出" {send "yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm\n";exp_continue}
      # "y/d/N" {send "y\n";exp_continue}
      # "完毕" {send "php74 -v\n"}
      # }
      # send "yum list installed remi-release\n"
      # expect "installed" {send "php74 -v\n"}
      # expect "未找到命令" {send "yum -y install php74-php-common php74-php-pecl-redis5 php74-2.0 php74-php-pecl-geoip php74-php-mbstring php74-php-pecl-mongodb php74-php-json php74-php-pecl-msgpack php74-php-devel php74-php-pecl-igbinary php74-php-mysqlnd php74-php-pecl-zip php74-php-bcmath php74-php-xml php74-php-soap php74-php-fpm php74-php-process php74-runtime php74-php-cli php74-php-pdo php74-php-pecl-msgpack-devel php74-php-gd php74-php-opcache php74-php-intl \n";exp_continue}
      # expect "完毕" {send "exit\n"}
      # expect "Zend Engine" {send "exit\n"}
      # expect eof
      #EOF

#远程创建项目文件夹目录
expect <<EOF
spawn ssh root@${i}
expect "successful" {send "mkdir -p ${filePath}\n"}
send "exit\n"
expect eof
EOF
#scp同步代码文件
echo "scp -r ${filePath} root@${i}:${filePath%/*}"
scp -r ${filePath} root@${i}:${filePath}
done



二、ssh免登做法

ssh-keygen -t rsa #生成一份本机的公钥
#此处因为原机器没做过免登,所以直接scp覆盖文件了
scp /root/.ssh/id_rsa.pub root@172.104.126.241:/root/.ssh/authorized_keys #复制到远程的.ssh文件夹下

友情链接
联系方式
  • 邮箱 / E-mail:121388038@qq.com