Search code examples
bashoracle-databaseunixsqlplus

Get oracle listener status output from sqlplus no matter what the listener name


With the below command, I can get the listener name in the listener.ora for the current $ORACLE_HOME

grep ' =$' $ORACLE_HOME/network/admin/listener.ora | grep -v '(' | grep -v 'SID_LIST' | sed 's/=//g'

However, my goal is to get that to output from dropping out of SQLPLUS.

SQL> !lsnrctl status

So that the above command will use the output of the grep:

SQL> !lsnrctl status <output_of_grep>

I am floundering around trying to put it all into some variable but my unix skills are failing me. And, actually I do not know if it is even possible to do that, can anyone help?


Solution

  • You can further pipe the grep command to xargs. See for example:

    grep ' =$' $ORACLE_HOME/network/admin/listener.ora | grep -v '(' | grep -v 'SID_LIST' | sed 's/=//g' | xargs -n 1 lsnrctl status
    

    I have extended your grep and sent it to lsnrctl via xargs.