The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how do i get current bandwidth usage via shell script? scarfake Shell Programming and Scripting 2 05-25-2008 10:27 PM
using shell script to telnet ricky katix SUN Solaris 6 01-16-2008 02:27 PM
telnet shell script on red hat 9 cmd line only kypeswith Shell Programming and Scripting 3 10-14-2007 04:22 PM
shell script extended usage... joerg535 UNIX for Dummies Questions & Answers 1 08-24-2007 10:02 AM
telnet & su in shell script vastare Shell Programming and Scripting 1 01-19-2006 11:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2008
a1_win a1_win is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 33
usage of telnet in shell script

Hi All,

How could I use telnet to connect to Primary Host in the below shell script:

Could I use:

(
echo user
sleep 2
echo password
sleep 2
echo "ls ~"
sleep 2
echo "exit"
) | telnet hostname


#-----------------------------------------------------------------------------
# Use SQL*Plus to query the MAX(SEQUENCE#) from both databases V$LOG_HISTORY
# view. If the STANDBY appears to be falling behind, then send alert mail..
#-----------------------------------------------------------------------------


OutFile=/tmp/stdby_chk_$$.out
sqlplus -s /nolog << __EOF__ > ${OutFile} 2>&1
whenever oserror exit 99
connect / as sysdba
set verify off

whenever sqlerror exit 6
col logseq_on_standby new_value V_STDBY_LOGSEQ
select /*+ rule */ max(h.sequence#) logseq_on_standby
from v\$log_history h,
v\$parameter p
where h.thread# = to_number(decode(p.value,'0',1,p.value))
and p.name = 'thread';

col filecnt new_value V_STDBY_FILECNT
select count(*) filecnt
from v\$datafile;

whenever sqlerror exit 7
connect ${_PriUnPwd}

whenever sqlerror exit 8
col logseq_on_primary new_value V_PRIMARY_LOGSEQ
select /*+ rule */ max(h.sequence#) logseq_on_primary
from sys.v_\$log_history h,
sys.v_\$parameter p
where h.thread# = to_number(decode(p.value,'0',1,p.value))
and p.name = 'thread';

col filecnt new_value V_PRIMARY_FILECNT
select count(*) filecnt
from v\$datafile;

whenever sqlerror exit 9
begin
if &&V_STDBY_LOGSEQ < &&V_PRIMARY_LOGSEQ - 2 then
--
if &&V_PRIMARY_FILECNT > &&V_STDBY_FILECNT then
--
raise_application_error(-20001,
'${_StdbyOraSid} is falling behind; datafile(s) were added to PRIMARY');
--
elsif &&V_PRIMARY_FILECNT < &&V_STDBY_FILECNT then
--
raise_application_error(-20002,
'${_StdbyOraSid} is falling behind; datafile(s) were dropped from PRIMARY');
--
else
--
raise_application_error(-20000,
'${_StdbyOraSid} is falling behind.');
--
end if;
--
end if;
end;
/
exit success
__EOF__
#
#-----------------------------------------------------------------------------
# Based on error code from SQL*Plus, compose an error message...
#-----------------------------------------------------------------------------
integer _Rtn=$?
case ${_Rtn} in
0) rm -f ${OutFile} ;; # ...everything is OK!
6) _Echo failure "Query of V\$LOG_HISTORY on STANDBY failed\n\n`cat ${OutFile}`\n" ;;
7) _Echo failure "unable to connect to PRIMARY" ;;
8) _Echo failure "Query of V\$LOG_HISTORY on PRIMARY failed\n\n`cat ${OutFile}`\n" ;;
9) _Echo failure "STANDBY is falling behind PRIMARY\n\n`cat ${OutFile}`\n" ;;
*) _Echo failure "SQL*Plus failed\n\n`cat ${OutFile}`\n" ;;
esac
rm -f ${OutFile}
#
#-----------------------------------------------------------------------------
# Done!
#-----------------------------------------------------------------------------
exit 0

Thanks for your time!

Regards,
  #2 (permalink)  
Old 10-21-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,516
do you have other programming tools, eg Perl,Python, SSH2 etc? these tools provide you better control over the "telnet" protocol and i suggest you use them if possible.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0