NVME Drive Keep Alive Script

Placed in /Scripts/keepalive

 pi@raspberry01:~/Scripts/keepalive$ cat keepalive.sh 
 #bin/bash
 
## BAINWERX
## NVME Keepalive Read|Write Script
## version 1.2
## created Feb 2021

## Time in 12 hr format
 logging_time=$(date +'%r')
 
## backup dir format
 logging_dir=$(date +'%m_%d_%Y')
 
find /home/pi/Scripts/keepalive/*.log -mtime 1 -delete;
 echo "NVME Keepalive Read|Write at" "${logging_time}" >> /home/pi/Scripts/keepalive/"${logging_dir}".log 

Runing this script will create a .log file with a simple write to the nvme drive. Next step wil be to setup a cron task with

sudo crontab -e

add the following lines to enable the script

# nvme drive keepalive by posting to drive every minute
 */1 * * * * sudo sh /home/pi/Scripts/keepalive/keepalive.sh

Now Save and reboot the system.

NOTE

If you are adding this with pihole…you might want to add the following step which will run when the pi is rebooted. It tells the pi that when it reboots…wait 15 seconds and then restart the pihole dns resolution

# On reboot + 15 seconds restart the pihole dns resolver (loop prevention)
 
@reboot sleep 15 && sudo pihole restartdns

Raspbian Commands – RFKILL

RFKILL is a handy tool to hard disable wireless and bluetooth from Raspbian devices like a pi. Unlike other command line tools, this is persistant meaning that it will survive reboots until it is unblocked.

sudo rfkill block wifi
sudo rfkill block bluetooth

to undo…

sudo rfkill unblock wifi
sudo rfkill unblock bluetooth

Raspberry PI – Wireless Scanning

We stepped up to a wireless mesh network at the house this weekend. We’ve been having a lot of weird wireless issues in the last week or so…so we updated our old Linksys routers to a new wireless mesh.

Switching wireless id’s wasn’t the end of the world…I thought it would be a bigger pain in the butt…but it’s really not that terrible. Most applications have a method to be able to switch the wireless network they connect to “fairly painlessly”. Even the Ring doorbell (which has 2 extra steps) wasn’t terrible.

I did want to try and figure out how to wirelessly scan and confirm which networks the pi’s were on as they serve a couple of purposes for us.

wgetid will show you the network the pi is connected to.

sudo iwlist wlan0 scan | egrep “Cell|ESSID|Signal|Rates” will provide a quick wireless scan and show you the strength and rates available.

Raspberry Pi – Mounting an NFS @ boot

I have an “every 3rd night backup” script that’s been crashing out, and it’s because as soon as I log off the system drops the file share…so the system forgets where to store backups.

So using the logic of the following crontab that works I’ve made my own slightly customized version…

@reboot sleep 30 && python /path/to/your/script.py &

Reverse engineering the code, the secret sauce is actually in the sleep 30, which is basically telling the system to wait for a few ticks before running the following command…which ironically waits just long enough for the network stack to be fully up and running and then mount.

@reboot sleep 30 && sudo mount -t nfs 192.168.1.8:/volume1/pi /media/SYNOLOGY

Raspberry Pi – MOTD

For those not in the loop, the MOTD is the message of the day that is shown after you login to the Pi.

After some running through the motions on a few things, I was able to customize it to show information that I would like to know when I access the device…

After sitting and coding things out (mostly remembering things like grep, sed and cut…my default motd now looks like this.

Raspberry Pi – Getting Started with a Headless Pi

So in order to keep life somewhat simple at the moment, I’m not planning to immediately connect the Pi to the network via cable / monitor / keyboard or mouse…that means it’s gonna be headless.

Step 1 download the latest Rasbian LITE image

Step 2 extract the .img file from the file that was downloaded

Step 3 connect the sd card to the computer and use Etcher to flash the sd card to the latest raspian image

Step 4 enable ssh functionality by connecting to /Volumes/boot followed by touch ssh (this created a blank file called ssh)

Step 5 enable wireless functionality by editing /Volumes/wpa_supplicant.conf to reflect the following changes, when complete save the changes and eject the sd card

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
    ssid="YOUR_SSID"
    psk="YOUR_WIFI_PASSWORD"
    key_mgmt=WPA-PSK
}

Step 6 connect your pi to power and turn it on

Step 7 ping raspberrypi.local to determine your ip

Step 8 ssh raspberrypi.local -l pi with a password of raspberry

Step 9 perform the following tasks

a) sudo raspi-config

b) sudo apt-get update

c) sudo apt-get dist-upgrade

d) sudo reboot