Search for string and append string to file

A very useful string search and append that I find myself rewriting over and over. So I’ve decided to write a post and capture the script:

if grep -q sensu-client “/etc/rc.local”; then
echo “exists”;
else
echo “does not exist”
sudo sed -i ‘/exit 0$/i sudo service sensu-client restart’ /etc/rc.local;
fi

 

Leave a Reply