expect

How to use the output of the shell command in expect script's send

笑着哭i 提交于 2021-01-29 13:49:21
问题 I have a expect script written to perform a login operation. The login requires the 2fa code, this code can be obtained by executing the shell command 2fa my_login . Now how do I execute the 2fa command and pass it's output to the send of my script? I need to do something like send -- "$(2fa my_login)" . The output of the $(2fa my_login) should be passed to the send. My script #!/usr/bin/expect -f set timeout -1 spawn /home/local/apps/forticlientsslvpn/64bit/forticlientsslvpn_cli --server vpn

How can I fix my expect script for scp download?

左心房为你撑大大i 提交于 2021-01-29 05:42:55
问题 I am trying to use expect to bypass the password authentication process for a remote server I'm using, so I can download a series of files in bulk, each of which is stored in a different folder. The reason for using expect is the remote files are stored in separate folders, and the server I'm accessing won't allow me ssh key access. At present I am struggling to download a single file using expect, never mind numerous ones at once. Below is my simple script: #!/bin/bash #connect to the server

use expect to enter password when need sudo in script

可紊 提交于 2021-01-29 02:02:00
问题 I am using Ubuntu 14.04 and installed expect. I am trying to write a script to enter password when it prompted. UPDATED Code: #!/usr/bin/expect -d set timeout 20 set pw odroid spawn sudo apt-get update expect {\[sudo]\ password for odroid: } send "$pw\r" close Any suggestions? thx UPDATE Errors: expect: does "" (spawn_id exp4) match glob pattern "\[sudo]\ password for odroid: "? no [sudo] password for odroid: expect: does "[sudo] password for odroid: " (spawn_id exp4) match glob pattern "\

use expect to enter password when need sudo in script

不羁岁月 提交于 2021-01-29 02:00:07
问题 I am using Ubuntu 14.04 and installed expect. I am trying to write a script to enter password when it prompted. UPDATED Code: #!/usr/bin/expect -d set timeout 20 set pw odroid spawn sudo apt-get update expect {\[sudo]\ password for odroid: } send "$pw\r" close Any suggestions? thx UPDATE Errors: expect: does "" (spawn_id exp4) match glob pattern "\[sudo]\ password for odroid: "? no [sudo] password for odroid: expect: does "[sudo] password for odroid: " (spawn_id exp4) match glob pattern "\

Expect/TCL telnet proc does not wait for the prompt

倖福魔咒の 提交于 2021-01-28 10:54:06
问题 I have a Expect proc that sends command for telnet login and send commands. Inside the telnet proc I do a TFTP . The size of the file is 10MB. But the telent prompt does not wait until the prompt appears .It waits for the timeout period and comes off. is there any way we can wait for the prompt in Expect . Regards, Mithun 回答1: If the tftp file transfer takes longer than Expect's default timeout (10 seconds) you will need to set a longer timeout first. Eg. for a 60-second timeout, start your

TCL Expect kills child of child process

旧街凉风 提交于 2021-01-28 06:06:58
问题 I have an expect script like this #!/usr/bin/expect -f set timeout 30 log_user 0 set PASSWORD $::env(PASSWORD) set USERNAME $::env(USERNAME) set TOKEN $::env(TOKEN) puts stderr "Generating OTP" spawn oathtool --totp $TOKEN expect -re \\d+ set otp $expect_out(0,string) puts stderr "Connecting to VPN server" spawn -ignore HUP env openconnect -b https://vpn expect "GROUP:" send "Tech\n" expect "Username:" send "$USERNAME\n" expect "Password:" send "$PASSWORD\n" expect "Password:" send "$otp\n"

How do I tell expect that I have finished the interactive mode?

假如想象 提交于 2021-01-21 04:59:45
问题 I am writing some expect commands in bash. Script: #!/bin/bash set timeout -1 expect -c " spawn telnet $IP $PORT1 sleep 1 send \"\r\" send \"\r\" expect Prompt1> interact timeout 20 { sleep 1 } expect { Prompt2> {send \"dir\r\" } } " My intentions with the script are, first let it telnet into a machine, when it sees Prompt1, let it give control to me, I will execute a command to load a specific image. Then wait until Prompt2 shows up (which indicates image has been loaded). Then Let it

Automate SCP with multiple files with expect script

老子叫甜甜 提交于 2021-01-21 04:39:45
问题 So I have seen multiple posts on this and maybe I just haven't seen the right one. I am using an expect script to scp multiple files from my locale to a remote. I dont want to set up keys for passwordless logins, because then the servers cant be blown away and stood up with out more work, yes I could automate the key creation, I would just rather not. So I want to be able to use the * but every time I use the * it tells me. The reason I want to use * instead of a full name is because the

ssh-add from bash script and automate passphrase entry

故事扮演 提交于 2021-01-03 06:13:53
问题 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:13: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