I have a list of scsi disks that I need to remove. The list is considered random at best and changes from time to time. I want to remove everything except a predefined list that I have created. Let's assume for now that I only want to keep:
The command I need to execute is:
"echo 1 > /sys/block/sdX/device/delete"
Where X is the device to be removed.
I'm not good at bash scripting so I don't really know where to start.
To recap so I don't get DV'd for not being clear.
I need to "echo 1 > /sys/block/sdX/device/delete" for every sdX device on the system except for a predetermined list.
EDIT: After the answer below, this is what I've decided to use. "LocalDisks.txt" should contain lines like "/dev/sda"
#!/bin/bash exclude=$(cut -d/ -f3 LocalDisks.txt) for sysfile in /sys/block/sd* ; do dev=$(basename $sysfile) del=$sysfile/device/delete if [[ $exclude == *$dev* ]] ; then echo "Device $dev excluded" elif [ ! -w $del ] ; then echo "$del does not exist or is not writable" else echo 1 > $del fi done