LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2009, 11:34 PM   #1
user99099099
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Rep: Reputation: 0
Bash Scripting - Reading Konsole Response / Output


Hi,

I'm throwing together a small bash script that automates connecting to a
number of servers through SSH and would like to add an extra layer of
verification just for peace of mind.

Right now everything's stored in my .ssh/known_hosts file but just to be
safe, I want to have the script check for a prompt.

For example, if I do "ssh server_name" I would like the script to read in
the response / output of that command to see if it says "Are you sure you
want to continue connecting (yes/no)?" or if it says "[user@server ~]$".
Dependent upon the response, I could have an if statement evaluate it and
send the proper response whether it be "yes" or a sudo command.

Thanks in advance.
 
Old 01-22-2009, 02:18 AM   #2
rizwanrafique
Member
 
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

Rep: Reputation: 19
You could write a small script that does something like:
Code:
#!/bin/bash

echo "Readlly?"
read choice

if [ $choice == "Y" ]; then
    /usr/bin/ssh $1
fi
Let's say you call it /home/rizwan/tmp/my_ssh.

Do:
Code:
alias ssh='/home/rizwan/tmp/my_ssh'
And you should be ok. You can further enhance my_ssh by sending all its parameters to the real ssh command.

Probably there are better ways but I would do that :-)
 
Old 01-22-2009, 04:52 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, I think the OP wants to check the output of the ssh cmd to see he gets the 'host key has changed, could be a MITM attack.... continue...' etc msg.
In which case, I'd suggest using Perl Net::Ssh module http://search.cpan.org/~ivan/Net-SSH-0.09/SSH.pm or Net::SSH::Perl.
Other options inc IPC::Open2, IPC::Open3
 
Old 01-22-2009, 11:12 PM   #4
user99099099
LQ Newbie
 
Registered: Nov 2005
Posts: 8

Original Poster
Rep: Reputation: 0
Yes chrism01, you're correct. That's what I was going for. I'll check into the Perl solution. I've never done any Perl development but now wouldn't be a bad time to learn. Thanks.

Last edited by user99099099; 01-22-2009 at 11:16 PM.
 
Old 01-23-2009, 04:32 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, here's a couple of links:
http://perldoc.perl.org/ - lang docs, examples, tutorials
http://www.perlmonks.org/?node=Tutorials - more tutorials
 
  


Reply



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
Bash Scripting: Redirect output of entire script to file & screen Kristijan Programming 3 10-12-2017 03:17 PM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
How to get the contents of a konsole session for scripting? scobiej Linux - Desktop 3 09-19-2008 07:03 AM
Bash Scripting POSIX Class [[:alnum:]] giving wrong output livetoday Linux - Newbie 3 01-21-2008 11:56 PM
Slow konsole response taarnak Linux - General 2 12-16-2003 05:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:50 PM.

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
Open Source Consulting | Domain Registration