Last active
May 8, 2018 10:58
-
-
Save marinnedea/00e926b266eb01de9a90d8e9a2b69ce0 to your computer and use it in GitHub Desktop.
Clear orphaned waagent PID files - Azure WaAgent on Linux related
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
#!/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