Skip to content

Instantly share code, notes, and snippets.

@marinnedea
Last active May 8, 2018 10:58
Show Gist options
  • Save marinnedea/00e926b266eb01de9a90d8e9a2b69ce0 to your computer and use it in GitHub Desktop.
Save marinnedea/00e926b266eb01de9a90d8e9a2b69ce0 to your computer and use it in GitHub Desktop.
Clear orphaned waagent PID files - Azure WaAgent on Linux related
#!/bin/bash
#get the running waagent PID
waagentpid=$(ps axf | grep waagent | grep -v grep | awk '{print $1}')
#all waagent.pid files in /var/run/ directory
dir=/var/run/*waagent.pid
#for each file in $dir
for f in $dir
do
#assign to var $pid the value in the file
pid=$(< "$f")
if [ "$waagentpid" -eq "$pid" ]
then
echo "Waagent is running on PID $pid. Keeping $f intact."
else
echo "No process running on PID $pid. Deleting the $f file!"
#delete the file coresponding to the value of $f
rm -f $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment