How to quit TERADATA qrysessn from a shell script?

Tools & Utilities
Enthusiast

How to quit TERADATA qrysessn from a shell script?

I am writing a shell script that counts the Total and Idle session numbers, so I am using the Query Session tool (qrysessn) and I am calling it inside the shell script using the cnsrun. But I can not find a method to exit or quit or end or abort this qrysessn from inside the shell script.

 

The only way to exit this qrysessn is from cnsterm using the command stop 1 or stop 2 or stop 3 or stop 4 depending on the window qrysessn started in.

 

Any ideas...

 

Here is my script:

 

#!/usr/bin/ksh
# Purpose: To send an Alert when the number of Idle sessions excceed 300 sessions.
#
# Date: 01-Oct-2016
#
# ----------------------------------------------------------------
set -x
LOGDIR=/root/dbascripts/ADMIN/logs/IDLE_sessions_count_`date +%m%y`
LOGFILE=IDLE_sessions_count_`date +%d%m%y_%H-%M`.log

mkdir -p $LOGDIR
/opt/teradata/tdat/pde/15.10.02.06/bin/cnsrun -utility qrysessn -commands "{*} {*} {y}" -force -ok -multi -nostop -log /tmp/idlesessioncount.out -debug 1 > $LOGDIR/$LOGFILE
countidle=`cat /tmp/idlesessioncount.out | grep IDLE | wc -l`
counttotal=`cat /tmp/idlesessioncount.out | grep Session | wc -l`
if [ $countidle -gt 20 ] || [ $counttotal -gt 30 ] ;then
echo "Teradata IDLE sessions count is $countidle and Total sessions count is $counttotal" > $LOGDIR/mail.out
/usr/sbin/sendmail dwhalert@jumpstart.bss.etisalat.eg < $LOGDIR/mail.out
fi

4 REPLIES
rjg
Supporter

Re: How to quit TERADATA qrysessn from a shell script?

Mohamed,

Qrysessn can be closed using quit; from within the utility.

 

Rglass

Enthusiast

Re: How to quit TERADATA qrysessn from a shell script?

Ofcourse I tried this before posting this thread..

I tried it again to show you what happens:

 

This is the code in my script where you can see that I added quit at the end:

/opt/teradata/tdat/pde/15.10.02.06/bin/cnsrun -utility qrysessn -commands '{*} {*} {y} {quit}' -force -ok -multi -nostop -log /tmp/idlesessioncount.out -debug 1

 

Then I went to cnsterm to check where qrysessn was started:

 

Etisalat-1-10:~ # cnsterm 6
Attempting to connect to CNS...Completed.
Hello


Input Supervisor Command:
start ferret

Started 'ferret' in window 2
at Tue Oct 18 13:52:59 2016


Input Supervisor Command:


Input Supervisor Command:


Input Supervisor Command:
start qrysessn

Started 'qrysessn' in window 2
at Tue Oct 18 14:12:49 2016

 

 

 

So after running my script I waited some time and then made sure that it finished..and then i went to stop qrysessn to find it still running:

 

Input Supervisor Command:
> stop 2
stop 2


CNSSUPV 'stop': Screen 2 (qrysessn) is stopped!!
at Tue Oct 18 14:14:40 2016

 

 

 

Also, checking the log file to see if the quit command was run successfully, I found the following:

 

 

========================================================================

Host Session PE DBC User ID
----- -------- ----- -------------------------------
1 13626314 30704 U_TSI

State details : IDLE


========================================================================


End of session state report

 

Please enter a logical host id (? for help):

cnsrun: screen 2 status: Reading
quit

cnsrun: screen 2 status: Running
*** Warning - Illegal characters in the input ignored

 

 

NOTICE: 

There is a Warning message which indicates that the quit command was not executed.

Tags (1)
rjg
Supporter

Re: How to quit TERADATA qrysessn from a shell script?

I only use qrysessn from cnsterm not using a shell script.

Have you tried using the required semi-colon after quit as I posted in original reply.

 

Rglass

Teradata Employee

Re: How to quit TERADATA qrysessn from a shell script?

We need to send a <cr> as the last command (drop the quit string).

 

Example:

node1:~ # cnsrun -utility qrysessn -commands '{*} {*} {y} {quit}' -force -ok -multi -nostop -log /tmp/idlesessioncount.out -debug 1
cnsrun: opened pipe to CNS localhost (fd=file6)
cnsrun: System status is 'Attempting to connect to CNS...'
cnsrun: System status is 'Connecting user root...'
cnsrun: System status is 'Attempting to connect to CNS...completed.'
cnsrun: System status is '1/1 node1 Logons are enabled - Users are logged on'
cnsrun: screen 1 status:
cnsrun: setting window 1 title to 'ferret'
cnsrun: screen 1 status:        
cnsrun: screen 6 status: Reading
DBS State: 1/1 node1 Logons are enabled - Users are logged on
DBS State: 1/1 node1 Logons are enabled - Users are logged on
cnsrun: Idle ready to start qrysessn
start qrysessn

cnsrun: screen 6 status: Running
Started 'qrysessn' in window 1
 at Thu Oct 27 13:32:01 2016

cnsrun: screen 1 status: Running
cnsrun: setting window 1 title to 'qrysessn'
cnsrun: open window: 1
cnsrun: screen 6 status: Reading
cnsrun: clearing screen 1
 

 _______
    |                                |              |
    |    ___     __     ____         |    ____    __|__    ____
    |   /      |/  \    ____|    ____|    ____|     |      ____|
    |   ---    |       /    |   /    |   /    |     |     /    |
    |   \___   |       \____|   \____|   \____|     |__   \____|
 
    Release 15.10.01.05 Version 15.10.01.05
    SESSION STATUS Utility (Dec 94)
 

 Session state Query Utility : 16/10/27  13:32:01

 Please enter a logical host id (? for help):

cnsrun: screen 1 status: Reading
*

cnsrun: screen 1 status: Running

 Please enter session ids (? for help):

cnsrun: screen 1 status: Reading
*

cnsrun: screen 1 status: Running

Is detail information needed if the session is involved in HUT/FASTLOAD/MLOAD/EXPORT?
y-yes, n-no
cnsrun: screen 1 status: Reading
y

cnsrun: screen 1 status: Running
QUERYSESSION will run in Workload Def: WD-Default


 Session State Query Results : 16/10/27  13:32:01

 Host   Session  PE     DBC User ID
 -----  -------  -----  -------------------------------
     1   220826  30719  DBC

 State Detail : MONITOR Partition Session

 Request#    State                       TimeStamp
 ----------  --------------------------  ---------
       9005  IDLE                        13:31:45

 ========================================================================


 End of session state report

 

 Please enter a logical host id (? for help):

cnsrun: screen 1 status: Reading
quit

cnsrun: screen 1 status: Running
 *** Warning - Illegal characters in the input ignored

 Please enter a logical host id (? for help):

cnsrun: screen 1 status: Reading
node1:~ # cnscim -s

CNS Screens

Screen 1  --  qrysessn
   active=True,  enabled fkeys=, help level=0,
   nostop=False,  reading=True, hide=True

Screen 5  --  DBS I/O
   active=True,  enabled fkeys=, help level=0,
   nostop=False,  reading=False, hide=False

Screen 6  --  SUPERVISOR
   active=True,  enabled fkeys=, help level=0,
   nostop=False,  reading=True, hide=False
node1:~ # cnsterm 1
Attempting to connect to CNS...Completed.
Hello
 Session State Query Results : 16/10/27  13:32:01

 Host   Session  PE     DBC User ID
 -----  -------  -----  -------------------------------
     1   220826  30719  DBC

 State Detail : MONITOR Partition Session

 Request#    State                       TimeStamp
 ----------  --------------------------  ---------
       9005  IDLE                        13:31:45

 ========================================================================


 End of session state report

 

 Please enter a logical host id (? for help):

quit

 *** Warning - Illegal characters in the input ignored

 Please enter a logical host id (? for help):

>


 QrySession has terminated
^C
node1:~ # cnsrun -utility qrysessn -commands '{*} {*} {y} {}' -force -ok -multi -nostop -log /tmp/idlesessioncount.out -debug 1
cnsrun: opened pipe to CNS localhost (fd=file6)
cnsrun: System status is 'Attempting to connect to CNS...'
cnsrun: System status is 'Connecting user root...'
cnsrun: System status is 'Attempting to connect to CNS...completed.'
cnsrun: System status is '1/1 node1 Logons are enabled - Users are logged on'
cnsrun: screen 1 status:
cnsrun: setting window 1 title to 'qrysessn'
cnsrun: screen 1 status: Running
cnsrun: screen 6 status: Reading
DBS State: 1/1 node1 Logons are enabled - Users are logged on
DBS State: 1/1 node1 Logons are enabled - Users are logged on
cnsrun: Idle ready to start qrysessn
start qrysessn

cnsrun: screen 6 status: Running
Started 'qrysessn' in window 1
 at Thu Oct 27 13:32:30 2016

cnsrun: screen 1 status: Running
cnsrun: setting window 1 title to 'qrysessn'
cnsrun: open window: 1
cnsrun: screen 6 status: Reading
cnsrun: clearing screen 1
 

 _______
    |                                |              |
    |    ___     __     ____         |    ____    __|__    ____
    |   /      |/  \    ____|    ____|    ____|     |      ____|
    |   ---    |       /    |   /    |   /    |     |     /    |
    |   \___   |       \____|   \____|   \____|     |__   \____|
 
    Release 15.10.01.05 Version 15.10.01.05
    SESSION STATUS Utility (Dec 94)
 

 Session state Query Utility : 16/10/27  13:32:30

 Please enter a logical host id (? for help):

cnsrun: screen 1 status: Reading
*

cnsrun: screen 1 status: Running

 Please enter session ids (? for help):

cnsrun: screen 1 status: Reading
*

cnsrun: screen 1 status: Running

Is detail information needed if the session is involved in HUT/FASTLOAD/MLOAD/EXPORT?
y-yes, n-no
cnsrun: screen 1 status: Reading
y

cnsrun: screen 1 status: Running
QUERYSESSION will run in Workload Def: WD-Default


 Session State Query Results : 16/10/27  13:32:30

 Host   Session  PE     DBC User ID
 -----  -------  -----  -------------------------------
     1   220826  30719  DBC

 State Detail : MONITOR Partition Session

 Request#    State                       TimeStamp
 ----------  --------------------------  ---------
       9010  IDLE                        13:32:04

 ========================================================================

 Host   Session  PE     DBC User ID
 -----  -------  -----  -------------------------------
     1   221498  30718  DBC

 State details : IDLE


 ========================================================================


 End of session state report

 

 Please enter a logical host id (? for help):

cnsrun: screen 1 status: Reading

cnsrun: screen 1 status: Running

 QrySession has terminated
cnsrun: checking for utility started...
cnsrun: screen 1 status:        
node1:~ # cnscim -s

CNS Screens

Screen 5  --  DBS I/O
   active=True,  enabled fkeys=, help level=0,
   nostop=False,  reading=False, hide=False

Screen 6  --  SUPERVISOR
   active=True,  enabled fkeys=, help level=0,
   nostop=False,  reading=True, hide=False
node1:~ #