usage of telnet in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usage of telnet in shell script
# 1  
Old 10-21-2008
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  
Old 10-21-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Basic sed usage in shell script

Hi, A basic sed question. I have a set of files. In each file there is a number that I want replaced. For example, if I run sed I should get the following: % cat test2.txt #goofy//171.00 goofy 171.00 % sed -i 's/171/xxx/g' test2.txt % cat test2.txt #goofy//xxx.00 goofy xxx.00 ... (2 Replies)
Discussion started by: pc2001
2 Replies

2. Shell Programming and Scripting

Need shell script for SMS via telnet command

I am not very much familiar with telnet based scripting so I would need your help to directly submitting sms as deliver_sm or submit_sm msg to SMSC (IP & system_id and password are already known). So, need your help to provide such script. I previously used such script but my harddisk crashed and... (1 Reply)
Discussion started by: wasay
1 Replies

3. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

4. Shell Programming and Scripting

Using telnet in my shell script

Hello Guys, I have a linux server where I already logged in, once logged in, i telnet to local host using some dedicated port and do some action. This I can easily do manually. Since I need to fire a lot requests so I would like to optimize it using a shell script to avoid telnetting each... (3 Replies)
Discussion started by: umarsatti
3 Replies

5. Shell Programming and Scripting

Need help to make a shell script with usage

Hello, I begin to write my first shell script, but I am totally lost, hope you can help me. I'd like to write a script with some conditions and multiples usages: ./myscript.sh -i <host> or ./myscript.sh -e <host> Have you some suggestion, because I am really lost, I try to do something... (12 Replies)
Discussion started by: Francesco
12 Replies

6. Shell Programming and Scripting

Pattern extraction and usage by shell script

Suppose im in a directory A. which has sub-directories x/y/z m/n/p etc. Iam only considered with those which have a file netl.oa at the lowermost level. So i used the find command which gives me a list in the form ./abc/def/ghi/jkl/netl.oa and so on Now i want the names abc def jkl and ghi. My... (3 Replies)
Discussion started by: sid.verycool
3 Replies

7. Shell Programming and Scripting

Telnet using shell script

Hi I need to telnet a device with IP Address and port. After logging in, I need to execute some commands in that device. Please find the example below telnet 170.10.11.1 2100 #170.10.11.1 is the IP address. 2100 is the Port after telnet, the device will show the command prompt as : ... (2 Replies)
Discussion started by: sudharsan23
2 Replies

8. Solaris

using shell script to telnet

I would like to log into a server read a certain file and get the results back. I have tried like below to no avail; #!/bin/ksh -x ( sleep 2 echo sdpuser sleep 2 echo cs3reloaded sleep 5 cd /export/home/scripts/daily_checks sleep 5 head daily_check_report.txt > test160108.txt exit )... (6 Replies)
Discussion started by: ricky katix
6 Replies

9. UNIX for Dummies Questions & Answers

shell script extended usage...

Hi all, In a shell script, how can I do the following: Find out the size of a mounted usb stick (df -h /media/usbdisk) and use the result (physical size of USB stick) to set a loop-counter according to the disk size?? As a result, I do copy files of 4MB each as many times as they will fit... (1 Reply)
Discussion started by: joerg535
1 Replies

10. Shell Programming and Scripting

telnet & su in shell script

Hi, Any scripting experts out there that can point me to the right direction of writing a script using telnet and su to access a server without any users interaction such as login and entering passwd. Thanks. Thanks in advance vastare (1 Reply)
Discussion started by: vastare
1 Replies
Login or Register to Ask a Question