Shell Script for remote Middleware


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script for remote Middleware
# 1  
Old 02-21-2011
Lightbulb Shell Script for remote Middleware

Hi Experts, Smilie

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.


Code:
#!/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 ##

Last edited by pludi; 02-21-2011 at 06:56 AM..
# 2  
Old 02-21-2011
How about something like this:

Code:
{ 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.
# 3  
Old 02-22-2011
This is what I have now and it won't stay in the apps/middleware prompt

Code:
#!/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


Last edited by Scott; 02-22-2011 at 07:09 PM.. Reason: Please use code tags
# 4  
Old 02-22-2011
Of course it won't you need the read and echo piped into ssh like this:

Code:
#!/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

# 5  
Old 02-22-2011
Nope still not working
Code:
./test-script[25]: 0403-057 Syntax error at line 30 : `while' is not expected.


Last edited by Scott; 02-22-2011 at 07:10 PM..
# 6  
Old 02-22-2011
OK AIX dosn't support -p on read, [[ test or decimal sleep args. This should work for you now:

Code:
#!/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

# 7  
Old 02-23-2011
sorry tell you it's still not - its freezing my terminal my tty - I have to quit and login again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies

2. Shell Programming and Scripting

Shell script for remote servers

Hi , I have written a small script : set -x #!/bin/ksh for i in `cat /tmp/list` ( list contains remove servers ) do ssh -t $i << EOF uname -a cd ~user echo "Enter the dir >" read dir path=`ll -ld /home/user/"$dir"` if ; then echo "Dir exists " read rm $path else echo "no such... (9 Replies)
Discussion started by: kpatel786
9 Replies

3. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

4. Shell Programming and Scripting

Triggering remote UNIX shell script from Remote desktop

I m trying to run a batch script in remote desktop which executes unix commands on the unix server...the problem is i wnt the output in HTML format.so in my batch script i m giving the cmd like ssh hostname path ksh HC_Report.ksh>out.html ...but it generates the HTML file in remote desktop .i... (2 Replies)
Discussion started by: navsan
2 Replies

5. Programming

Expect script to run a Shell script on remote server

Hi All, I am using a expect script to run a shell script on remote server, the code is as follows. But the problem is that it executes only first command, and hangs it doesn't run the next commands. spawn ssh $uid@$host expect "password:" send "$password\r" expect "*\r" send... (2 Replies)
Discussion started by: yashwanthsn
2 Replies

6. Shell Programming and Scripting

Run Shell Script on Remote System

I honestly tried searching for this in this forum and in google. Maybe I found the answer but didn't even realized it. I would like to run shell script thats on my machine that collects the hostname and IP address from the remote system and sends the output to my machine. I'm not sure if need... (2 Replies)
Discussion started by: elbombillo
2 Replies

7. Shell Programming and Scripting

Getting remote data through shell script

Hi, I need to get the details (File System status & Memory status) of a remote server. I am executing a shell script in ksh and preparing the report. Pls help. Regards, armohans. (1 Reply)
Discussion started by: armohans
1 Replies

8. Shell Programming and Scripting

Script using rsh(remote shell)

Hi, I am writing a script that will require me to perform tasks across servers. I tried to use rsh <host> "Commands..." > /dev/null 2>&1. However, I am required to execute a long series of commands after that and rsh does not seem to support this and its also insecure. I tried to use rsh to... (5 Replies)
Discussion started by: joseph_ng
5 Replies

9. Shell Programming and Scripting

remote-login via Shell-Script

Hello all, I would like to login from one unix-system with a (tcsh)-script to an other unix-system.The login-procedure and the transmission of username, resp. password runs via ssh. The problem is after logging onto the remote server once "Enter" has to be pressed, before one gets to the... (1 Reply)
Discussion started by: Juergen Paepke
1 Replies

10. UNIX for Dummies Questions & Answers

remote login via shell script

is it possible for me to have a shell script log me in to a telnet session? i have in mind something along the lines of % telnet host < script, where the first two lines of script will be username and pass followed by a list of commands to execute on the remote host. this doesn t work as... (4 Replies)
Discussion started by: lethe
4 Replies
Login or Register to Ask a Question