Re: [CentOS] Need fstab-decode for CentOS 8

2022-02-27 Thread centos

Am 28.02.22 um 05:45 schrieb Robert Nichols:

On 2/27/22 12:26 PM, cen...@niob.at wrote:

Am 27.02.22 um 04:33 schrieb Robert Nichols:
Does anything for CentOS 8 provide the function of the fstab-decode 
utility?
Entries in /proc/mounts and /etc/fstab can have escape sequences for 
certain special characters, and I need to decode that. 


Preface: Never heard of fstab-decode before. Researching the command 
made me really wonder why it was invented. Especially since I have 
never seen an /etc/fstab with "escape sequences" or "special 
characters" since at least 1990 (If I am wrong: Please show me such a 
fstab file).


So why not just use:

 umount $(awk '$3 == "vfat" {print $2}' /etc/fstab)

instead of the seemingly canonical use of fstab-decode

 fstab-decode umount $(awk '$3 == "vfat" { print $2 }' /etc/fstab)


Those samples break if the mount point directory name contains spaces, 
tabs, or whatever other characters I don't know about that also get 
represented by escape sequences. I'm not actually using it with 
/etc/fstab, but with /proc/mounts which uses the same convention. I 
can control /etc/fstab and avoid the problem, but I cannot control how 
some auto-mounted foreign filesystem might be named. I have a script 
that needs to be robust in the face of such names.



Get creative! Unix administration is a creative job. Having said this:

Using white space within mount points is asking for trouble anyway. If 
you really want this in the most generic way, then do the unquoting with 
something like this:


    awk '$3 == "vfat" {print $2}' /etc/fstab | perl -pl000 -e 
's/\\([0-7]{3})/chr(oct($1))/eg' | xargs -0 -n 1 -r umount


This seems to be the unixy way to do this.

If you really need the fstab-decode program put this in a script (if you 
want to be able to use commands with arguments you may choose to remove 
the double quotes in the argument to xargs):



#!/bin/bash
# a simple fstab-decode implementation

CMD="$1"
shift

while [ -n "$1" ] ; do
echo -E "$1"
shift
done | perl -pl000 -e 's/\\([0-7]{3})/chr(oct($1))/eg;' | xargs -0 -n 1 -r 
"$CMD"



Peter
___
CentOS mailing list
CentOS@centos.org
https://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need fstab-decode for CentOS 8

2022-02-27 Thread Robert Nichols

On 2/27/22 12:26 PM, cen...@niob.at wrote:

Am 27.02.22 um 04:33 schrieb Robert Nichols:

Does anything for CentOS 8 provide the function of the fstab-decode utility?
Entries in /proc/mounts and /etc/fstab can have escape sequences for certain special characters, and I need to decode that. 


Preface: Never heard of fstab-decode before. Researching the command made me really wonder why it 
was invented. Especially since I have never seen an /etc/fstab with "escape sequences" or 
"special characters" since at least 1990 (If I am wrong: Please show me such a fstab 
file).

So why not just use:

 umount $(awk '$3 == "vfat" {print $2}' /etc/fstab)

instead of the seemingly canonical use of fstab-decode

 fstab-decode umount $(awk '$3 == "vfat" { print $2 }' /etc/fstab)


Those samples break if the mount point directory name contains spaces, tabs, or 
whatever other characters I don't know about that also get represented by 
escape sequences. I'm not actually using it with /etc/fstab, but with 
/proc/mounts which uses the same convention. I can control /etc/fstab and avoid 
the problem, but I cannot control how some auto-mounted foreign filesystem 
might be named. I have a script that needs to be robust in the face of such 
names.

--
Bob Nichols "NOSPAM" is really part of my email address.
Do NOT delete it.

___
CentOS mailing list
CentOS@centos.org
https://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need fstab-decode for CentOS 8

2022-02-27 Thread centos

Am 27.02.22 um 04:33 schrieb Robert Nichols:
Does anything for CentOS 8 provide the function of the fstab-decode 
utility?
Entries in /proc/mounts and /etc/fstab can have escape sequences for 
certain special characters, and I need to decode that. 


Preface: Never heard of fstab-decode before. Researching the command 
made me really wonder why it was invented. Especially since I have never 
seen an /etc/fstab with "escape sequences" or "special characters" since 
at least 1990 (If I am wrong: Please show me such a fstab file).


So why not just use:

umount $(awk '$3 == "vfat" {print $2}' /etc/fstab)

instead of the seemingly canonical use of fstab-decode

fstab-decode umount $(awk '$3 == "vfat" { print $2 }' /etc/fstab)

Myself, I would use the super-standard xargs, that can even take care of 
the case that there might be no matching lines, that is:


    awk '$3 == "vfat" {print $2}' /etc/fstab | xargs -r umount

And if there REALLY are files around with "special characters" I would 
do it like this:


    awk '$3 == "vfat" {ORS="\0" ; print $2}' /etc/fstab | xargs -0 -r 
umount


I consider this a standard idiom usable for many more use cases than 
just parsing /etc/fstab



Peter

___
CentOS mailing list
CentOS@centos.org
https://lists.centos.org/mailman/listinfo/centos