ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Unfortunately I have to enter the device's pwd for each scp/ssh call.
Is there a way to read the pwd ONCE via script and then distributing it via $devpwd ???
Yes, I know about key authentication, and, no, there is no way using this :-( All I found are well-meant ideas how to install key authentication. Yes, I know about possible security risks and, no, I do NOT want to store pwds in files ;-)
Any ideas how I can avoid entering the pwd again and again?
TIA,
Heinz
I like the above idea, but given that the OP says he/she doesn't want to use key authentication, I think it would be a good job for `expect`.
Since I'm not good at writing `expect` scripts from scratch, if it were me I would use `autoexpect` to generate a working `expect` script that logs into one device and performs the needed tasks; then I would expand the script (mostly just copy & paste) to make it repeat the operations for the remaining machines.
Assuming the password is the same for all machines (hence the name "master password") you would just need to input the password one time to the script, and the script would re-use it to log into the second and subsequent machines.
If OP wants to investigate this route, check the manpage for `autoexpect` (and for `expect` also) - it's pretty complete as manpages go, and should give you an idea if it's the tool for this job.
What I've been searching for is the possibility to do the exact same procedure to a set of IP devices, e.g. reconfiguring by changing a config file and restarting a deamon, uploading a new flash image and calling an internal reflash procedure, ...
With a little help I got this, I've stripped all unneeded for better understanding what I did:
I thougt it WOULD work like a charm, but only the first part did. The second failed, I've tricked myself by switching between two configs for testing... :-(. The command passed along ssh had never been executed.
But when I' echoing the ssh line to console ( using expect's -d parameter), and execiting it from the prompt it does exact what I'm expecting :-s
And this one is nagging cause of a pile of lines after successful login before the prompt appears.
The "most pretty" way for me would be to get the first attempt running; but, if second would make it - is there a simple possibility to "loop" thru an unknown number of incoming lines, just waiting/watching for the prompt?
BTW, I've used the notation given above cause doing it this way it's much easier using $variable from script without chinning the bar.
First I've forgotten to add a "\n" at the end of my command strings, and second the prompt isn't "dev>" but "dev> " - which of course has never been found due to the trailing space... :-%
Add'lly I've changed the syntax a little bit, still using embedded expect code in the bash script (due to much easier access to script variables.
Code:
/usr/bin/expect - << EndMark
...
...
...
EndMark
This gives me the benefit to be able to use standard "..." string notation for send and expect which was a debacle in the previous version, too.
The thread is some months old - I wonder about the OP's statement not to use an ssh-key. A passphrase protected ssh-key can be added to the ssh-agent at the start, and removed again when you are done.
Yes key exchange is the best way, but this is not always possible as everyone logging on needs to have a key setup, so this is a alternative without storing the password in a script (and assumes all the servers have the same password).
Updated code above to add a sleep 1 after expect 100% . This is because the file transfer was being ended before all the file had actually transferred, therefore the 100% is being displayed prematurely (probably milliseconds).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.