I want to print in a log with the help of lsof
the information about opened resources but I don't want the customer to see what libraries are used.
I browsed through the lsof man page but I cannot get a hold of how I can exclude only the libraries from the output. Is there an easy method to do this?
Asked
Active
Viewed 1,329 times
0

George
- 1,027
- 3
- 12
- 20
-
1Would piping the output through `grep -v '\/lib'` be doable in your context? That way you'd have complete control over what's written. – creinig Mar 21 '13 at 13:23
-
1Why don't you want the customer to see the libraries? Are you entirely sure your customer won't be able to see them otherwise? If a customer has access to `/proc/` he surely could these libraries.... – Basile Starynkevitch Mar 21 '13 at 13:31
-
1@BasileStarynkevitch This is the requirement, i don't know exactly. My guess is that the client doesn't have access to the machine and the logs are stored on an sdcard. – George Mar 21 '13 at 13:59
-
My point is that if `lsof` -which uses `/proc/` internally- is runnable by the customer thru your script, he can directly access `/proc/` (as soon as he is able to run some script or upload some program on the machine). – Basile Starynkevitch Mar 21 '13 at 14:54
2 Answers
2
You can exclude content from the output of lsof using it's -d flag along with it's negation character ^
For example, the following will prevent the txt file descriptor being displayed by lsof.
lsof -d '^txt'

Zlemini
- 4,827
- 2
- 21
- 23
1
you can use sed, awk, cut for parsing output of lsof, show only those lines, which doesn't have Lnn and ltx in their 4th field.

A human being
- 1,220
- 8
- 18