UBNTMOD check range of IP addresses and see if they resolve DNS

The following uses the ubntmod.sh script to check a device then report if it is resolving DNS or not. ip=”192.168.1.” specifies the first part of the ip, the “for ((i=1; i<=254;i++))” tells it to go from –, change the beginning and ending number if you want to change the ip range.

ip="192.168.1." && for ((i=10; i<=30;i++)); do if ( fping ${ip}$i -r1 | grep alive); then ./ubntmod.sh -i ${ip}${i} -e ; else echo ${ip}$i not alive; fi ; done 

Broken out for easier reading.

for ((i=10; i<=30;i++))
if ( fping ${ip}$i -r1 | grep alive); then
./ubntmod.sh -i ${ip}${i} -e
else echo ${ip}$i not alive

If the script is able to log into the device and resolve DNS you should get Resolves DNS

Linux night light script

The following script let you turn your screen brightness up/down, but also adjust the color for night time.

Copy and paste code below in a nightlight.sh file

chmod +x nightlight.sh

and run

./nightlight.sh on .5


export DISPLAY=$(w $(id -un) | awk 'NF > 7 && $2 ~ /tty[0-9]+/ {print $3; exit}')

display=`xrandr | grep "\ connected" | cut -d" " -f1`
# Check if brightness was specified.  If not, set screen to 50% brightness
if (echo $2 | grep [0-9]);then
elif (echo $1 | grep -q help);then
         echo "############"
         echo "Brightness variable not set, setting to fallback of 50%"
night_mode() {
   for disp in ${display}; do
     xrandr --output $disp --gamma $1 --brightness ${brightness}
  done }
# auto is for future development
# auto() {
# The idea behind auto is to setup something that can pull the actual sunrise/sunset times then automatically adjust the display.
# Ideally there would be an algorithm so it does it slowly over a period of time, say slightly change the color over 30 minutes.
# until the desired color limit is reached
# curl sunrise-sunset.com/timezone/time
# if (time > sunset && colorTemp != colorTempMin); then
# set color to current temp-1
# elif (time > sunrise && colorTemp != colorTempMax); then);
# set to full brightness and temp
# else
# unable to parse, skipping.
# fi
help() {
echo " Help for nightmode script.  
How to run script
./nightmode.sh on/off brightness
Turn nightmode on and set screen brightness to 75%
./nightmode.sh on .75
Turn night mode off and set screen brightness to 100%
./nightmode.sh off 1
case $1 in
  off) night_mode 1:1:1 1.0 ;;
  help) help ;;
  auto) auto ;;
  *) night_mode 1:1:0.5 ;;

Setup in crontab to automatically trigger when it gets night or morning

* 21 * * * ~/nightlight.sh on .5  # Turn on at night
* 7 * * * ~/nightlight.sh off 1  # Turn off in the morning

Bash script to send messages to Microsoft Teams

Copy and save into teams.sh file. Make executable. Change web hook, Run!

The script is a modified Slack script from off the web.

# bash script to send messages to Microsoft Teams.
function usage {
echo "HELP ME!"
echo "description: send messages to Microsoft Teams channels"
echo "special notes: You'll need to change the teamsUrl variable to contain your webhook from Teams."
echo "usage: ${0} -b \"Message contents\""
echo " -m Message body"
echo " -h This help info"
exit 1
while getopts "m:h" opt; do
case ${opt} in
m) msgBody="$OPTARG"
h) usage
\?) echo "Invalid option -$OPTARG" >&2
# Add/Change the webhook to one you created in Teams
if [[ ! "${msgBody}" ]]; then
echo "You didn't specify a message!"
read -d '' payLoad << EOF
"text": "${msgBody}",
statusCode=$(curl \
--write-out %{http_code} \
--silent \
--output /dev/null \
-H 'Content-type: application/json' \
--data "${payLoad}" ${teamsUrl})
echo ${statusCode}

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

servicemonitor.sh httpd mariadb

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

Setup Script

Create servicemonitor.sh 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="~/teams.sh -b"  # Sends a message to Microsoft Teams channel.  Needs the teams.sh script in the users home directory.
 ${msg} "$1"
 function SERVICECHECK {
 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 teams.sh 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 servicemonitor.sh

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/servicemonitor.sh httpd mariadb

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

wget www.incredigeek.com/home/downloads/scripts/sftpUserAdd.sh

Make executable

chmod +x sftpUserAdd.sh

Run with the new user you want to create.

./sftpUserAdd.sh 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

Zenoss 5 backup Script


# Zenoss 5 backup script

# Zenoss 5 Backup log file
# Backup directory

echo "Starting Zenoss backup Script"

echo "Starting backup to ${bdir}." $(date) >> ${log}
echo "Starting Backup to ${bdir}." $(date)

# Stop Zenoss Service
serviced service stop Zenoss.core


# Wait for Zenoss to stop and then continue the backup
while [ -ne `serviced service status Zenoss.core | grep Stopped` ]
        echo "Waiting for Zenoss to Stop"
        sleep 5

# Backup
echo "Starting Zenoss Backup"
serviced backup ${bdir} 
echo "Backup Finished"


# Start Zenoss
echo "Starting Zenoss"
serviced service start Zenoss.core

echo "Finished backup." $(date) >> ${log}
echo "Finished backup." $(date)