Sed sed bash – Writing Simple Bash Scripts

I manage a lot of websites and servers, and there’s nothing more time consuming than fulfilling the request of a random client who wants to make changes to their website or add a new web page. Thankfully I happen to be a Linux Network Administrator and have access to every delicious part of many Linux servers to assist me in making this process easy and stress free.

Sure! I can hire some guy out of India to manage these menial tasks. But why? With some simple bash scripting and a little bit of Sed knowledge – I can create multiple web pages within a minute. Here’s my little secret:

With some simple bash scripting, I create a simple template copied from a content page on the website. Replace content with specific tags (i.e. Change the page title to _TITLE_) this way I can determine parts of that page I want to overwrite with my bash script. Once I have every part of the template tagged, I write my bash script.

#/bin/bash
echo Page Title
read TITLE
echo File Name
read FILENAME

#copy over the template
cp template.php $FILENAME
echo Writing $FILENAME Done.

#replace those tags
sed -i “s/_TITLE_/$TITLE” $FILENAME
echo Writing new title to $FILENAME done

echo New Web Page $FILENAME created
echo Done.

save the file
chmod +x your script
./run your script

That’s it… You can see how easy it is to utilize the above script to create new web pages quick and easy. It saves me a ton of time with older websites. Hope you like it!