-
-
Save jhadev/c30ba18e07d5fcc7f5dc2e5df576f134 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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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