Skip to content

Instantly share code, notes, and snippets.

@gubatron
Last active November 21, 2022 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gubatron/2d97b31b0621c459f8b5ee8665c9f7b9 to your computer and use it in GitHub Desktop.
Save gubatron/2d97b31b0621c459f8b5ee8665c9f7b9 to your computer and use it in GitHub Desktop.
Linux command (script) to kill old ssh-agent processes, (could be parametrized to change the process name)
#!/usr/bin/env python
# Author: @gubatron
# License: MIT License, Copyright 2019
import os
import sys
if __name__ == '__main__':
cmd_get_process_list = 'ps -ef --sort=start_time | grep ssh-agent | grep -v grep'
output = os.popen(cmd_get_process_list)
lines = output.read().split("\n")
output.close()
if len(lines) < 3:
print('kill_old_ssh_agents: You\'re good, nothing to kill')
sys.exit(0)
for line in lines[:-2]:
cmd = 'kill -9 ' + line.split()[1]
print('kill_old_ssh_agents: ' + cmd)
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment