-3

I need to have a script that instructs the system to run an fsck on a drive but I only want it to run if the drive is not mounted "/dev/mmcblk0p2 /mnt/Share ext4 defaults 0 2"

Basically is it possible to either

  1. tell it to run "fsck /dev/mmcblk0p2 yes Y | command-that-asks-for-input" after the attempted mount fails

Or

  1. Tell it to run "fsck /dev/mmcblk0p2 (no to first question then) yes Y | command-that-asks-for-input"

Thanks so much oh great and powerful men behind the curtains. May the force be with you.

Thanks guys!

1 Answers1

-1

You could use the mount command to check if the drive is mounted. Use grep to check if the output includes the desired partition/drive. Use the || operator to run your command if the partition is not mounted.

mount | grep /dev/mmcblk0p2 > /dev/null || fsck/dev/mmcblk0p2 ...

slarag
  • 139
  • I think you'll find that you need sudo to run fsck Permission denied while trying to open /dev/sda1 You must have r/w access to the filesystem or be root – Elder Geek Jan 24 '24 at 02:25