Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

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";
echo "does not exist"
sudo sed -i '/exit 0$/i sudo service sensu-client restart' /etc/rc.local;


Filed under: Bash, Linux, Ubuntu No Comments