Shell Script for remote Middleware

Hi Experts, :confused:

I need help in one of my bit complicated script (for me complicated for experts like you might be simple).

I have 100+ Middleware servers and 200+ DB servers and 200+ application servers in my environment. What I�m looking is I have a script ready sitting on one JUMP server I can login using my script to all these middleware servers to its direct prompt by providing authentication. What it does is it will check all the services and any alerts by providing middleware commands in my script which is working perfectly.

What I want want/looking is - I need to stay in the server_auth prompt where I can do/run all the commands/my work and when I have completed my job/work from the server_auth>> prompt when I type exit or quit I should get out from the prompt. Using script how should or can I achieve this please advise.

This is the portion of my script what it goes does its jobs and come out with results from JUMP server.

#!/usr/bin/sh
/bin/clear
 
Node=`hostname`
 
DBpass=abc123
domain=$1
Mailto=$2
 
echo " "
echo " "
print "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "\tChecking for $domain Server and Logs:"
print "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " "
 
ssh $Node su � Admin_User -c "server_auth" << ++ 
DBAdminUsr                      # Admin User ID
`echo $domain`                 # It�s Domain
$DBpass                               # Admin Password 
select $Node                     # I�m selecting the Server name
check_server_status      # Command One
check_server_alert         # Command Two
++

## Ends Here ##

How about something like this:

{ echo ls
  echo "server_auth"
  echo "DBAdminUsr"
  echo $DBpass
  echo "select $Node"
  echo "check_server_status"
  echo "check_server_alert"
  sleep 1.5
  while read -p "${Node}_auth>>" cmd
  do
    [[ $cmd == "quit" ]] && break
    echo $cmd
    sleep 0.5
  done
} | ssh Admin_User@$Node 

Only issue is the prompt may print before previous command has finished, this is because the input routine has no way of knowing when command is done, you can adjust sleep times above to reduce chance of this.

Someone else with expect experience may know of a better way to do this.

#!/usr/bin/sh
/bin/clear

domain=$1
Mailto=$2
echo " "
echo " "
print "\t~~~~~~~~~~~~~~~~~~~~~~"
print "\tChecking for App$domain:"
print "\t~~~~~~~~~~~~~~~~~~~~~~"
echo " "

adminpass=password123

function remote_scp_server {
ssh $Node su - adminuser -c "scpview" << ++
adminuser
`echo $domain`
$adminpass
select $Node
++
}

while read -p "remote_scp_server>>"  cmd
do
[[ $cmd == "" ]] && break
echo $cmd
done

## Ends Here

Of course it won't you need the read and echo piped into ssh like this:

#!/usr/bin/sh
/bin/clear
 
Node=`hostname`
 
DBpass=abc123
domain=$1
Mailto=$2
 
echo " "
echo " "
print "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "\tChecking for $domain Server and Logs:"
print "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " "
 
adminpass=password123
 
{ echo scpview
  echo "adminuser"
  echo "$domain"
  echo $adminpass
  echo "select $Node"
  sleep 1.5
  while read -p "remote_scp_server>>" cmd
  do
    [[ $cmd == "" ]] && break
    echo $cmd
    sleep 0.5
  done
} | ssh $Node su - adminuser
 
## Ends Here

Nope still not working

./test-script[25]: 0403-057 Syntax error at line 30 : `while' is not expected.

OK AIX dosn't support -p on read, [[ test or decimal sleep args. This should work for you now:

#!/usr/bin/sh
/bin/clear
 
Node=`hostname`
 
DBpass=abc123
domain=$1
Mailto=$2
 
echo " "
echo " "
print "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "\tChecking for $domain Server and Logs:"
print "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " "
 
adminpass=password123
 
{ echo scpview
  echo "adminuser"
  echo "$domain"
  echo $adminpass
  echo "select $Node"
  sleep 1
  echo "remote_scp_server>>\c" > /dev/tty
  while read cmd
  do
    [ "Z$cmd" = "Z" ] && break
    echo $cmd
    sleep 1
    echo "remote_scp_server>>\c" > /dev/tty
  done
} | ssh $Node su - adminuser
 
## Ends Here

sorry tell you it's still not - its freezing my terminal my tty - I have to quit and login again.

Rather than using scpview lets try some more standard commands-like ls and echo-first eg:

...
{
    echo "ls | wc -l"
    echo "echo Test command"
    sleep 1
    echo "remote_scp_server>>\c" > /dev/tty
    while read cmd
    do
      [ "Z$cmd" = "Z" ] && break
      echo $cmd
      sleep 1
      echo "remote_scp_server>>\c" > /dev/tty
    done
} | ssh $Node su - adminuser

Is this working, can you type "id" or "ls -l" at the remote_scp_server>> prompt and get output?

Sorry sir - it is not working - its just hangs and wont respond and I have Ctrl+C to quit my putty

wonder if the ssh command is even working, can you just try ssh `hostname` su - adminuser from the comand prompt, to ensure the ssh side is OK.

yes that works from command line good - I came to conclude that this might not work b/c its logging into the middle ware prompt.

Seems to be the case as the script works OK with the systems I've tried it on.

perfect - that means then the middle ware the system I'm on is not allowing - might depends on system to system / env to env :slight_smile:

But, I really appreciate you help here.