I have a bash script that runs every hour. Output of this is sent to me via email. This is run through cronjob.
#!/bin/bash
# Script: temp_email.sh
# -------------------------------------------------------
cpu=$(</sys/class/thermal/thermal_zone0/temp)
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $(/opt/vc/bin/vcgencmd measure_temp)"
echo "CPU => $((cpu/1000))'C"
echo "-------------------------------------------"
echo ""
echo ""
As of now it provides temperatures via email. I wanted to add a loop and self-healing to mounted drives and http service.
I am using following commands to get results of apache2 service status
systemctl list-units --no-legend apache2.service | cut -d' ' -f4
The output if the service is running is "running
". I want the loop to attempt to start the service if the status is anything but running. Output of this attempt.
I use the following to check status of external drives mounted to the Raspberry Pi.
lsblk -dlno NAME,MOUNTPOINT /dev/sd??*
Again, I want to put this in a loop wheirein if the drive is unmounted it will first gracefully stop the apache2 service, mount the drive and later start the apache2 service.
I am unable to get "if & then statements" correctly. I do not want any changes in case both the service and drives are running as they should.
Thank you.