I have a deployment user that's running a cronjob tuning in every minute.
On the remote server (the deployment target) I didn't have my public keys available but instead got a Could not open a connection to your authentication agent on my deployment server on ssh-add.
I ended up putting this line to my .bashrc:
ps -u $(whoami) | grep ssh-agent &> /dev/null || (eval $(ssh-agent) && ssh-add)
Despite it shouldn't in my understanding, the cronjob opens a new ssh-agent everytime. After 14-16 hours the server runs out of memory after creating a kern log with lots of entries like this:
Aug 12 21:50:58 tools kernel: [64021.568750] [25668] 1000 25668 2654 81 9 0 0 ssh-agent
... and I have to restart it.
How can I limit the number of running ssh-agent processes to one or kill the process after ending the cronjob?
UPDATE
The given answer works perfectly fine, I just found out that that i had another eval ssh-add within the crontab. I'm going to reward the given question with the bounty.