I am writing this simply script which conver to into a daemon and run in the background. The script job is simple. And it need to monitor a process type say ls command process. And write it into a file for records.
My approach to this to just have a while true loop to constantly check for a process type using ps command. And if it detect it, it will append it to a file.
I was wondering if this is a bad approach to write this
my code as follow
while true
do
if [[ $(ps -aux | grep -w "ls") ]]
then
#append to file
fi
done &
sleep xcommand lest your script go berserk. And, did you consider thepgrepcommand in lieu of theps | greppipe? Be aware you may get a multiline output.