美好的一天,我一整天都在阅读类似的主题,但不幸的是找不到适合我情况的答案。所以这就是我想要做的。我有很多函数的 shell 脚本,其中一个函数假设调用 ssh-agent:
sh_agent_run () {
case "$(pidof ssh-agent | wc -w)" in
0) echo "SSH agent is not running. Startting SSH agent."
eval `ssh-agent -s`
ssh-add ${ssh_key}
;;
1) echo "SSH agent is running. Nothing to do."
;;
*) echo "Too much instances of SSH agent is running. Stopping SSH agent instances and running just one"
while pidof ssh-agent; do
echo "Stopping ssh-agent..."
killall -9 ssh-agent
sleep 1
done
echo "Starting valid SSH agent instance"
eval `ssh-agent -s` …Run Code Online (Sandbox Code Playgroud)