Skip to main content
added 19 characters in body
Source Link

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your ~/.bashrc or ~/.zshrc file the following code:

function function1 () { ps xu | grep "$1.*$2" | awk '{print $1" "$2" "$11;}' } alias mygrep="function1" 

And to use alias here are examples to force everyone to learn regular expressions:

. /etc/profile #to make alias usable mygrep ${USER} ${PROCESS_PATH} mygrep ${USER} "[f]nord" mygrep "[f]nord" mygrep ".*[s]shd" 

P.S. I've only tested these commands on Ubuntu and Gentoo.

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function function1 () { ps xu | grep "$1.*$2" | awk '{print $1" "$2" "$11;}' } alias mygrep="function1" 

And to use alias here are examples to force everyone to learn regular expressions:

. /etc/profile #to make alias usable mygrep ${USER} ${PROCESS_PATH} mygrep ${USER} "[f]nord" mygrep "[f]nord" mygrep ".*[s]shd" 

P.S. I've only tested these commands on Ubuntu and Gentoo.

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your ~/.bashrc or ~/.zshrc file the following code:

function function1 () { ps xu | grep "$1.*$2" | awk '{print $1" "$2" "$11;}' } alias mygrep="function1" 

And to use alias here are examples to force everyone to learn regular expressions:

. /etc/profile #to make alias usable mygrep ${USER} ${PROCESS_PATH} mygrep ${USER} "[f]nord" mygrep "[f]nord" mygrep ".*[s]shd" 

P.S. I've only tested these commands on Ubuntu and Gentoo.

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function function1 () { ps xu | grep "$1.*[ ].*$2.*"*$2" | awk '{print $1$1" $2;"$2" "$11;}' } alias mygrep="function1" 

And to use alias dohere are examples to force everyone to learn regular expressions: . /etc/profile #to make alias usable my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord

. /etc/profile #to make alias usable mygrep ${USER} ${PROCESS_PATH} mygrep ${USER} "[f]nord" mygrep "[f]nord" mygrep ".*[s]shd" 

P.S. I've only tested these commands on Ubuntu and Gentoo. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function function1 () { ps xu | grep "$1.*[ ].*$2.*" | awk '{print $1 $2;}' } alias mygrep="function1" 

And to use alias do: . /etc/profile #to make alias usable my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord

P.S. I've only tested these commands on Ubuntu. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function function1 () { ps xu | grep "$1.*$2" | awk '{print $1" "$2" "$11;}' } alias mygrep="function1" 

And to use alias here are examples to force everyone to learn regular expressions:

. /etc/profile #to make alias usable mygrep ${USER} ${PROCESS_PATH} mygrep ${USER} "[f]nord" mygrep "[f]nord" mygrep ".*[s]shd" 

P.S. I've only tested these commands on Ubuntu and Gentoo.

added 327 characters in body
Source Link

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function get-pid-by-process-name-and-usernamefunction1 {() { ps xu | grep "$1.*[ ][].*|]$2[*$2.*|]"*" | awk '{print $1 $2;}';' } alias my-grep="get-pid-by-process-name-and-username" mygrep="function1" 

And to use alias do: . /etc/profile #to make alias usable my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord

my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord 

P.S. I've only tested these commands on Ubuntu. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function get-pid-by-process-name-and-username { ps xu | grep "$1.*[ ][.*|]$2[.*|]" | awk '{print $1 $2;}'; } alias my-grep="get-pid-by-process-name-and-username"  

And to use alias do:

my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord 

P.S. I've only tested these commands on Ubuntu. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples

Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:

ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' 

If you want for example to kill ssh-agent for current user you might use following command:

kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` 

To create a handy alias add to your .bashrc file the following:

function function1 () { ps xu | grep "$1.*[ ].*$2.*" | awk '{print $1 $2;}' } alias mygrep="function1" 

And to use alias do: . /etc/profile #to make alias usable my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord

P.S. I've only tested these commands on Ubuntu. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples

added 327 characters in body
Source Link
Loading
Formatting
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324
Loading
added 115 characters in body
Source Link
Loading
Source Link
Loading