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

Leave a Reply