FAQ Database Discussion Community


How to store a line from expect_out(buffer) to a variable in tcl

bash,foreach,tcl,expect
For example, if the output ( in expect_out(buffer) )is blah blh blah asdjsudfsdf how can I store the 2nd line to a variable? so far I have this: foreach line [split $expect_out(buffer) "\n"] { if [lindex $line 1] { set variable $line } } But this does not work, it...

Using expect on a Mac to access a router via telnet

osx,telnet,expect
I'm trying to write a script on a Mac which should access a router via telnet. This is to enhance the router's power, which cannot be done via web. The problem is that the telnet channel is blocked, and in order to unlock it I need to run the following...

expect fails when running proc inside proc

bash,unix,tcl,expect
My script works fine (retrieves sftp prompt) when using one proc. But when I try to use proc inside proc, script gets stuck, and I do not know why. Please do not refactor the code, that is not the point, I need to understand what is the issue here. Working...

Else in shell expect command

php,shell,expect
I have successfully executed the following command via php but it only works straight forward. If the host is already added or any expect is mismatched means it is failing. Can anyone suggest a way to handle this even if the expect is mismatched it should goto the next step?...

Expect, find files with timestamp

tcl,expect
I have folder with files as below: RBS_delete20150518-170641.xml RBS_delete20150517-160545.xml ... I'm using expect program, but can't get regexp working on date stamp: if {[file exists /home/ARNE/ARNE/SCRIPTS/RBS_delete[0-9].xml]} ...

Expand passed arguments before printing with puts to virtual server

shell,tcl,expect
I am having trouble with an expect script not evaluating arguments. Everything in the puts ${file_id} block (simplified obviously) gets placed onto a virtual machine and is later used to for configuration. The block you see puts the same code into a local directory for me to see if things...

Saved format output in columns [grep, sed, awk or ?]

regex,perl,awk,sed,expect
I have created a Expect Script file that telnet to multiple +200 switches. My code: #!/usr/bin/expect -f #Slurp up the input file set fp [open "ip.txt" r] # To avoid empty lines, 'nonewline' flag is used set file_data [read -nonewline $fp] close $fp set prompt ">" log_file -noappend switch_port_status.txt foreach...

Expect call shell script

bash,expect
I am trying to call a shell script and store the result in an expect variable. get_pw.sh accepts 2 args and decrypts the file using the provided md5hash. If I execute ./get_pw.sh file.test md5hash from the bash prompt it returns the password string as expected. When called from expect, the...

can't trim \r in variable

bash,expect
I get a list of files from a remote dir. Now I want to know if those files exist in a local dir. My problem is, that the \r in the string of each file name is untrimmable. I did it before in the 4th line and it worked. numOfRemoteFiles=`expect...

Expect script for checking ssh connection for a list of ips

shell,ssh,scripting,expect
Can anyone help me in creating an expect script to just do an SSH on a list of servers and check if it was fine. I do not need to interact, do not need to fire any command on each server, I just want to do an ssh and come...

Read .properties file to set value in use and password field in Expect shell script

shell,expect
How to read values from Properties file for user and Password field in expect in shell? Suppose if i have values.prop file having values like below, user=abcd pwd=xxxx I want to set the above value in my test.sh as below !/usr/bin/expect set user "abcd" set password "xxxx" spawn ssh [email protected]$host...

Using a tcl proc to login to devices

tcl,expect,session-timeout
I have a tcl (expect) script to log into devices and transfer files. Unfortunately, the files are large, and during the transfer period the ssh connection ends (the files are still transferred though). So I basically have to login again before I can perform more actions on the device. Since...

Why are my equal strings not equal?

bash,expect
I found lot of same problems, but no solution help with mine. listingInOrder.sh set user [lindex $argv 0] set dir [lindex $argv 1] set password [lindex $argv 2] set N [lindex $argv 3] spawn ssh [email protected]$N.physik.hu-berlin.de ls -1tr $dir | tail -1 expect "Password:" send "$password\r" interact mainfile.sh filelocal=`ls -1tr...

Running multiple instances of one tcl script

multithreading,bash,tcl,expect,multiple-instances
Currently I am reading in host names from a file using a foreach command and using this hostname to connect to the device. All this is done within my TCL script. Is there a way I can run multiple instances of the script so that each device is queried separately?...

Perl ssh Password

python,perl,ssh,expect
I am trying to use perl to SSH in to a machine and issue a few commands... my $ssh = Net::SSH::Perl->new($host); $ssh->login($user,$pass); my($stdout, $sterr, $exit) = $ssh->cmd($cmd); print "$stdout \n" This is the general idea, but I am still stuck at the prompt for the password. I have also attempted...

Duplicated output from Expect Script

linux,bash,ssh,expect
I have an expect script A to ssh that runs on host A, remotes to host B, runs bash script B on host B, then append output of script B back to a file on host A. After running this expect script, appended contents are exactly what I desire, BUT...

Expect with SJWS wadm command

bash,expect
I'm using expect in the very traditional way of match string, send desired inputs within a bash script wrapping around iplanet/SJWS wadm command, which itself is a bash script calling a java program. Rather than when I run the program manually, certain components such as passwords get echoed back to...

Set up TightVNC programmatically with BASH

bash,debian,expect,vnc-server,tightvnc
I'm writing a script to set up VNC (amongst other things) on many debian based devices. I want to include VNC in this setup (specifically, tightVNC if possible) and have it set a given password (randomly generated by the script). The problem is, every guide I find seems to assume...

How to send BACKSPACE in expect?

linux,expect
I'm trying to automatize some tool, and I have spawn /home/rundoc.sh $path $view expect "Please enter correct product number []" sleep 2 send "CX102504\r" Problem is that by default in prompt is added last product number , for example Please enter correct product number [] CX000001 When I run my...

No Such Variable When Using While Loop in Expect

tcl,expect
I'm attempting to access a variable within a while loop in expect, but I keep getting an error that the variable doesn't exist. The code in question: #!/usr/bin/expect spawn ./simulator.sh set timeout 1 ...<extra code>... # Return the time in seconds from epoch proc getTime {year month day hour minute}...

Bash script to spawn and execute commands

linux,bash,expect
I am trying to create a bash script to ssh into a session and run a command then exit out of the session. currently this is what i have so far: #!/usr/bin/expect -f spawn ssh [email protected] expect "assword:" send "password\r" expect "#" send "cd /data2/someDirectory\r"------> don't see this command being...

Expect Script through Putty works but not when called by scripts executed via http

ssh,expect
I have an expect script that connects to one of our remote servers, it runs a few commands as admin then exits. When i run the script through the Putty CLI it works properly. However when I call the script via http it fails, the script isn't presented with the...

EXPECT SCRIPT:procedure being ran before actual code

stored-procedures,tcl,expect,procedure
I'm creating an expect script to let me use macros in my managing of cisco devices. after all the connections are done, my script waits for the "#" so I know the user is ready for input. if I define my procedure AFTER interact, script works fine, but obviously it...

autoexpect on docker centos6.6 container cannot work

centos,docker,expect,autoexpect
Docker container pure image: centos6.6 after bash, I install these: yum -y install tar zip unzip expect glibc.i686 Package expect-5.44.1.15-5.el6_4.x86_64 already installed and latest version and run autoexpect, I always get these error: [[email protected] bin]# autoexpect autoexpect started, file is script.exp no such variable (read trace on "env(SHELL)") invoked from...

How to match a colon after a close bracket

tcl,expect
Why does the following not match the : expect { timeout {puts timedout\n} \[1\]: {puts matched\n} } > expect test.tcl [1]: timedout If I change it and remove the colon the match works: expect { timeout {puts timedout\n} \[1\] {puts matched\n} } $ expect test.tcl [1] matched Or if I...

Expect - wait until process terminate

telnet,expect
I am completely new in Expect, and I want to run my Python script via Telnet. This py script takes about 1 minute to execute, but when I try to run it via Telnet with Expect - it doesn't work. I have this expect simple code: #! /usr/bin/expect spawn telnet...

Expect script output at Perl console

perl,expect
I have a exp script -script.exp to enter a name and password. it calls test.sh file like below. set timeout -1 spawn ./test.sh -create match_max 100000 expect -exact "Enter the name: " send -- "abcd\r" expect -exact "\r Please confirm password: " send -- "xxy\r" expect -exact "\r expect eof...

Tcl expects output from tclsh to shell script

linux,variables,tcl,expect,cisco
I'm searching for last few days for solution to my problem so finally I came here. I got to write a Tcl script that should be opened from a Linux/Debian system. The problem is, that the script should log into a Cisco router and then go into the special tclsh...

Convert expect output from DOS to UNIX style in realtime

tcl,expect,dos2unix
I write some expect scripts by connecting to a remote host through serial connection. My problem is that the output of the spawned process (enabled with log_user 1) contains DOS-style endings (each line being terminated with ^M when reading logs in VIM). I normally run dos2unix on all logs at...

Quickest way to evaluate a variable in TCL

reference,tcl,expect,evaluation
I have a variable myref set to: set myref {$expect_out(buffer)} What is the quickest way to get the $expect_out(buffer) into myval? set myval [HOWTOEVAL $myref] ...

Python 3, extract info from file problems

file,python-3.x,edit,expect,xlwt
And again, asking for help. But, before I start, here will be a lot of text, so please sorry for that. I have about 500~ IP addresses with devices 2x categories in .xlsx book I want: telnet to device. Check device (by authentication prompt) type 1 or type 2. If...

How to ignore or Pass 'Yes' when The authenticity of host can't be established in Expect Shell script during Automation

shell,automation,rsa,expect,host
I want to Provide 'Yes' automatically or Ignore it and proceed in a SECURE way, when the below statement comes during execution of my Expect Shell script?. #!/usr/bin/expect spawn ssh [email protected]$host The authenticity of host 'abcdef (10.566.1.98)' can't be established. RSA key fingerprint is jk:94:ba:93:0b:eb:ff:df:ea:gh:hj:23:3c:hj:9c:be. Are you sure you want...

Running shell script as admin using expect on OS X

bash,shell,expect,osx-yosemite
I am trying to let non-admin users run a script in a shared environment that requires root privileges. I was going to build either an AppleScript or Automator application that invokes expect in order to pass the login credentials (yes, I know the dangers, it will all be execute only)....

expect script regex not working

regex,expect
This script is failing to work as expected: #!/usr/bin/expect set timeout 2 set server [lindex $argv 0] set user [lindex $argv 1] set password [lindex $argv 2] set mac [lindex $argv 3] set interface "po1" spawn ssh [email protected]$server expect "Password:" send -- "$password\n" expect "*>" send "show mac address-table address...

Spawning interactive CLI command with Expect exits with 0 early, when run as Symfony Process in Behat context

php,bash,symfony2,expect,behat
This is quite an advanced question, perhaps knowledge of Symfony and Behat may not be necessary to understand the problem. So in order to test the input and output of an interactive CLI app bin/albumgrab I've written in PHP using the Symfony Console component, I've set up my Behat feature...

Questions on Regex algorithm (not necessarily EXPECT related)

regex,tcl,expect
I'm trying to create a regex to capture the neighbor detail of my devices (example output below). I could hard code each individual line, but I'm looking for a better solution. maybe learn a new algorithm. I'm interested in capturing Device ID (HOST1), Interface (GigabitEthernet0/1), and Port ID (GigabitEthernet2/43). for...

Mockito Expect an Exception

exception-handling,mockito,junit4,expect,mockmvc
I'm trying to test the method below with Mockito and Junit: @Transactional @RequestMapping(method=RequestMethod.PUT,value ="/updateEmployer/{empId}") public @ResponseBody Object updateEmployer(@PathVariable Integer empId,) throws Exception { Employee e = EmployeeRepository.findOne(empId); for (Department de : e.getDepartement()){ de.setDepartmentName(e.getName + "_" + de.getName()); } EmployeeRepository..saveAndFlush(e); return null; } This is the method Test: @Test // throw...

Pexpect eats bash prompt

python,shell,expect,pexpect
This expect script launches a bash shell that includes the prompt: #! /usr/bin/env expect spawn -noecho "bash" expect "$ " send "echo 'Hello, " interact e.g. [email protected]:/path/to/working/directory$ echo 'Hello, I tried doing the same thing with Pexpect: #! /usr/bin/env python import pexpect child = pexpect.spawn('bash') index = child.expect("\$ ") child.send("echo...

show ip interface brief in expect script

telnet,remote-access,expect,cisco
I would like to be able to setup a expect script file that would remote into multiple switches. Do you know how to write expert script for telnet to 200 switches and run a command example: show ip interface brief then list all switch status on Linux?? #!/usr/bin/expect -f spawn...

RPM command repeatedly asking for password

expect,rpm
I am signing a big set of RPM packages (50000) using the below command find $1 -name \*.rpm |xargs rpm --resign As part of the RPM command structure, it asks for password. I am using expect script for supplying the password, like this. expect -c " spawn $1 expect \"Enter...

Bash - Hiding a command but not its output

bash,tcl,expect
I have a bash script (this_script.sh) that invokes multiple instances of another TCL script. set -m for vars in $( cat vars.txt ); do exec tclsh8.5 the_script.tcl "$vars" & done while [ 1 ]; do fg 2> /dev/null; [ $? == 1 ] && break; done The multi threading portion...

Segmentation fault with expect 5.43.0 with tclsh 8.4

ubuntu,tcl,expect
I am currently using expect 5.43.0 along with tclsh 8.4. When i include the expect package i get segmentation fault. my script contains #!/usr/bin/tclsh package require Itcl package require Expect How to fix this problem. Any suggestions will be helpful Regards...

Catch error in tcl

tcl,expect
I have part of expect script, which is connecting to remote server, and running command /opt/arne/bin/import.sh -f /home/janko496/moshell/test.xml -val:rall. So basicily it is doing ok, but what I need is catch some errors which may happen after this command -vall-rall and then exit. Here is the log of the script...

Execute a python script from expect

python,expect
I am using expect for automation and I want to execute a python script from it. But it is not working....This is what I have tried so far #!/usr/bin/expect spawn "./os_fun" and #!/usr/bin/expect spawn "./os_fun.py" and #!/usr/bin/expect spawn python "./os_fun(.py)" The "os_fun.py" contains the simple code: #!/bin/usr/python import os print...

Cannot reconnect to serial port that was previously opened in the same TCL script

serial-port,tcl,expect,permission-denied,reconnect
I have been working towards automating hardware testing using TCL, where the hardware is connected to a serial port. The current script can connect to the serial port the first time through, and disconnect at the end. However, it cannot reconnect to the serial port again unless the application is...

Capture output from ssh with expect script

ssh,output,send,expect,cisco
I want to capture the output of my expect script in a file.txt. #!/usr/bin/expect -f match_max 10000 set timeout 120 eval spawn ssh 10.0.0.0 set prompt ":|#|\\\$" interact -o -nobuffer -re $prompt return send "password\r" expect ">" send "sh cdp neighbors detail\r\r " expect ">" send "\n" sleep 5 This...

if all else fails tcl script fails

tcl,expect,scp
I am trying to make a script to transfer file to another device. Since I cannot account for every error that may occur, I am trying to make an if-all-else fails situation: spawn scp filename [email protected]:filename expect "word:" send "password" expect { "100" { puts "success" } "\*" { puts...

Parsing command line using argc and argv in expect

expect
I have an expect routine, which needs to spawn a process and pass the command line arguments I passed to the expect routine to the spawned process. My expect routine has the following line spawn myProcess $argv and when I call my expect routine I call it from the command...

Tcl script breaks out of foreach loop

foreach,nested,tcl,expect
I have a tcl script to log into devices and print SUCCESS. This is the script: The file: (the first IP is valid, and can be logged into, the next 3 are fake). 192.38.133.145 178.18.34.48 183.24.56.3 145.234.67.145 The script: #!/bin/expect package require Expect set file [open "hosts" r] set f_data...

How can I check if a directory is empty?

tcl,expect
I'm aware that expect is tcl-in-sheep's-clothing, but even when I google with that in mind I'm coming up empty. Is there a way to determine if a particular directory is empty (or not empty, I can just use negation)?...

Expect - Different timeout for expect_user and expect?

expect
I'd like have an unlimited (or very large) timeout for expect_user and the default timeout for expect. Is there a way to set different timeouts? Or would I just have to manually do it before every change in usage?

Perl expect doesn't work after logout

perl,ssh,expect
A very simple code to connect to a server, run some commands, disconnect and run some more commands locally. #!/usr/bin/perl use strict; use warnings; use Expect; my $timeout = 15; my $password = "1234"; my $expect = new Expect; $expect->raw_pty(1); $expect->spawn("bash\n"); $expect->send("echo run some initial commands locally\n"); # edit: added...

How to return from shell 'read' command passed in expect script?

linux,shell,ssh,user-input,expect
I am really new to using expect, and a bit confused regarding passing commands to an expect script, so please bear with me... I have searched numerous forums, but cannot seem to find an example of an expect script that uses the read command to get user input. In my...

sshpass doesn't work with SSH ProxyCommand option

ssh,expect,sshpass
I am trying to automate SSH login for a SSH tunnel using a proxy: I do not want to use the ssh-copy-id solution sshpass works properly when I set the ssh tunnel without ProxyCommand option but it doesn't work with the option set (Write failed. Broken pipe). The ssh tunnel...