views:

178

answers:

1

Hello,

This is what I want to do,

  • insert USB flash drive.
  • mount it.
  • record uniquie identifer string to a file.
  • format the drive to FAT32.
  • copy a text file to the drive.
  • unmount it.
  • remove the drive.

30 times

The situation is this, I have bought 30 usb drives. I need to format each one to ensure they are clean, I need the unique string from each device. I need to put the same txt file on each one.

I am not great at writing scripts but can read and follow bash and python.

Any pointers would be appreciated.

edit

Thank you for your resposes.

Here is what I have got so far, in windows.

I used USBDeview from nirsoft.net options > advanced options > "execute the following command when you insert a USB device" and used the following command "python getserial.py %serial_number%"

the getserial.py script puts the %serial_number% passed from USBDeview into a text file, then copies a file to the USB device.

import sys
import shutil

sourceFile = "C:\\^READ ME.txt"
destinationFile = "E:\\^READ ME.txt"

f = open('serials.txt', 'a')
f.write(sys.argv[1] + '\n')
f.close()

from time import sleep

sleep(3)

shutil.copyfile(sourceFile, destinationFile)

Would still be interested in a full script that could do this but I think it is beyond my capabilities at the moment.

+2  A: 

In order to automatically detect an inserted USB flash drive, you could use autofs. Unfortunately it is not able to run a script when a device is inserted, otherwise the other steps could be performed quite easily.

So, you need to detect that autofs mounted a new flash drive. crontab might be a solution to periodically check whether a disk is mounted and if so your steps could be performed. Only thing is to detect whether you already processed the mounted disk or not (ie the disk is new or not)

In order to find the UUID you could take a look at ls /dev/disk/by-uuid or blkid and using their output to actually grab the UUID. Formatting your drive could be done using something like mkfs -t vfat /dev/<your usb drive here>.

Hopefully these pointers help you solving your problem.

Veger
thank you for the response, this has pointed me in the right direction. Sorry I can't vote up, (new here).
samsixty