expect

ssh-add from bash script and automate passphrase entry

拥有回忆 提交于 2021-01-03 06:11:49
问题 I am trying to do ssh-add from script (don't care about about security at the moment). Now ssh prompts for passphrase, which needs to be automated, so i read couple of things like this and found expect. And now i do following: eval `ssh-agent -s` script tmp.sh defined as : #!/usr/bin/expect spawn ssh-add /root/.ssh/id_rsa expect "Enter passphrase for /root/.ssh/id_rsa:" send "my_pass" interact ./tmp.sh ssh-add -l If ssh-add would have worked it shows something like 4096 SHA256:wlfP

ssh-add from bash script and automate passphrase entry

大城市里の小女人 提交于 2021-01-03 06:11:41
问题 I am trying to do ssh-add from script (don't care about about security at the moment). Now ssh prompts for passphrase, which needs to be automated, so i read couple of things like this and found expect. And now i do following: eval `ssh-agent -s` script tmp.sh defined as : #!/usr/bin/expect spawn ssh-add /root/.ssh/id_rsa expect "Enter passphrase for /root/.ssh/id_rsa:" send "my_pass" interact ./tmp.sh ssh-add -l If ssh-add would have worked it shows something like 4096 SHA256:wlfP

How to get Command history by cursor key in Linux tclsh

不羁的心 提交于 2020-12-29 02:45:41
问题 Can get the command history by using cursor key (like up arrow key) in TCL shell (tclsh). I am running tclsh on fedora with linux version 2.6.21. 回答1: You want access to the readline library, you can do that with rlwrap: $ rlwrap tclsh Useful options are -c for file name completion, and -f to add words from a file to the completion list: $ rlwrap -cf my_complete_file tclsh Since you almost always want to use rlwrap , adding a shell alias is useful: alias tclsh='rlwrap tclsh' 回答2: I usually

How to get Command history by cursor key in Linux tclsh

荒凉一梦 提交于 2020-12-29 02:45:26
问题 Can get the command history by using cursor key (like up arrow key) in TCL shell (tclsh). I am running tclsh on fedora with linux version 2.6.21. 回答1: You want access to the readline library, you can do that with rlwrap: $ rlwrap tclsh Useful options are -c for file name completion, and -f to add words from a file to the completion list: $ rlwrap -cf my_complete_file tclsh Since you almost always want to use rlwrap , adding a shell alias is useful: alias tclsh='rlwrap tclsh' 回答2: I usually

how to check if a host is in your known_host ssh

雨燕双飞 提交于 2020-12-02 06:22:11
问题 I have the following command works in my script that adds the host to the known hosts in ssh. VAR2=$(expect -c ' spawn ssh -o StrictHostKeyChecking=no '"$REMOTE_HOST_USER@$REMOTE_HOST_IP"' expect "*?assword:*" send "'"$REMOTE_HOST_PASSWD"'\r" expect { "Permission denied, please try again." { exit '"$WRONG_PASSWORD"' } } ') Works fine, but I need to control before the command if the host is already in known_hosts and not execute command if it is already in known_hosts. How can i check if an

how to check if a host is in your known_host ssh

心已入冬 提交于 2020-12-02 06:20:42
问题 I have the following command works in my script that adds the host to the known hosts in ssh. VAR2=$(expect -c ' spawn ssh -o StrictHostKeyChecking=no '"$REMOTE_HOST_USER@$REMOTE_HOST_IP"' expect "*?assword:*" send "'"$REMOTE_HOST_PASSWD"'\r" expect { "Permission denied, please try again." { exit '"$WRONG_PASSWORD"' } } ') Works fine, but I need to control before the command if the host is already in known_hosts and not execute command if it is already in known_hosts. How can i check if an

how to check if a host is in your known_host ssh

家住魔仙堡 提交于 2020-12-02 06:18:18
问题 I have the following command works in my script that adds the host to the known hosts in ssh. VAR2=$(expect -c ' spawn ssh -o StrictHostKeyChecking=no '"$REMOTE_HOST_USER@$REMOTE_HOST_IP"' expect "*?assword:*" send "'"$REMOTE_HOST_PASSWD"'\r" expect { "Permission denied, please try again." { exit '"$WRONG_PASSWORD"' } } ') Works fine, but I need to control before the command if the host is already in known_hosts and not execute command if it is already in known_hosts. How can i check if an

分发系统介绍,expect脚本远程登录,expect脚本远程执行命令,expect脚本传递参数

我们两清 提交于 2020-10-28 17:47:34
分发系统介绍 场景:随着业务越来越大,网站或者APP服务端所使用的编程语言为PHP,需要配置lamp或者lnmp环境,还需要把代码上传到服务器上去。但是平时业务功能不断增加,需要改代码,如果有几十台上百台机器,就需要一个分发系统,将每次更新的代码发布到新的机器上去。 核心shell脚本:expect,可以实现传输文件,也可以远程执行命令 思路:首先要准备一台模板机器,机器上的代码是最新代码(准备上线),然后要知道上线机器的IP地址,对应用户的密码,使用expect脚本,借助于rsync将这些代码推送到机器上去,还可以通过expect去执行一些命令。 expect脚本远程登录 首先安装expect 自动远程登录 加入执行权限 执行expect脚本,成功登录 expect脚本远程执行命令 expect "]*" ,当匹配到"]"时,执行命令 远程登录并执行命令然后退出 查看执行结果 expect脚本传递参数 执行脚本 执行多条命令,用双引号括起来 来源: oschina 链接: https://my.oschina.net/u/3708406/blog/1625521

shell与expect混编远程执行脚本

|▌冷眼眸甩不掉的悲伤 提交于 2020-10-28 15:11:09
前言 此处的shell为bash 。 维护工作中,对于多台服务器进行相同操作,人工操作需要进行多次登陆登出,费时费力,参考网上资料,总结了个遍历操作的脚本。 步骤: 1. 先行把登陆后的操作命令,写成shell脚本,通过scp批量传送到远程主机的指定目录; 2. 使用 shell 进行遍历操作,使用 expect 语法进行交互操作,通过混编 shell 和 expect 语法完成对多台主机的相同操作。 #!/bin/bash #@author Martin Deng #@date 2018-03-02 #目标文件夹 DIR_TARGET="/root" #目标脚本 SH_TARGET="myShell.sh" #登陆的用户 USER="root" #登陆的密码 PASSWORD="passwd" #目标主机 HOSTS="host_01,host_02" # 按逗号分隔 OLD_IFS="${IFS}" IFS="," arr=($HOSTS) IFS=${OLD_IFS} # 遍历执行 for HOST in ${arr[@]} do echo "USER: ${USER} , HOST: ${HOST} , PASSWORD: ${PASSWORD} , DIR_TARGET: ${DIR_TARGET} , SH_TARGET: ${SH_TARGET}" /usr/bin