Install Ruby 2.6.1 via RVM on CentOS

Install Prerequisites

yum install -y curl gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make cmake bzip2 autoconf automake libtool bison libssh2-devel libicu-devel

Install RVM

curl -L | bash -s stable

Setup RVM, install Ruby 2.6.1 and set to default.

source /etc/profile.d/ 
rvm install 2.6.1
rvm use --default 2.6.1

You may need to add root or the user your using to the rvm group

sudo usermod -G rvm username

Pulled some of the info from here

Bash ANSI-C Quoting

Pulled from

As a side note there is a lot of good bash info out here. ANSI-C Quoting

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: \a

alert (bell) \b

backspace \e\E

an escape character (not ANSI C) \f

form feed \n

newline \r

carriage return \t

horizontal tab \v

vertical tab \\

backslash \'

single quote \"

double quote \?

question mark \nnn

Some examples

echo Hello $'\t' World

Returns “Hello World” with a tab space between both words.

echo Hello $'\n' World

Returns Hello on one line and World on the second

echo "\"Hello World\""

Returns “Hello World” inside double quotes

Bash script to monitor system service

This bash script runs and checks to see if a service like httpd, or mysql is running and alerts if it is not.

Script Usage httpd mariadb

Where httpd and mariadb are the services you want to monitor/check.

Setup Script

Create file and paste the following contents in.


timeHour=date +%H # date/time just shows the hour
quietHour="02" # If it is this hour, then exit program, useful if services are expected to go down during a particular time for maintenance
if ( echo ${timeHour} | grep ${quietHour}); then
echo "Is during quiet time. Quiting."

function ALERT {
msg="~/ -b" # Sends a message to Microsoft Teams channel. Needs the script in the users home directory.
${msg} "$1"
if (systemctl status ${serviceName} | grep Active | grep inactive); then
ALERT "ERROR: $(hostname) - ${serviceName} - ${0} is inactive"
echo "ERROR: ${serviceName} is inactive!"
echo "Running!"
for i in $@
echo Checking ${i}

Note the script that is called is another script that is called that sends an alert to Microsoft Teams. Is not needed for this script to run, but allows for remote alerting.

Save file and make it executable

chmod +x

Add script to crontab (Optional)

crontab -e

The following runs the script every 5 minutes. Can change the 5 to 1 to run every minute. Change httpd and mariadb to the service you want to monitor.

*/5 * * * * /home/UserName/ httpd mariadb

Delete anonymous MySQL user

Log into mysql

mysql -u root -p

List users

select User,Host from mysql.user;

Should return something like the following

MariaDB [mysql]> select User,Host from user;
| User | Host |
| root | |
| librenms | localhost |
| | localhost.localdomain |
3 rows in set (0.00 sec)
MariaDB [mysql]>

Delete anonymous user

Note that there are two single quotes ‘ before the @ sign, not a double quote “

drop user ''@'localhost.localdomain';

LibreNMS enable RRDCached on CentOS 7

Commands from

Create System Service

sudo vi /etc/systemd/system/rrdcached.service
Description=Data caching daemon for rrdtool
ExecStart=/usr/bin/rrdcached -w 1800 -z 1800 -f 3600 -s librenms -U librenms -G librenms -B -R -j /var/tmp -l unix:/run/rrdcached.sock -t 4 -F -b /opt/librenms/rrd/

Save with esc + :wq

Enable rrdcached service on boot up and start the service now

systemctl enable --now rrdcached.service

Enable RRDcached in librenms config

vi /opt/librenms/config.php

add/edit the following line. If it is commented out, uncomment it

$config['rrdcached'] = "unix:/run/rrdcached.sock";

Save with esc + :wq

Check the disk IO after a little bit to see if it went down.

VIM/SED Search and replace lines that do not contain numbers

Objective: Find all lines in a file that only contain alpha characters and delete or replace.

Sample contents of file.


The following sed command works for our objective.

sed s/[[:alpha:]]\{8\}/ALPHAONLY/g file.txt

The part in the [] tells sed to search for any alpha characters a-Z, the part in bold \{8\} tells it to search 8 spaces out (Change if needed) and ALPHAONLY is what alpha line will get substituted to.

sed s/[[:alpha:]]\{8\}/ALPHAONLY/g



You can run the same basic syntax in VI

Search and replace


Or to delete the lines


You can also change [[:alpha:]] for [[:digit:]] if you want to search for numbers instead.

Secure Erase Hard Drive using DD

The following commands are dangerous! Proceed with caution!

Change /dev/sdX to your drive. Make sure you get the correct drive, or you could wipe you main system.

dd if=/dev/zero of=/dev/sdX bs=1M status=progress

The status=progress part shows how much dd has writen. Helpful to gauge how far along it is.

If you want a more secure way to erase the drive, change zero to random. Makes it slower, but should be more secure.

dd if=/dev/random of=/dev/sdX bs=1M status=progres

Side note, these commands should work in macOS, but you may need to drop the status=progress option.

LibreNMS manually clean up MySQL Syslog Database

Adding the following option to the config.php file is supposed to delete anything over 30 days.

$config['syslog_purge']                                 = 30;

You can also manually delete the entries out of the MySQL database by logging into MySQL, selecting the librenms database, and running the command below.

The command deletes all entries older than 12/9/2018 at 08:00. Change the date and time as needed.

DELETE FROM syslog WHERE timestamp < '2018-12-9 08:00:00';

The following link has some more clean up options.

BASH Script to add new SFTP user and setup permissions

This script adds a new SFTP user with only sftp access.  Refer to this post on setting up a SFTP server.

Download script


Make executable

chmod +x

Run with the new user you want to create.

./ sftpUsername

You may need to edit the script and modify the location parameters.

# Automatically setup and add SFTP user
# Script creates new user and setups permissions
if grep -q ${newUser} /etc/passwd ;then
echo ${newUser} Already exsists. Aborting!
exit 1
mkdir -p ${sftpDir}/${newUser}/files
useradd -g sftpusers -d ${sftpDir}/${newUser}/files -s /sbin/nologin ${newUser}
passwd ${newUser}
chown ${newUser}:sftpusers /sftp/CareMark/files