Lets say you had a web page and you wanted to change the css at certain times to show a new picture. Here’s some sed regexp’s to do it for ya.

In this example, I am picking a random image from a directory of approved images and switching out the old whatever.jpg with newstuff.jpg

______________________backchange.sh

#!/bin/bash<br></br> #heres the line i am going to be editing (actually the background of my site):<br></br> #background-image: url(https://website.net/img/backs/whatever.jpg);<br></br> cd /var/www/img/backs/<br></br> set -- *<br></br> length=$#<br></br> random=$(($RANDOM%($length+1)))<br></br> file=${!random}<br></br> cd /var/www<br></br> mv style.css style.css.bak<br></br> sed "s/img\/backs\/.*/img\/backs\/$file\);/" style.css.bak > style.css

Very useful for changing the background of a site by just setting up a cron job to change it whenever you like.

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.