Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

Rep: Reputation: 0
script detecting ssh password request


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.

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

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
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:

i you can see that or not... timed out many times for me. if not his code looks like this:


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
if [ "${buffer:(-${#expect}):${#expect}}" = "$expect" ]; then
echo -en "$send" 1>&3
return 0;

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 ;-)


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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:47 PM.

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