Newbie here. My goal is to have the expect script log into the Ubuntu 18.04 server and run two commands (lsb_release -a and ip addr) and eventually pipe the output/results to a file. For now, I would be happy to get this one command or two to run successfully. How to fix this?
Error: I get the password prompt but the script isn't passing the password (??) Normal response/output using "ssh -l" from the cli.
Moderator's Comments:
Please use CODE tags for sample input, sample output, AND code segments.
Last edited by Don Cragun; 03-04-2019 at 09:07 PM..
Newbie here. My goal is to have the expect script log into the Ubuntu 18.04 server and run two commands (lsb_release -a and ip addr) and eventually pipe the output/results to a file. For now, I would be happy to get this one command or two to run successfully. How to fix this?
Error: I get the password prompt but the script isn't passing the password (??) Normal response/output using "ssh -l" from the cli.
Moderator's Comments:
Please use CODE tags for sample input, sample output, AND code segments.
Why do you have so many <space>s at the start of the strings you expect to see from the remote host? You don't show those leading spaces in the normal output that you get when you login manually.
Why do you have <space>s at the start of the strings you send to the remote host? I assume that "admin" is a sample and not your real password for the user "admin" on that server, but you have specified that the first character of the password you are sending to the remote host is a <space>. Is that really what you want?
Why do you have <space>s at the start of the strings you expect to see from the remote host? You haven't shown us <space>s in those spots in the output you get from the remote hosts when you login manually. Why do you expect the remote host to send those <space>s when you try to login programmatically?
You're probably better off just using expect to look for the end of what you expect the remote host to send instead of looking for everything. There is less chance that you have a typo that will keep you from logging in. (I.e., look for "password: " instead of looking for " admin@192.168.1.12's password: " and include the <space> at the end of that ONLY if the remote server actually includes a <space> in the output it sends when it is asking you to supply your password.)
If you type the command lsb-release -a with a leading and trailing <space>, but do not hit the enter key; what does your local system do? Does it guess that you're done and run the command for you, or does it patiently sit there waiting for you to finish the command by hitting the enter key?
If you want the remote system to run that command, shouldn't you send it a \r to tell it that you're done entering the command?
When debugging these sort of scripts you should have a much shorter timeout. You don't want to wait for 60 seconds for expect to tell you it missed something:
Once it's working OK then bump you timeout up to a reasonable value, I still think 60 seconds it too long for a login prompt or for those simple commands to complete.
Is there a reason not to generate an SSH key to provide a passwordless connection? Using expect is trying to break through the well considered security practice of SSH.
If you get it set up, then the client just needs to call in in one line. The following allow for progressively more complex calls according to your need. You only need the simplest one that works for you:-
Would that not simplify the client side code? Is there a reason to attack SSH with expect? I assume you have credentials to get to each server. This will take a little effort first time to get the SSH connection set up, but then it is so much easier to actually use and leaves your script much cleaner.
I need to copy python script file to around 100 servers using expect script.
1. Copy script to my user home first(/home/myhome) on each remote server
2. change permissions on copied file to 766.
3. sudo to appuser1 account on remote server. copy script file from my user home to /usr/bin/... (1 Reply)
Dear All,
I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Hello All,
I hope someone could help me with this.
I'm creating a shell script to run a process. The trouble is, part of the process has to be ran as a different user. I can 'su' to the user ok, but I'm having trouble passing a 'cd' command as well as some variables I set earlier in the... (1 Reply)
Hi
I'm trying to run a script " abc.sh" which triggers "use.sh" .
abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script.
Please find below the scripts:
#abc.sh
#!/usr/bin/expect -f
exec /root/use.sh
expect "*name*"
send... (1 Reply)
How can I pass password in SSH command without using expect in a shell program.
I don't have expect installed on my Solaris server.
#!/bin/bash
ssh user@hotname (how to supply pass in script?:wall:)
Experts please help its very urgent.
Shrawan Kumar Sahu (4 Replies)
Hi
I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue:
I want expect script for random passwords and random commands generation.
please can anyone help me?
Many Thanks in advance (0 Replies)
All,
I am trying to use expect to send SFTP password because I am unable to share a key with the vendor.
They gave me a password that uses some symbols in it like $ and !
When i try to use the send command in expect it thinks the $ is a variable.
Is there anyway to have it send the... (2 Replies)
Hello folks
I have a conf file ,say 'pass.conf' ,which is storing ascii password : PASS1111.
I need to encrypt this password once and store it in a file.
I ,then need to write a script which would read this encrypted password and decrypts it.The o/p o this script shud be this decrypted... (8 Replies)
Could someone please help me...I have an expect script. There's a need for a log in during the script and a password is required...right now the password is just a variable in the expect script...what would be the best way to put that in an encrypted flat file and have the expect script pull the... (2 Replies)
Hi,
Does anybody know how to change the password on multiple servers with a script. I have 300 Sun boxes and the password expiry is set to 30 days. Im in a process to build a script using expect. Need a help from an expert who has already done it.
Regards,
Vinod (1 Reply)