expect

How to have Expect script output to file

[亡魂溺海] 提交于 2019-12-24 01:12:46
问题 I need to gather some statistics from a network switch and would like to use an expect script to output the data to a file. I would like to run this script as a cron job and have the data appended to the file when it is run. Following is the working code I have so far, I just do not know how to get the output to a file. Any help is greatly appreciated. #!/bin/bash #get mac-address count /usr/bin/expect -f -<<EOD spawn ssh user@192.168.1.100 sleep 2 #Catch the password prompt and send supplied

how to use regexp to match a parentheses in TCL

妖精的绣舞 提交于 2019-12-24 00:56:12
问题 I have a question about using regexp to match a parentheses in TCL. For example I have a string like this: yes, it is (true, and it is fine). I just want to match this part yes, it is (true , how to match it? 回答1: You can enclose parentheses in a character class as @bobah suggests, yes, it is [(]true But it's more common to escape it: yes, it is \(true But if you're escaping it, make sure you understand that you must either do this: regexp -- "yes, it is \\(true" $subject or this: regexp --

Escape string for putting it into regex in TCL

隐身守侯 提交于 2019-12-24 00:34:33
问题 I use Expect as testing framework and write some helper functions to simplify typing of matching patterns for expect command. So I look for function that transform any string into string in which all special regex syntax escaped (like * , | , + , [ and other chars) so I would be able put any string into regex without worrying that I break regex: expect -re "^error: [escape $str](.*)\\." refex "^error: [escape $str](.*)\\." "lookup string..." For expect -ex and expect -gl it is pretty easy to

Send command for password doesn't work using expect script in ssh connection

时光总嘲笑我的痴心妄想 提交于 2019-12-23 23:43:33
问题 I want to be able to login remotely to the router using SSH connection using expect script, and this is what I have: #!/usr/bin/expect set host "192.168.1.50" set user "root" set password "mypass" spawn ssh "$user\@host" expect "word:" send "$password\r" When I tried to use that, the router became unresponsive (and possibly timed out). When it went to password prompt line, it immediately went back out. I did authentication using my SSH key by manually typing "yes" when it prompted me with

expect inside while loop - loops forever

余生颓废 提交于 2019-12-23 20:19:45
问题 I'm new to expect scripts, so please forgive my stumbling... Below is the meat of my expect script. The intent is to scroll thru several screens of output, after each of which the user is prompted with "Continue? [y/n]". Finally, when there are no more screens, a "% " prompt is displayed, which SHOULD cause execution to fall out of the while loop. set more_screens 1 while {$more_screens > 0} { sleep 10 expect { "\[y/n]" { send "y\r"} "% " { set more_screens 0 } } } What happens instead is...

Install R 3+ on Redhat 6.3

浪子不回头ぞ 提交于 2019-12-23 15:21:52
问题 I want to install R on my Red hat cluster which has the version below: $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.3 (Santiago) When I went to R's homepage and this is what in their repository: I am wondering there is only redhat version 4 and 5 there and I don't know which version will best fit my operating system. Texinfo Problem Goes Here Since I have asked more than 6 questions today. Stackoverflow doesn't like me to ask more questions. So I will put the following

How to make expect command in expect program script to wait for exact string matching

随声附和 提交于 2019-12-23 09:46:59
问题 I want to know how to make expect command in expect script to wait for exact string to be matched before proceeding to next line in the script. Bourne shell (sh) script: #!/bin/sh #!/usr/bin/expect spawn ssh -Y localuser@lbblr-tirumala expect -exact "localuser@lbblr-tirumala's password: " # replace password with ur own passwd send "geomax45\r" # replace the prompt with ur own prompt expect "localuser@lbblr-tirumala:~$ " # run application send "./sample\r" expect "*Menu*\r 1. print hello world

eof not recognized in Expect Script

那年仲夏 提交于 2019-12-23 05:17:55
问题 i have got some problems in my expect script. I am spawning a scp file upload but the eof is not recognized. The expect rans into the timeout before the script goes on. What am i doing wrong?? Here is the script function ssh_upload_file () { test_log INFO "Uploading File $3 to Device $2 with a $1 seconds timeout" "ssh_upload_file" last_log_entry_to_detail expect <<- DONE set outfilename "$DETAIL_LOG" log_file "$DETAIL_LOG"; set timeout $1 set lantime_ip $2 system "touch ~/.ssh/known_hosts"

bash script which downloads a file with sftp

百般思念 提交于 2019-12-23 04:19:10
问题 I need to make a sftp connection with a password and download a file. There is an ip restriction so first of all i should make a ssh connection. I wrote a script but it stucks after connecting with ssh. Note: i also tried doing it with an expect script but it also didn't work. #!/usr/local/bin/ ssh test@test1.t.com lftp sftp://test2:123456@test2.com get "file.xls" Edit: You can also see my expect code here. #!/usr/local/bin/expect -f expect -c " spawn ssh test@test1.t.com expect \"test\@test1

top command in shell script

送分小仙女□ 提交于 2019-12-23 04:06:09
问题 I am trying to get first 5 lines of top command through expect script. Im calling this expect script from a shell script along with some other stuff. top | head -5 gives me below output ie without cpu stats- top - 09:10:58 up 46 days, 17:03, 12 users, load average: 0.01, 0.02, 0.00 Tasks: 138 total, 1 running, 137 sleeping, 0 stopped, 0 zombie Mem: 16432400k total, 8408096k used, 8024304k free, 609200k buffers Swap: 6290736k total, 0k used, 6290736k free, 6754356k cached If I run just top