Expect自动化工具简介

公司服务器使用了两层跳板机,外面的一台我们管它叫 server A, 另外一台 叫它 server B。 虽然我不知道这种双保险给公司带来了多少安全感,但是我知道我的运维效率降低了差不多90%吧 :>。 server A被直接暴露在公网上, 我们不能使用 ssh key 只能使用 password认证ssh。 这还不算完,server A每3小时改一次自己的root密码。 后面的server B跳板机器的自我安全感就强多了,server B可以直接免密使用ssh key登陆所有的内网服务器,而且允许server A免密登陆到自己。 我决得这样两次登录很浪费时间,于是写了个脚本从外网一次性登陆到server B服务器上。 expect 脚本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #!/usr/bin/expect -f # for anyone not familar with expect # should read this awesome post # https://www.pantz.org/software/expect/expect_examples_and_tips.html set timeout 15 ### CHANGE pwd every 3h set pwd "mySuperSecretpwd123" set nested_ssh "ssh server_B" ## for debug # log_user 0 # exp_internal 1 send_user "going to connected to server A\n" spawn ssh -q -o StrictHostKeyChecking=no server_A expect { timeout { send_user "\ntimeout Failed to get password prompt, is VPN on?\n"; exit 1 } eof { send_user "\nSSH failure for server A\n"; exit 1 } "*assword:" } send "$pwd\r" expect { timeout {send_user "\nSSH failure for server B\n"; exit 1 } "Last login:*" } send "$nested_ssh\r" interact 基本语法 简单说下基本流程如下: ...

March 19, 2020 · datewu

Neutron小记

前段时间的花了很多功夫对接k8s和openstack的kuryr-kubernetes网路组件。 学到了很多openstack的知识,今天抽出时间来整理下。 client 首先是 install openstack-cli neutron client: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/bin/bash [root@deoops ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.5 (Maipo) #### add openstack yum repo source [root@deoops ~]# vi /etc/yum.repos.d/openstack.repo [root@deoops ~]# yum install -y python2-openstackclient openstack-neutron [root@deoops shells]# cat source export OS_PROJECT_DOMAIN_NAME=default export OS_USER_DOMAIN_NAME=default export OS_PROJECT_NAME=your_project_name export OS_USERNAME=your_use_name export OS_PASSWORD=your_pwd export OS_AUTH_URL=http://10.8.1.3:35357/v3 export OS_IDENTITY_API_VERSION=3 export OS_IMAGE_API_VERSION=2 vip 我们来创建一个virtual IP验证上一步配置的openstack source对不对 : ...

April 21, 2019 · datewu