logo
Tags down

shadow

How to loop Bash array in Expect script


By : DisplayName=
Date : September 15 2020, 02:00 PM
I hope this helps you . I have an array in my bash script: , The correct syntax to interpolate the array's values would be
code :
array set param ${my_file[@]}
array set param a.txt b.txt c.txt d.txt e.txt
array set param {one one.txt two two.txt}
/usr/bin/expect <<EOF
set timeout -1
spawn sftp $sftp_option $user@$host
expect "Password:"
send "$pswd\r"
expect "sftp>"
foreach arg {${my_file[@]}} {
 send "mget $arg*\r"
 expect "sftp>"
}
send "bye\r"
EOF


Share : facebook icon twitter icon

Formatting Expect Script Inside of User Command in Bash Script


By : kibria iqbal
Date : March 29 2020, 07:55 AM
I hope this helps . Might be an issue with timeout here... not sure how long the installer takes.
The default expect timeout is 10 seconds, if it doesn't see the expected text in that time, it will proceed regardless, you could change the timeout values like so:
code :
expect -timeout 100 $INSTALL_PATH_REQUEST
YES="\"Yes\""
YES="\"Yes\r\""
 expect -timeout 320 "Install Complete."

bash/expect/loop - how to loop a simple bash script doing telnet


By : Jonathan ST
Date : March 29 2020, 07:55 AM
wish helps you You can read the file within your expect script.
Open the file and assign the file descriptor to a variable, read each line and execute the above code you wrote.
code :
set fildes [open "myhosts.txt" r]
set ip [gets $fildes]
while {[string length $ip] > 0} {

    spawn telnet $ip
    expect "User Name :"
    send "username\r"

    expect "Password  :"
    send "password\r"
    expect ">"
    send "4\r"
    expect "*#"
    exit
    set ip [gets $fildes]
}
close $fildes

can you run expect command in a bash shell script for loop


By : David Boyd
Date : March 29 2020, 07:55 AM
Hope that helps When using a here document (< code :
for x in $IP
do

    /usr/bin/expect<<EOF

    spawn ssh -i /home/location/id_rsa root@172.17.26.$x
    expect "Enter passphrase for key 'id_rsa':"
    send "password\n"
    sleep 3
    log_file XMGcheck.log
    expect "~"
    send "cat /reg/nv/system/serial|sed \x22s/\x24/,/g\x22 ; tail -n 50 /usr/log/ams.log|grep -i xmg|wc -l \n"
    expect eof

    EOF
for x in $IP
do
    /usr/bin/expect<<EOF

    spawn ssh -i /home/location/id_rsa root@172.17.26.$x
    expect "Enter passphrase for key 'id_rsa':"
    send "password\n"
    sleep 3
    log_file XMGcheck.log
    expect "~"
    send "cat /reg/nv/system/serial|sed \x22s/\x24/,/g\x22 ; tail -n 50 /usr/log/ams.log|grep -i xmg|wc -l \n"
    expect eof

EOF
done

Exiting bash script for loop on expect script expect error


By : martoh
Date : March 29 2020, 07:55 AM
To fix this issue A bash for loop will not fail if part of its body returns non-zero. You have to explicitly test for it, and handle it. For example:
code :
for role in $user_roles
    do
            expect_scripts/users.exp $role"1" $role $user_email $password
            if [ $? -ne 0 ]; then 
                 exit 1; 
            fi
    done
for role in $user_roles
    do
            expect_scripts/users.exp $role"1" $role $user_email $password || exit 1
    done

Pass bash array to expect script


By : bellet
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a bash script that calls an expect script like so , Sample.sh
Related Posts Related Posts :
  • Brace expansion into a single argument
  • How to list all of the unique non-ascii characters in a file?
  • Loop through the directories to get the image files
  • Cannot Install Delve Go Debugger on Mac
  • Where a process substitution gets stdin from
  • What does Hash Colon (#:) mean as first line of shell script?
  • multiprocessing for bash loop
  • Do simple commands in bash run in subshells, since a single command can constitute a pipeline?
  • Append filename with last 3 characters of the parent directory in Bash
  • Updating values in nested variables
  • How can I add one of two random numbers to each row of a csv proportionately?
  • Bash function to "use" the most recent "dated" file in a dir
  • Find-While Process Substitution and Count of Files
  • Running Prolog commands from a bash script
  • hostname manipulation in makefile
  • Bash script does nothing when I run it, seems to keep waiting
  • How to replace a number with sed command if number%7==0 in bash?
  • Does bash have a `default`-equivalent for the case statement when using fallthrough?
  • Bash while loop behaves differently when run remotely vs locally
  • for loop with 2-digit variables for start and end values
  • how to rename two files to different name automatically in bash
  • How can I append an entry to an array in a while loop in bash?
  • Bash - Correct number in indian Phone Number format
  • add a column of zeros to a new text file with bash
  • Grep for matches inside a while loop
  • Nested if else bash statement
  • Best way of using `env` command and passing environment variables by file
  • Automatically move files of a certain type from folder A to B whenever they are added to folder A on macOS
  • Which tools to use to list pricing for all lineageOS ROMs?
  • What is the difference between ${foobar} and $(foobar) in a Makefile?
  • execute list of python files in directory shell script
  • Script : substitute value in script and display it
  • How to print the contents of crontab with line numbers inside a read command?
  • Cancel "tail -f" if the file hasn't changed for N seconds?
  • Schedule cron from 10PM to 1AM every half an hour
  • Bash alias causing error "bash: cd: too many arguments" only when set in .bashrc
  • Assigning a variable in a shell script for use outside of the script
  • How to make $1 a variable and get the first character?
  • echo unicode not actually scaping the characters
  • What is the shortest expression to match all file/dir names (including those beginning with a dot) in Bash?
  • Comparing SHA-512 Salted Hashes, displays filename during execution
  • Combining variable concatenation and for loops in bash
  • Shell Script question mark (?) issue in its uses
  • Use variable as operator in if test
  • How to pass environment variables from a string to a bash command
  • How do I subtract milliseconds from time in this format: "2020-01-06 11:27:12.280" in shell script
  • Bash read file line by line and append the value to a specific variable
  • How should i shrink my bash script into 5 for loops?
  • print newline in process substitution
  • Batch processing of a large JSON file with jq
  • Bash add characters before and after $foo
  • Bad substitution error in terminal related to bash profile
  • Git Clean removing the entire feature branch
  • How to ask Cocoa app to run an action from the terminal and then return the result
  • How do I edit current shell command without executing it?
  • How to Write A Second Column in Bash in an Existing txt file
  • cat multiple files in separate directories file1 file2 file3....file100 using loop in bash script
  • Iterate over a tuple in bash
  • db2 "describes" console table output is unreadable
  • Iterate over only files stored in git
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk