I have following bash script, I wanted to add few more things to it: (This script runs from root cronjob every 6 hours). Device is Raspberry Pi running raspberian.

# Script: temp_email.sh
# -------------------------------------------------------

echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $(/opt/vc/bin/vcgencmd measure_temp)"
echo "CPU => $((cpu/1000))'C"
echo "-------------------------------------------"
echo ""
echo ""

Following is the functionality I'd like to add to this:

I wanted to get current (at the time the script executes) status of apache2 web service. I have tried "service apache2 status" but the output is too long. I would like to get a simple running / stopped in case of the service status.

I would like get status of 2 drives which are mounted under /mount_folder/ . I have tried mount -l but again the information is too much. How do I get only the output for /dev/sd* devices?

Finally I would like for this script to start apache service if it is stopped and mount the devices under /dev/sd* to their respective mount point.

Could someone kindly guide me to it.

1 Answer 1


For the current state of apache2 you can use:

rpi ~$ systemctl list-units --no-legend apache2.service | cut -d' ' -f4
rpi ~$

For the mount status of '/dev/sd*' you can use (example):

rpi ~$ lsblk -dlno NAME,MOUNTPOINT /dev/sd??*
/dev/sda1 /boot
/dev/sdb1 /mnt/disk
rpi ~$

To start apache service you can use:

rpi ~$ sudo systemctl start apache2.service

This will do nothing if the service is already started. For mounting the block devices you use the normal mount command, e.g.:

rpi ~$ sudo mount /dev/sdb1 /mount_folder/sdb1
rpi ~$ sudo mount /dev/sdb2 /mount_folder/sdb2
  • @ParthManiar I'm glad to help you. May it be possible that you accept the answer (the tick on the left side)? This finishes your question and others can see in overviews that the question has an answer.
    – Ingo
    Nov 14, 2018 at 11:29
  • Done. Pardon me for missing out on that. Nov 14, 2018 at 11:40
  • Can you guide me to have a loop in place for this? It should check for mount and service status and only start / mount in case it finds it off / unmounted. I know that starting apache in case it is already on has no effects but I would like to have this in a loop only to initiate if there's a failure. :) Nov 14, 2018 at 11:46
  • @ParthManiar yes, no problem, but it's difficult to do it in this question. This is finished. Comments are not the right way to do it. The best is you make a new question.
    – Ingo
    Nov 14, 2018 at 11:53
  • @ParthManiar But I'm afraid that it can be voted to close (5 votes required) because it's not really belonging to Raspberry Pi. It is bash programming.
    – Ingo
    Nov 14, 2018 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.