You are not logged in.
Currently I am using
lsof -i -n -P | awk '{print $1}' | uniq | sed '/COMMAND/d'
which just spits out the names of the applications that are using internet access (which is all I want). But Deluge comes up as /usr/bin. It comes up that way in the system monitor as well. Does anyone know a better way of doing this other that lsof?
Last edited by dodo3773 (2011-05-04 21:32:11)
Offline
I don't know if its better, but I'm using 'netstat -pant'. Short and easy to remember.
Edit: Oh, if it should JUST spit out the names, I don't know. Sorry.
Last edited by Lars Stokholm (2011-05-04 20:03:54)
Offline
I don't know if its better, but I'm using 'netstat -pant'. Short and easy to remember.
Edit: Oh, if it should JUST spit out the names, I don't know. Sorry.
Right on that works pretty well. But now instead of showing "/usr/bin" it shows "python2" Although, python2 is a lot more accurate then /usr/bin.
Last edited by dodo3773 (2011-05-04 20:31:36)
Offline
"I exist" is the best myth I know..
Offline
Wow, thanks!
zʇıɹɟʇıɹʞsuɐs AUR || Cycling in Budapest with a helmet camera || Revised log levels proposal: "FYI" "WTF" and "OMG" (John Barnette)
Offline
Now I am getting /usr/bin/python2. Deluge is python2 though. I am thinking that actually showing deluge might not be possible.
Offline
It would require a bit of additional mangling
[karol@black ~]$ ps -o cmd= -p $(lsof -i -n -P | sed 1d | awk '{print $2}' | uniq)
firefox
/usr/bin/python2 /usr/bin/deluged
/usr/bin/python2 /usr/bin/deluge -u console
or
[karol@black ~]$ ps -o cmd= $(pgrep deluge$)
/usr/bin/python2 /usr/bin/deluge -u console
Offline
It would require a bit of additional mangling
[karol@black ~]$ ps -o cmd= -p $(lsof -i -n -P | sed 1d | awk '{print $2}' | uniq) firefox /usr/bin/python2 /usr/bin/deluged /usr/bin/python2 /usr/bin/deluge -u console
or
[karol@black ~]$ ps -o cmd= $(pgrep deluge$) /usr/bin/python2 /usr/bin/deluge -u console
This is very interesting. When I do it I see
firefox
evolution --component=mail
/usr/bin/python2 /usr/bin/deluge
What I would like to get from this is
firefox
evolution
/usr/bin/deluge # or just deluge
So, maybe with an if then statement... Need to look at this a little closer. Thanks for the tip though. This is great.
Offline
You may simply cheat and grep away deluge, evolution or whatever.
Last edited by karol (2011-05-04 21:34:23)
Offline
Got it. I can get the results with this
ps -o cmd= -p $(lsof -i -n -P | sed 1d | awk '{print $2}' | uniq) | sed /deluge/d | awk '{print $1}' && ps -o cmd= -p $(lsof -i -n -P | sed 1d | awk '{print $2}' | uniq) | grep deluge | awk '{print $2}' | cut -c 10-15
and it will give me
firefox
evolution
deluge
Thanks a lot everybody.
Last edited by dodo3773 (2011-05-04 21:40:09)
Offline
The sed hieroglyphics might be more flexible:
lsof -nPi | awk '{print $1}' | uniq | sed 1d | sed -e 's#evolution --component=mail#evolution#' -e 's#/usr/bin/python2 /usr/bin/deluge#deluge#'
Simply add a sed substitution for any troublesome app.
Last edited by karol (2011-05-04 22:05:15)
Offline
The sed hieroglyphics might be more flexible:
lsof -nPi | awk '{print $1}' | uniq | sed 1d | sed -e 's#evolution --component=mail#evolution#' -e 's#/usr/bin/python2 /usr/bin/deluge#deluge#'
Simply add a sed substitution for any troublesome app.
So
sed -e 's#evolution --component=mail#evolution#'
relaces "evolution --component=mail" with "evolution"
that is definately cleaner. Thanks.
Offline
Does that work? It looks to me like it shouldn't, but I don't have any apps that fit that criteria to test with.
The issue to me is that awk '{print $1}' will only print up to the first space, whereas both sed substitutions include a space. I might be missing something obvious though.
I dislike piping from awk to sed and would normally try to write the whole thing in awk if I have the time, but I haven't written anything in awk for a few months and it'll take too long for the benefit, so here's how I'd do it:
lsof -nPi | awk '!/COMMAND/{print $1}' | uniq | sed 's/.*\(evolution\).*/\1/;s/.*\(deluge\).*/\1/'
This, at least, removes some unnecessary sed calls, though the sed command is slightly less clear. You can embed newlines into the sed command if preferred like this:
lsof -nPi | awk '!/COMMAND/{print $1}' | uniq | sed 's/.*\(evolution\).*/\1/;
s/.*\(deluge\).*/\1/'
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Isn't this all very ugly? Why not write a simple tokenizer function in bash that returns the first token, if it is not /usr/bin/python or /opt/java/bin/java and in this case return the second token?
On second thought there maybe is such a script that returns the "true" name of the process somewhere...
฿ 18PRsqbZCrwPUrVnJe1BZvza7bwSDbpxZz
Offline
Good idea.
Untested:
lsof -nPi | awk '!/COMMAND/ {print $1}
/.*python[2]*/ || /.*java/ {print $2}' | uniq
It doesn't clear the path of applications run via those two. It's about two steps from being a full awk application. Add names to an associative array (makes it uniq) and strip the path.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Okay, there were several errors with all of the above, so I've fixed them here. Again, I couldn't test python & java output, but I made a text file with what I thought (from above) they would look like and tested against that. It may need a few minor tweaks though:
#!/bin/bash
lsof -nPi | awk '/.*python[2]*/ || /.*java/ {cmd[$2] = $2;next}
!/COMMAND/ {cmd[$1]=$1}
END {for (item in cmd ) {
sub(".*/", "", item)
print item}
}'
One possible improvement is that it could be made just an awk script and call lsof from within awk (use getline).
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Okay, there were several errors with all of the above, so I've fixed them here. Again, I couldn't test python & java output, but I made a text file with what I thought (from above) they would look like and tested against that. It may need a few minor tweaks though:
#!/bin/bash lsof -nPi | awk '/.*python[2]*/ || /.*java/ {cmd[$2] = $2;next} !/COMMAND/ {cmd[$1]=$1} END {for (item in cmd ) { sub(".*/", "", item) print item} }'
One possible improvement is that it could be made just an awk script and call lsof from within awk (use getline).
Nice! How about posting it here?
Offline
Done, thanks.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline