Shell script using ssh remains connected at primary site


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script using ssh remains connected at primary site
# 1  
Old 10-23-2008
Shell script using ssh remains connected at primary site

Hi All,

OS:AIX 5.3 L

My shell script using ssh remains connected at primary site and ssh doesn't get disconnected.What should be typed and where in the shell script below to do it.

Shell script
========

#!/usr/bin/ksh

v_standby=`sqlplus -s /nolog <<END
@standby.sql
END`
echo $v_standby

ssh abc@hostname.domain
v_primary=`sqlplus -s /nolog <<END
@primary.sql
END`
echo $v_primary
if [ $v_standby < $v_primary - 2 ]
then
mailx -s "Standby lagging behind;" xyz@yahoo.com
fi


primary.sql
===========


set lines 500 pages 500
set verify off
set head off
connect / as sysdba
select /*+ rule */ max(h.sequence#) logseq_on_primary
from v$log_history h,
v$parameter p
where h.thread# = to_number(decode(p.value,'0',1,p.value))
and p.name = 'thread';
exit;


standby.sql
===========

set lines 500 pages 500
set verify off
set head off
connect / as sysdba
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';
EXIT;
# 2  
Old 10-23-2008
Hello. What are you trying to do exactly? If there's an enter after your ssh statement, then it's normal it stays connected:

Code:
ssh abc@hostname.domain

That just makes a connection to hostname.domain and leaves the session open. The syntax to execute a command remotely is:

Code:
ssh user@hostname command

I'm not 100% sure what you are trying to do, but you probably want:

Code:
#!/usr/bin/ksh

v_standby=`echo @primary.sql | sqlplus -s /nolog`
echo $v_standby

v_primary=`ssh abc@hostname.domain "echo @primary.sql | sqlplus -s /nolog"`
echo $v_primary
if [ $v_standby < $v_primary - 2 ]
then
mailx -s "Standby lagging behind;" xyz@yahoo.com
fi

But then the file primary.sql will need to exist on the primary server.
# 3  
Old 10-24-2008
Shell script using ssh remains connected at primary site

Hi vimes,

I am getting this error while running the script:

498
ksh: sqlplus: not found.

./stdby_check1.sh[8]: -: 0403-012 A test command parameter is not valid.

Now what should be looked into it for the fix..

-Amit
# 4  
Old 10-24-2008
Hello,

I advise you read man test. It will help you a lot.

The error on line 8 is because your if statement is not valid.
You can't do the -2 inside the if statement. Also to check numbers you use -lt (less than). It's also explained in the man page. So you could do something like this:

Code:
v_primary = `expr $v_primary - 2`
if [ $v_standby -lt $v_primary ]
then
mailx -s "Standby lagging behind;" xyz@yahoo.com
fi

Expr is used to evaluate our values as expressions, so we can do some math with it. See man expr.

Now for the other error (sqlplus: not found.), you should be able to figure that out. It means your script can't find where sqlplus is. Locate the sqlplus binary on your system (use find or which) and add the full path in your script every time you call sqlplus). Good luck Smilie

Last edited by vimes; 10-24-2008 at 06:44 AM.. Reason: Code fix
# 5  
Old 10-24-2008
it is long time ago when i was forced to use aix .. bash has these days option -s that allows you to send you code from stdin. that can be used to keep you code on computer A while it is executed on B.
example:
echo "/usr/bin/date" | ssh user@remote "/bin/bash -s"

now replace "echo date" with cat <<EOF my complicated suff and you can keep you code on one computer alone.
# 6  
Old 10-27-2008
Shell script using ssh remains connected at primary site

Hi All,

I am using the below shell script the objective is:

Objective:
========

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 through the below shell script:

How could I connect to the primary database in the below shell script using SSH?

#-----------------------------------------------------------------------------
# Use SQL*Plus to query the MAX(SEQUENCE#) from both databases V$LOG_HISTORY view. If the STANDBY appears to be falling behind, 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__


Anyone could help would be appreciated!!

Thanks for your time!

Regards,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris 8: Multiple primary interfaces connected to the same network

Hello, I have a machine with Solaris 8, and it has multiple interfaces that are connected to the same network which means they all have metric 0 (1 hop) to the default gateway. assume: * e1000g0: 10.1.1.70 * e1000g2: 10.1.1.72 * e1000g4: 10.1.1.74 * e1000g5: 10.1.1.76 * gateway:... (11 Replies)
Discussion started by: aeg
11 Replies

2. Shell Programming and Scripting

echo to connected ssh clients

Hello, i have a network device that users connect to using ssh. I have a script that connects to the device and has to echo something to other connected people. How can this be established? ssh user@device 'echo Hello > /dev/console' doesn't seem to do the trick. (2 Replies)
Discussion started by: trafo23
2 Replies

3. Shell Programming and Scripting

Shell script to display user logged last week and time connected

Hello all, I want to display all the user logged last week and know the time tnat they are connected. I have been looking for a solution in the Forum, but I didn't find. Thanks in advance (4 Replies)
Discussion started by: ahernandez
4 Replies

4. Shell Programming and Scripting

d. Write a shell script to count the number of accounts which belong to particular primary

guys, I am new shelll scripting.. this a question on passt exam paper, I was trying to solve it , I can not. the question is as follow? a. Write a shell script to count the number of accounts which belong to particular primary group in a standard UNIX system which uses local... (1 Reply)
Discussion started by: gurmad
1 Replies

5. UNIX for Advanced & Expert Users

How to export ENV variables, which remains set for all the shell

Hi ! How to export ENV variables, which remains set for all the shell Example :- Login :myID Pwd : **** -> Here my ID .profile is executed. Let say I set MYENV variable Kisses% rlogin ABC -l XXXGroupID -> I login into a remote Solaris Server ABC password : **** -> "XXXGroupID's... (1 Reply)
Discussion started by: dashok.83
1 Replies

6. UNIX for Dummies Questions & Answers

Closing console connected to another machine via ssh

Hi, I have ssh'd into a UNIX server at work from my linux desktop and executed a tar command to backup up some directories to a tape drive. I was wondering would the tar command still execute to completion if I closed my terminal console on my desktop that is connected to the server, would the... (1 Reply)
Discussion started by: mojoman
1 Replies

7. Shell Programming and Scripting

shell script for primary and standby DB archive log check

Hi All, OS:AIX 5.3 64 bits I would like the below script to send alert mail with the message - "Standby logs falling behind Primary" to xyz@yahoo.com Script ===== #!/usr/bin/ksh #----------------------------------------------------------------------------- # Use SQL*Plus to query... (1 Reply)
Discussion started by: a1_win
1 Replies

8. Shell Programming and Scripting

How to use SSH to connect to Primary DB and send alert mail

Hi All, AIX 5.3 64 bit: I am using the below shell script the objective is: Objective: ======== 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 through the below shell script: How... (0 Replies)
Discussion started by: a1_win
0 Replies

9. Shell Programming and Scripting

shell script not connecting to primary from standby site

Hi All, I am using below shell script using SQL*Plus to query the MAX(SEQUENCE#) from both databases V$LOG_HISTORY view.If the STANDBY appears to be falling behind by - 2, then alert mail should be sent... How could I achieve it with improving the below script. #!/usr/bin/ksh ... (0 Replies)
Discussion started by: a1_win
0 Replies

10. Shell Programming and Scripting

Shell script process remains after "exit 1"

I have a script that performs an oracle export: <snip> if then exp / full=y file=${exp_file} log=${exp_log} direct=y feedback=1000000 STATISTICS=NONE buffer=20000000 else exp / full=n owner=${schema_name} file=${exp_file} log=${exp_log} direct=y feedback=1000000... (4 Replies)
Discussion started by: Squeakygoose
4 Replies
Login or Register to Ask a Question