LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-02-2006, 03:25 PM   #1
jp9999
LQ Newbie
 
Registered: May 2006
Posts: 1

Rep: Reputation: 0
script detecting ssh password request


hi,

i've been thinking about this for a few days now, and cant find the way to do this.


We're using an api to copy files to the target servers.

We have public key is on the servers, but sometimes (due to overload, unstable ssh version, or whatever) we get "connection refused". If we keep trying, it will eventually work. Also, for the users that don't have the key, i would like to display some error message. So basically, we have a web page to do some stuff, but if in the backgroup we get "connection refused" or the "password" question, i would like to be able to detect that.

I don't want to install expect. Is there a simple way to catch that filehandler (fh 4)?

The only way i've thought of so far is to spawn in the background another process that ssh to the servers, wait a second or so, and look if that process is still there. If it is, it means it was asked for a password. Thats not very elegant tho.

sorry for my poor english/communication.

jp
 
Old 05-02-2006, 03:46 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
I'm afraid i have to take you to task on saying that you don't want to install expect. expect it *THE* absolutely obviously and perfect solution to do what you want to do, why won't you use it??

that said... google truns up someones attempt to implement expect purely in bash: http://66.249.93.104/search?q=cache:...implementation

i you can see that or not... timed out many times for me. if not his code looks like this:
Code:
#!/bin/bash

timeout=600

expect() {
local expect="`echo -en $1`" send="$2"
local delim="${expect:(-1):1}"
local buffer="" block=""
while read -u3 -r -t$timeout -d "$delim" block; do
buffer="$buffer$block$delim"
if [ "${buffer:(-${#expect}):${#expect}}" = "$expect" ]; then
echo -en "$send" 1>&3
return 0;
fi
done
}

exec 3<>/dev/tcp/localhost/9999
expect "\377" "guest\n"
expect "Enter name:" "testing\n"
expect "Enter blurb:" "testing2\n"
if you can get that working... also perl has it's own implementation of expect so you could use that maybe.

why apologise for your english? it's better than most americans ;-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
avoid been ask password by ssh with script? Chowroc Programming 6 02-14-2006 06:17 AM
how to stop password request to connect to network webazoid Mandriva 1 12-23-2005 11:49 AM
script request lgualteri Programming 7 06-17-2005 11:19 AM
ssh server request k1ll3r_x Linux - Networking 4 04-20-2005 04:27 PM
Insufficient Privilege instead of Root Password Request buckberger Linux - Security 3 12-25-2004 09:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration