Question

I'm connecting to an exadata and want to get information about "ORACLE_HOME" variable inside them. So i'm using this command:

ls -l /proc/<pid>/cwd

this is the output:

2 oracle   oinstall          0 Jan 23 21:20 /proc/<pid>/cwd -> /u01/app/database/11.2.0/dbs/

i need the get the last part :

/u01/app/database/11.2.0  (i dont want the "/dbs/" there)

i will be using this command several times in different machines. So how can i get this substring from whole output?

Was it helpful?

Solution

Awk and grep are good for these types of issues.

New:

ls -l /proc/<pid>/cwd | awk '{print ($NF) }' | sed 's#/dbs/##'

Old:

ls -l /proc/<pid>/cwd | awk '{print ($NF) }' | egrep -o '^.+[.0-9]'

Awk prints the last column of the input which is your ls command and then grep grabs the beginning of that string up the last occurrence of numbers and dots. This is a situational solution and perhaps not the best.

OTHER TIPS

Parsing the output of ls is generally considered sub-optimal. I would use something more like this instead:

dirname $(readlink -f /proc/<pid>/cwd)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top