How to check usb device with if statement in bash

I am trying to create an automated bash script that populates a file using urandom in the flash memory of a device. I can manually use all the commands to make this happen, but I'm trying to create a script and having difficulty figuring out how to test a USB device. I know this will be either sda1 or sdb1, but not sure if the code below is enough ...? Thank you Below is the code:

if /dev/sda1
then
         mount -t vfat /dev/sda1 /media/usbkey
else
         mount -t vfat /dev/sdb1 /media/usbkey
fi
+5
source share
2 answers

UUID , , script. , - MYLABEL ( VFAT mtools 'mlabel)

$ sudo mount LABEL=MYLABEL /media/usbkey
+6

script , , . "Iamthemountabledrive.txt", . , . , , 5 , , .

testfile="/dev/usbdrive/Iamthedrive.txt"
if [ -e "$testfile" ]
then
  echo "drive is mounted."
fi
+6

All Articles