Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Add Comment to SSH process

  • 10-02-2014 03:13PM
    #1
    Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭


    This calls for either some lateral thinking or for one of you guys to point out the blinding obvious!

    I need to fork an SSH process or a batch of processes. And then I need to be able to kill them, uniquely. The forking takes place via a web interface and although I could get the pid of each process I rather not have multiple pid files hanging about. Even then it would be tricky to match pid with process. I was hoping there might a way to add a comment to the SSH process (ssh_config(5) list some promising switches but none I can use) What I was hoping for was something like:
    ssh user@host -i $file -p $port -oComment="My Unique Comment"
    

    Then, if I:
    ps -ef |grep "My Unique Comment" |grep -v grep | awk {'print $2'}
    
    I can grab the pid and kill as required. Any tips!?


Comments

  • Registered Users, Registered Users 2 Posts: 53 ✭✭spynappels


    Would it be possible to open each in a separate screen instance with a specific name and then you can kill the screen processes based on their name/comment?


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    azzeretti wrote: »
    This calls for either some lateral thinking or for one of you guys to point out the blinding obvious!

    I need to fork an SSH process or a batch of processes. And then I need to be able to kill them, uniquely. The forking takes place via a web interface and although I could get the pid of each process I rather not have multiple pid files hanging about. Even then it would be tricky to match pid with process. I was hoping there might a way to add a comment to the SSH process (ssh_config(5) list some promising switches but none I can use) What I was hoping for was something like:
    ssh user@host -i $file -p $port -oComment="My Unique Comment"
    

    Then, if I:
    ps -ef |grep "My Unique Comment" |grep -v grep | awk {'print $2'}
    
    I can grab the pid and kill as required. Any tips!?

    How about instead of a unique comment, you create a uniquely named config file for each ssh session. The contents of the config file can remain the same, but the name of the file will be unique. The you can do a ps aux | grep 'unique name", to kill it.


  • Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭azzeretti


    syklops wrote: »
    How about instead of a unique comment, you create a uniquely named config file for each ssh session. The contents of the config file can remain the same, but the name of the file will be unique. The you can do a ps aux | grep 'unique name", to kill it.

    I like this! Good thinking.
    Thanks.


Advertisement