Can a Linux script choose between options?
Don't ask me why but we have a script running to read from a specific model of usb device. However the particular device used is now end of life so we now need to use a different model.
I have been able to update the script to use this newer model of usb, however my problem arises because some people still have the old model USB too. So while we integrate the new usb devices and phase out the old ones we need the script to be able to read and run from both. Unfortunately my Linux experience is not quite strong enough to know how to change this script to be able to do this. I realise it is probably extremely simple but I have not come across anything like this before. Any help will be massively useful. this is the script we are running: disk_id () { # Checking if /media/usbdisk is connected df -h | grep -o "/media/usbdisk" > /dev/null 2> /dev/null if [ "$?" = "0" ] then umount /media/usbdisk > /dev/null 2> /dev/null fi # Checking if USB HDD is connected log "Checking if $DEVICE is connected" /usr/sbin/lsusb 2>&1| grep -o "BUFFALO" > /dev/null if [ "$?" != "0" ] then log "USB drive is not connected! Disconnect and reconnect the USB disk!" unlock_key exit 1 fi Basically we want this script to be able to read from both BUFFALO and FREECOM. |
probably this would be sufficient:
Code:
disk_id () |
Hi yogi_ni and welcome to LQ!
I do feel that schneidz' answer is fully correct and I thank them for their expertise. I think it may benefit with the relevant strings which you cited in your original post: Code:
/usr/sbin/lsusb 2>&1| egrep -o "BUFFALO|FREECOM" > /dev/null |
Hi Schneidz,
Thanks for the reply. Im not sure how this would work. We would need to add a second device type in the variables surely? What I was thinking of doing albeit fairly rudimental was inserting a second if statement. Would this work too? # Checking if USB HDD is connected log "Checking if $DEVICE is connected" /usr/sbin/lsusb 2>&1| grep -o "FREECOM" > /dev/null if [ "$?" != "0" ] then /usr/sbin/lsusb 2>&1| grep -o "BUFFALO" > /dev/null if [ "$?" != "0" ] then log "USB drive is not connected! Disconnect and reconnect the USB disk!" unlock_key exit 1 fi fi |
A couple of comments:
|
Quote:
|
a couple of thoughts on this, first of all, maybe UDEV might be a more appropriate tool? and instead looking for a specific UUID for the USB drive instead of a more generic means.
|
All times are GMT -5. The time now is 11:12 PM. |