Hi,
A while read loop would be a start.
while read -r line; do
echo "$line"
done < <(blkid -o list)
Now to test if you have
mswin764bit
Add a test pattern matching to see if mswin764bit is in the output of blkid -o list
while read -r line; do
$line = *mswin764bit* ]] && echo "$line"
done < <(blkid -o list)
If you want to just test if a pattern is in the output of blkid then you can just use grep or exit with an error message if there is no match.
Label=mswin764bit
grep -q "$Label" < <(ListDisk) || die "Sorry can't find disk/partition with the label: $Label"
where die is a function that needs a warn function, of course this warn and die function should be define first before you can use it. Meaning this code below should go first before the grep or any other line of code that you want to use the warn and die function.
warn() {
printf '%s
' "${BASH_SOURCE##*/}: $*" >&2
}
die() {
local st=0
case $2 in
*^0-9]*|'') :;;
*) st=$2;;
esac
warn "$1"
exit "$st"
}
Here is how i would do it.
First define the variables so it is easy to just change the values in the future.
Label=mswin764
CheckMount='(not mounted)'
MountPoint='/mnt'
regex1=$Label.+$CheckMount
regex2=$Label.+\/.+
Define a function for blkid including it’s options.
ListDisk() {
blkid -o list
}
First check if there is indeed a disk with the Label you have defined
grep -q "$Label" < <(ListDisk) || die "Sorry can't find disk/partition with the label: $Label"
Now parse ListDisk which is function that calls blkid and it’s options, with a while read loop and some test for regex that you have defined.
while read -r line; do
if $line =~ $regex1 ]]; then
Disk=${line%% *}
mount "$Disk" "$MountPoint" || die "$Disk cannot be mounted on $MountPoint!"
printf '%s
' "${Disk} has been mounted on $MountPoint"
elif $line =~ $regex2 ]]; then
Disk=${line%% *}
line="${line#*$Label}"
line="${line% *}"
printf '%s
' "$Disk is already mounted on ${line// }"
fi
done < <(ListDisk)
The code above has some PARAMETER EXPANSION to extract the disk and it’s label plus some regex (which I’m not good at ) to test for a match.
It should mount your partition in /mnt if it is not mounted and print a message if it is already mounted.
Now the last thing is to add your actual clamav script/code and point it to /mnt or anywhere/place/directory that you have defined as the mount point.
clamav blah..blah.. /mnt
Of course if you need to unmount that partition then you need to add the umount command.
You can take that code piece by piece and see how it works. Again that code is just an example of how I would do it and I’m not saying that is correct nor best approach but at least it is a working bash solution. 