Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to 4 different boxes using status successful

Status
Not open for further replies.

12bpm

Programmer
Apr 8, 2008
8
IE
check_lagtime()

rshstatus=`rsh -n lilo /db/p2/oracle/names9208/restart_names.sh`
if $rshstatus <>0 then
errstatus=1
mailx -s "xirsol8dr" ordba@xilinx.com >> $log_dr
else if errstatus=0
echo "status to xirsol8dr successful"

this is the logic behind what im looking to do
i want to be able to connect to each box and check if successful or not with error status and send mail with log to dba if not successful.
 
Something along the lines of
Code:
#!/bin/ksh
for host in box1 box2 box3 box4
do
  if [ $(rsh -n $host /db/p2/oracle/names9208/restart_names.sh) -ne 0 ]
  then
    mailx -s "xirsol8dr" ordba@xilinx.com >> $log_dr
  else
    echo "status to xirsol8dr successful"
  fi
done
but I don't understand your mailx line so maybe
Code:
#!/bin/ksh
for host in box1 box2 box3 box4
do
  if [ $(rsh -n $host /db/p2/oracle/names9208/restart_names.sh) -ne 0 ]
  then
    echo $host is broken | mailx -s "xirsol8dr" ordba@xilinx.com 
  else
    echo "status to xirsol8dr successful"
  fi
done



On the internet no one knows you're a dog

Columb Healy
 
hi

thank you for your help
however i need to cat the host names into a logfile
does the below script seem appropriate?

script=call_dr_scripts_central.ksh
dr_status=0
log_dr=/tools/xirdba/dr/bin/call_dr_scripts_central.log
touch $log_dr

for host in `cat /tools/xirdba/dr/bin/drhosts`
do
if [ $(rsh -n $host /tools/xirdba/dr/bin/standby_delay_report.ksh) -ne 0 ]
then
echo $host is broken >> $log_dr
else
drstatus=1
echo "failed to call $script for $host" >> $log_dr
fi
done



when i run this script above, i get the follwing error in the log

cat call_dr_scripts_central.log
failed to call call_dr_scripts_central.ksh for xirsol8dr
failed to call call_dr_scripts_central.ksh for xirmesd1
 
Hmm...

This line
Code:
  if [ $(rsh -n $host /tools/xirdba/dr/bin/standby_delay_report.ksh) -ne 0 ]
assumes that the /tools/xirdba/dr/bin/standby_delay_report.ksh script returns 0 to stdout on success and non zero on failure. If you're testing the return code then try
Code:
for host in `cat /tools/xirdba/dr/bin/drhosts`
do
  if rsh -n $host /tools/xirdba/dr/bin/standby_delay_report.ksh
  then
     echo $host is working >> $log_dr
   else
   drstatus=1
   echo "failed to call $script for $host" >> $log_dr
 fi
done


On the internet no one knows you're a dog

Columb Healy
 
hi
you have been a great help to me.
i want to be able to loop through each of the four hosts and check rsh connection status by
searching hostname,rsh/shh or physical/virtual using the awk command from below file


cat drhosts
-------------------------
xirslo8dr rsh physical
xirmesd1-dr1 ssh physical
xirdrhp3 rsh virtual
xirdrhp4 rsh virtual
----------------------------------

script=call_dr_scripts_central.ksh
dr_status=0
log_dr=/tools/xirdba/dr/bin/call_dr_scripts_central.log
touch $log_dr
physical=/tools/xirdba/dr/bin/standby_delay_report.ksh
virtual=/tools/xirdba/dr/bin/dr_call_cron_wrapper.ksh /tools/xirdba/dr/bin/standby_delay_report.ksh

cat /tools/xirdba/dr/bin/drhosts | while read line
if [ "`echo $LINE | awk -F: '{print $1}' -`" = "physical" ] and rsh ; then .........................

have you any ideas for how i could do this.

thanks again



 
Depending on your IFS setting (the default should be any white space) then
Code:
while read host protocol type
do
  if $protocol -n $host /tools/xirdba/dr/bin/standby_delay_report.ksh
  then
   then
     echo $host is working >> $log_dr
   else
   drstatus=1
   echo "failed to call $script for $host" >> $log_dr
 fi
done < /tools/xirdba/dr/bin/drhosts
This assumes that rsh and ssh work identically (i.e. the -n flag has the same effect). I've no idea what difference the physical/virtual duality makes

Noe also the use of the redirect instead of using cat. There are those who will start flame wars over UUOC (useless use of cat):)

On the internet no one knows you're a dog

Columb Healy
 
hi

what is protocol in reference to?
i dont understand how what you have given me a solution as to hows i can pull fields from the drhosts file.
there are 4 hosts
you can rsh or ssh on to them
some of them have physical location Eg: /tools/xirdba/dr/bin/standby_delay_report.ksh
others have virtual with wrapper like
/tools/xirdba/dr/bin/dr_call_cron_wrapper.ksh /tools/xirdba/dr/bin/standby_delay_report.ksh

i want to do the same as above but i need ot use the awk command in order to check status connection on hosts depending on what is in the drhosts file.

does this make sense?
thanks

 
Experiment with
Code:
while read host protocol type
do
  echo host is $host - protocol is $protocol - type is $type
done < /tools/xirdba/dr/bin/drhosts
As you will see we're parsing the drhosts file using read. If this doesn't work then we ma have to play with IFS

Given this
Code:
while read host protocol type
do
  # set remote command depending on type
  if [ $type = physical ] 
  then
    cmd=/tools/xirdba/dr/bin/standby_delay_report.ksh
  else
    cmd="/tools/xirdba/dr/bin/dr_call_cron_wrapper.ksh /tools/xirdba/dr/bin/standby_delay_report.ksh"
  fi
  
  # set remote shell depending on protocol
  if [ $protocol = ssh ]
  then
    myrsh="ssh -n"
  else
    myrsh="rsh -n"
  fi

  # Run the test  
  if $myrsh $host "$cmd"
  then
     echo $host is working >> $log_dr
  else
   drstatus=1
   echo "failed to call $script for $host" >> $log_dr
  fi
done < /tools/xirdba/dr/bin/drhosts

Note that for both the protocol and type tests typos may give a poor result. More bullet proof is
Code:
while read host protocol type
do
  # set remote command depending on type
  case $type in
    physical)
      cmd=/tools/xirdba/dr/bin/standby_delay_report.ksh;;
    virtual)
      cmd="/tools/xirdba/dr/bin/dr_call_cron_wrapper.ksh /tools/xirdba/dr/bin/standby_delay_report.ksh";;
    *) echo bad input file
       exit;;
  esac
  
  # set remote shell depending on protocol
  case $protocol in
    ssh) myrsh="ssh -n";;
    rsh) myrsh="rsh -n";;
    *) echo bad input file
       exit;;
  esac

  # Run the test  
  if $myrsh $host "$cmd"
  then
     echo $host is working >> $log_dr
  else
   drstatus=1
   echo "failed to call $script for $host" >> $log_dr
  fi
done < /tools/xirdba/dr/bin/drhosts

On the internet no one knows you're a dog

Columb Healy
 
hey

thank you so much for your time and effort in doing this script.
i wish i could get a few hours with you to go over some unix as im new to it.
But as this is only a unix forum, you have been more than helpful.
The script worked fine and returned all dr hosts successful.

+ echo xirdrhp4 is working
+ 1>> /tools/xirdba/dr/bin/call_dr_scripts_central.log
+ read host protocol type


thanks again columb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top