문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

dirname $(readlink -f /proc/<pid>/cwd)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top