Linux Shell Script to Compare PID

Just my testing Linux bash script code to compare PID... I'm not really using it yet. But I'm thinking if I can use it to verify that there is running process with the same PID in /var/run/appname.pid on the running process snapshot (ps).


if there is no such PID, maybe I can simply delete the .pid file. And the process which will check for this file can restart as usual.

Here's the content of my ~/pidcmp script:


#!/bin/sh

thepid=`cat /var/run/ppp0.pid`
echo "the pid is $thepid"
spsaux=`ps aux | grep [p]ppd`
okflag=0

gettx ()
{
local IFS=" "
i=0
for tx in $1; do
myarr[$i]=$tx
let i+=1
done
}
NEWLINE='
';
oldifs=$IFS
IFS=$NEWLINE
for line in $spsaux; do
# echo "line: $line"
gettx $line
foundpid=${myarr[1]}
if [ $foundpid == $thepid ]; then
echo "the pid is equal!!"
okflag=1
fi
done

#echo "foundpid: ${myarr[1]}"
IFS=$oldifs

echo "okflag = $okflag"


This is just my idea... The script is working for that purpose but use it at your own risk... Enjoy Linux bash scripting!!

Comments

Popular posts from this blog

How to Create Hyperlink on Blogger Post

How to Add a Sudo User on AlmaLinux 9.2 (Turquoise Kodkod): A Step-by-Step Guide

How to Show and Hide Text in Blog Post