linux - Running a bash script with an infinite while loop at startup and in the background on a Raspberry Pi -


i've made small bash script want run on startup of raspberry pi. script run on machine because have mounted usb drive keeps disconnecting @ random times. use media storage , find out @ times it's disconnecting , remount drive.

here script

#!/bin/bash while :   if mountpoint -q /media/media     continue else     echo $(date) >> log.txt     sudo mount /dev/sda1 /media/media fi sleep 1 done 

basically run when raspberry pi boots , have continuously running in background @ times.

can give me doing this? thank you.

using inotifywait

sudo inotifywait -d -e unmount /media/media/some_file | while read unmounted;      sudo mount /dev/sda1 /media/media done 

or maybe:

while true;     sudo inotifywait -e unmount /media/media/some_file | read unmounted     sudo mount /dev/sda1 /media/media done 

Comments