1

I have an encrypted USB dongue with cryptosetup, to mount it I have to execute a script that has hardcoded (or admits it as a parameter) the device name of that dongue that previously you had to search.

I wonder is there is any way via bash scripting or even doing a miniprogram to make an autodetection of the device name, leaving the workflow something like this:

  • Connect USB dongue
  • Execute script
  • Script searches for the device name of the dongue and mounts the device
  • Cryptosetup asks for the password
  • Device is mounted

1 Answer 1

1

The device name should appear in dmesg. Try something like this:

dev_name="/dev/"`dmesg | perl -ne '/.+\[(.+?)\] Attached/ && do{print "$1\n"}' | tail -n 1`

Assuming that your USB dongle is the last device attached (hence the tail -n1), this should save the device name as $dev_name.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .