- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting Help
Operating System - HP-UX
1754885
Members
3817
Online
108827
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2004 07:14 AM
тАО05-22-2004 07:14 AM
Oh Gods of the scripting world,
I'm stuck on a simple ksh script I'm writing. The purpose of the
script is to test the ssh connectivity without password prompts
between my database and app servers.
There are others in the company who for some reason mess up the keys,
and I have to regen and propagate new keys to all of the servers. DNS
changes mess things up as well.
Anyway, I need to make sure that when I enter "ssh" I get in
without a passowrd. If it prompts me for a password, the keys are off
and my other scripts will fail.
In the script I run the following (variables changed to constants just
for demo purposes):
# -- Remove temp file just in case
rm -f /tmp/testappserver1.txt 1>/dev/null 2>&1
# -- Test the connection to the file
ssh appserver1 'uname -a' >/tmp/testappserver1.txt 2>/dev/null
# -- If the file exists and is larger than 0 bytes
# -- then connection is good, else connection
# -- didn't work
if [ -s /tmp/testappserver1.txt ]; then
echo "SSH connectivity ok to appserver1"
else
echo "The ssh connection to appserver1 does not work."
fi
# -- Remove temp file
rm -f /tmp/test${1}.txt 1>/dev/null 2>&1
This works great if the keys are set right and will detect an error
when the DNS monkeys at my company changes the underlying IP addresses
without telling us.
But if the keys are off, it justs prompts me for a password. I need
to capture that somehow and say that's an error.
Any ideas?
Thanks in advance, Marly
marly dot thomas at wamu dot net or
marly38 at comcast dot net
I'm stuck on a simple ksh script I'm writing. The purpose of the
script is to test the ssh connectivity without password prompts
between my database and app servers.
There are others in the company who for some reason mess up the keys,
and I have to regen and propagate new keys to all of the servers. DNS
changes mess things up as well.
Anyway, I need to make sure that when I enter "ssh
without a passowrd. If it prompts me for a password, the keys are off
and my other scripts will fail.
In the script I run the following (variables changed to constants just
for demo purposes):
# -- Remove temp file just in case
rm -f /tmp/testappserver1.txt 1>/dev/null 2>&1
# -- Test the connection to the file
ssh appserver1 'uname -a' >/tmp/testappserver1.txt 2>/dev/null
# -- If the file exists and is larger than 0 bytes
# -- then connection is good, else connection
# -- didn't work
if [ -s /tmp/testappserver1.txt ]; then
echo "SSH connectivity ok to appserver1"
else
echo "The ssh connection to appserver1 does not work."
fi
# -- Remove temp file
rm -f /tmp/test${1}.txt 1>/dev/null 2>&1
This works great if the keys are set right and will detect an error
when the DNS monkeys at my company changes the underlying IP addresses
without telling us.
But if the keys are off, it justs prompts me for a password. I need
to capture that somehow and say that's an error.
Any ideas?
Thanks in advance, Marly
marly dot thomas at wamu dot net
marly38 at comcast dot net
LSD and UNIX are both from Berkley - 'nuf said.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2004 06:22 PM
тАО05-22-2004 06:22 PM
Solution
Hi,
You can use the PreferredAuthentications option while doing an ssh to the remote host. For ex.,
ssh -o "PreferredAuthentications publickey" -o "StrictHostKeyChecking no" $host do_something > /dev/null 2>&1
if [ $? = 0 ]
then
echo "$HOST: Successful"
else
echo "$HOST: Unsuccessful"
fi
With "PreferredAuthentications publickey" option, if publickey doesn't work, ssh won't go the keyboard-interactive method and will fail. Also, it is a good idea to use "StrictHostKeyChecking no" it will automatically accept the hostkey for any system that was not trusted before. Otherwise, it will throw an interactive session with a choice of yes\no to select. These two options work with 3.7 version. If you have a different version, look at the man page to find the corresponding options.
-Sri
You can use the PreferredAuthentications option while doing an ssh to the remote host. For ex.,
ssh -o "PreferredAuthentications publickey" -o "StrictHostKeyChecking no" $host do_something > /dev/null 2>&1
if [ $? = 0 ]
then
echo "$HOST: Successful"
else
echo "$HOST: Unsuccessful"
fi
With "PreferredAuthentications publickey" option, if publickey doesn't work, ssh won't go the keyboard-interactive method and will fail. Also, it is a good idea to use "StrictHostKeyChecking no" it will automatically accept the hostkey for any system that was not trusted before. Otherwise, it will throw an interactive session with a choice of yes\no to select. These two options work with 3.7 version. If you have a different version, look at the man page to find the corresponding options.
-Sri
You may be disappointed if you fail, but you are doomed if you don't try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2004 06:33 PM
тАО05-22-2004 06:33 PM
Re: Scripting Help
Thanks Sri - I'll give that a try an let you know!
Marly
Marly
LSD and UNIX are both from Berkley - 'nuf said.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2004 06:45 PM
тАО05-22-2004 06:45 PM
Re: Scripting Help
Sri - that worked great - very eloquent method! 10 points for you bud!
Marly
Marly
LSD and UNIX are both from Berkley - 'nuf said.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP