KSH scripting question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH scripting question
# 1  
Old 01-27-2006
KSH scripting question

Good day,

I am trying to write a script that completes an ssh challenge to a specific server and writes output to a log. We have shared ssh keys for the script user. My challenge is a simple hostname check;

ssh $host hostname

My problem arrises when there is an actual challenge, be it asking me for a password, or to update the known_host keys. This is going to be ran from cron and wont have anyone monitoring to answer these questions. When there is a challenge, I want to script to write it to a log and send someone an email. This is where my scripting knowledge comes to a complete halt.

I can not figure out how to take the output from the ssh challenge and use it in my script, for instance;

ssh $host hostname > $fileout2 2>&1
target=`cat $fileout2`
if [ "$host" = "$target" ] ; then
echo "... no challenge from $target" >> $fileout 2>&1
else
echo "... challenge from $host FAILED!!, please check SSH keys" >> $fileout 2>&1

When I am challenged lets say for a password, it never leaves the ssh call thus never gets to the if statement logic. This is where I need some assistance. How can I use the output or ignore the output all together ? If I can ignore it, and force the script to proceed, the if statement will fail and we will be notified. I know there are tools out there like "Expect" but these are production servers and adding tools like that are laborsom to get through all the politics.

Does anyone have a suggestion for me ? Ive searched the web for the past two days, done tons of reading and havent come up with a solution that works.

Thank you, I really appreciate any asistance anyone can give me.


Here is the script in its entirety.

#!/bin/ksh
# Script created to test the SSH functionality between host1, host2,
# host3 and dev_test1, and dev_test2. This functionality is in place for
# Oracle refreshes and needs SSH to function unchallenged. The script will
# be executed from the production servers.

# Hosts this server needs to be able to SSH unchallenged
hostlist="dev_test1 dev_test2"

# location of output log
fileout=/export/home/playing/ssh_checker.log
fileout2=/export/home/playing/target.log
thishost=`hostname`
date=`date`
email="someone@someplace.com"

echo "================================================" >> $fileout 2>&1
echo " SSH checker ran on $date from $thishost " >> $fileout 2>&1

for host in $hostlist
do
echo "================================================" >> $fileout 2>&1
echo "Checking $host for SSH challenge ..." >> $fileout 2>&1

ssh $host hostname > $fileout2 2>&1

target=`cat $fileout2`

if [ "$host" = "$target" ] ; then

echo "... no challenge from $target" >> $fileout 2>&1

else

echo "... challenge from $host FAILED!!, please check SSH keys" >> $fileout 2>&1

mailx -s "SSH challenge failed from $thishost to $host, please check SSH Keys" $email < /dev/null

fi

rm $fileout2

done
# 2  
Old 01-27-2006
If you just want to ensure that it works, how about:
rm outputfile
ssh host "uname -a" > outputfile &
pid=$!
sleep 5
and now look at the output file. No output in outputfile to look at? Musta not worked. So "kill $pid" to be sure you don't leave a hanging process and send the error email.
# 3  
Old 01-27-2006
I'll mess around with that idea and post results.

Thanks Perderabo
# 4  
Old 01-30-2006
Thank you Perderabo !

Simply adding a silly 2 second timeout after the ssh call worked for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH scripting

Hi Guys, I am trying to learn to script. first I have 2 server, A and B. A with IP 192.168.82.22. B with IP 192.168.82.44. Both with login user admin and password admin. server A will generate a file every day with name gg.log under /app/gg/20171002.log. I wish to write a script to copy the... (7 Replies)
Discussion started by: leecopper
7 Replies

2. Shell Programming and Scripting

ksh scripting

Hi All, Can you please let me know what I missed in the below function? Whenever I try to execute the script i am getting syntax error at line 101 : `fi' unexpected Function is function DELNWE5O { export ORACLE_HOME=/ora00/app/oracle/product/11.2.0/grid_1 export... (9 Replies)
Discussion started by: pvmanikandan
9 Replies

3. Shell Programming and Scripting

AIX 5.3 ksh Scripting

Hi, I posted a request for sever OS types earlier, but got no response. In an attempt to at least have a starting point, I think scaling it to one OS is preferred. Once I see the gist of it I can modify to account for different cases. I need a script that will go and check to see if an LDAP... (2 Replies)
Discussion started by: tekster2
2 Replies

4. Shell Programming and Scripting

Need a ksh scripting tool

Hi guys, I am new in Unix/linux field. I need a >>tool which is running on windows xp and provide the >>Korn shell scripting environment. As I used cygvin, but it is bash shell and most of the command of unix is not supported by cygwin.:confused: please suggest..... :) thanks in... (9 Replies)
Discussion started by: atul9806
9 Replies

5. Shell Programming and Scripting

Help needed in ksh scripting

I got a task to do today, I want to write a script for the following 1) Archive log more than 2 days old 2) Number of days the current Archive logs present 3) Total number of archive logs 4) Size of each archive log 5) When was last successful backup happened? Can I get a general script... (8 Replies)
Discussion started by: Rambo
8 Replies

6. Shell Programming and Scripting

(ksh) problem with scripting

Hello, I have following problem... I have two shell-scripts. The first one is only a script to add Arrays (working very good). In the second script I want to read the Arrays (also working good). I don't know how to explain it... script: #!/usr/bin/ksh . test.sh ... (14 Replies)
Discussion started by: mon5tar
14 Replies

7. Shell Programming and Scripting

Help with ksh scripting in AIX

I am looking for a script which does the following Script will run daily. 1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts. 2.Then it will compare new snapshot with the snapshot created in the previous run. 3.If filesystem exists in... (20 Replies)
Discussion started by: saidiya
20 Replies

8. Shell Programming and Scripting

ksh scripting help

I have the file as below server1 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server2 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server3 yes dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server4 ... (1 Reply)
Discussion started by: praveenbvarrier
1 Replies

9. Shell Programming and Scripting

Need help with KSH scripting

Hi I need to insert a page break into a file based on matching a phrase in the file. :confused: I am doing this with a ksh script on a Unix box. Any help would be greatly appreciated. Thanks (5 Replies)
Discussion started by: scrappycc
5 Replies

10. Shell Programming and Scripting

KSH Scripting

Will a shell script written in shell for HP/UX run on Solaris? (1 Reply)
Discussion started by: dstaller
1 Replies
Login or Register to Ask a Question