On 03/27/15 at 10:53am, Baoquan He wrote:
On 03/26/15 at 05:16pm, Baoquan He wrote:
+# the value of $_mntpoint will be +# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the +# directory is bind mounted. The former part represents the device path, rest +# part is the bind mounted directory which quotes by bracket "[]". +get_bind_mount_directory() +{
- local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}')
- local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}')
- _mntpoint=${_mntpoint#*$_mntpoint_nofsroot}
- _mntpoint=${_mntpoint#[}
- _mntpoint=${_mntpoint%]}
Here please consider sed command too. it definitely will be simpler. I don't like a big block for only such an action. And the condition checking is very clear for sed command.
And try this. It's a usual method
-bash-4.2# findmnt /var TARGET SOURCE FSTYPE OPTIONS /var /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var] xfs rw,relat -bash-4.2# findmnt /var| grep "[" | sed "s/(.*)[(.*)](.*)/\2/" /ostree/deploy/rhel-atomic-host/var
Hi, Bao.
The regular expression may fail to filter out the bind mounted path, if the device name has bracket, like "/dev/mapper/atomicos-[root]".
- _mntpoint=${_mntpoint#*$_mntpoint_nofsroot}
Now the $_mntpoint's value is "[/ostree/deploy/rhel-atomic-host/var]", so removing the first '[' and last ']' is ok.
Thanks Minfei