Shitu
Shitu

Reputation: 837

querying v$session table in unix

I am trying the following in unix:

count=sqlplus -s ${DB_USER}/${DB_PASS}@${DB_INST} << END
set echo off head off verify off feed off pages 0 lin 120
select COUNT(USERNAME) from v$session where status not in ('INACTIVE') and osuser not in ('oracle');
exit;
END
echo $count

But it is evaluating $session as null and just querying table "v". Any way to query this table in unix.

Upvotes: 0

Views: 2472

Answers (1)

Sylvain Leroux
Sylvain Leroux

Reputation: 52070

Assuming you are using bash, if you quote your heredoc termination string (i.e.: << 'END') you will prevent shell expansion of $...

count=sqlplus -s ${DB_USER}/${DB_PASS}@${DB_INST} << 'END'
set echo off head off verify off feed off pages 0 lin 120
select COUNT(USERNAME) from v$session where status not in ('INACTIVE') and osuser not in ('oracle');
exit;
END
echo $count

From man bash:

The format of here-documents is:

              <<[-]word
                      here-document
              delimiter

If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence \ is ignored, and \ must be used to quote the characters \, $, and `.

Upvotes: 1

Related Questions