Message ID | 20211027075615.19832-1-pvorel@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | [v2,1/1] ver_linux: Print filesystems | expand |
Hi! > +echo 'mounted filesystems (df):' > +df_opt= > +if ! (df -h 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -h"; fi > +if ! (df -T 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -T"; fi Uff that's ugly, can't we simply depend on df returning non-zero on invalid option? > +df $df_opt > + > echo > if is_enabled /sys/module/apparmor/parameters/enabled; then > echo 'AppArmor enabled' > -- > 2.33.1 > > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril, > Hi! > > +echo 'mounted filesystems (df):' > > +df_opt= > > +if ! (df -h 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -h"; fi > > +if ! (df -T 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -T"; fi > Uff that's ugly, can't we simply depend on df returning non-zero on > invalid option? On real HW (2 laptops with different linux distros) it fails for something else: $ df -hT; echo $? df: /run/user/1000/doc: Operation not permitted 1 If you want simpler form, I suggest df -hT 2>/dev/null || df instead of: df -hT 2>/dev/null || df -h Which version should I merge? Kind regards, Petr
Hi! > If you want simpler form, I suggest > df -hT 2>/dev/null || df Looks good.
> Hi! > > If you want simpler form, I suggest > > df -hT 2>/dev/null || df > Looks good. Ah, sorry, I see why I checked it more complicated way: with simply checking exit code you have output twice: df -hT 2>/dev/null || df Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 16G 8,0K 16G 1% /dev tmpfs tmpfs 16G 91M 16G 1% /dev/shm tmpfs tmpfs 6,2G 4,1M 6,2G 1% /run ... df: /run/user/1000/doc: Operation not permitted Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 16G 8,0K 16G 1% /dev tmpfs tmpfs 16G 91M 16G 1% /dev/shm tmpfs tmpfs 6,2G 4,1M 6,2G 1% /run ... => which is IMHO nogo. I could redirect to a file and cut it after, but in that case v2 is IMHO much better. Kind regards, Petr
Hi! > Ah, sorry, I see why I checked it more complicated way: > with simply checking exit code you have output twice: > > df -hT 2>/dev/null || df > Filesystem Type Size Used Avail Use% Mounted on > devtmpfs devtmpfs 16G 8,0K 16G 1% /dev > tmpfs tmpfs 16G 91M 16G 1% /dev/shm > tmpfs tmpfs 6,2G 4,1M 6,2G 1% /run > ... > df: /run/user/1000/doc: Operation not permitted > Filesystem Type Size Used Avail Use% Mounted on > devtmpfs devtmpfs 16G 8,0K 16G 1% /dev > tmpfs tmpfs 16G 91M 16G 1% /dev/shm > tmpfs tmpfs 6,2G 4,1M 6,2G 1% /run > ... > > => which is IMHO nogo. I could redirect to a file and cut it after, but in that > case v2 is IMHO much better. But still we don't need that grep part, right? So it should be something as: if `df -hT 2>/dev/null >/dev/null`; then df -hT else df fi
> Hi! > > Ah, sorry, I see why I checked it more complicated way: > > with simply checking exit code you have output twice: > > df -hT 2>/dev/null || df > > Filesystem Type Size Used Avail Use% Mounted on > > devtmpfs devtmpfs 16G 8,0K 16G 1% /dev > > tmpfs tmpfs 16G 91M 16G 1% /dev/shm > > tmpfs tmpfs 6,2G 4,1M 6,2G 1% /run > > ... > > df: /run/user/1000/doc: Operation not permitted > > Filesystem Type Size Used Avail Use% Mounted on > > devtmpfs devtmpfs 16G 8,0K 16G 1% /dev > > tmpfs tmpfs 16G 91M 16G 1% /dev/shm > > tmpfs tmpfs 6,2G 4,1M 6,2G 1% /run > > ... > > => which is IMHO nogo. I could redirect to a file and cut it after, but in that > > case v2 is IMHO much better. > But still we don't need that grep part, right? > So it should be something as: > if `df -hT 2>/dev/null >/dev/null`; then > df -hT > else > df > fi Yep, how simple, thanks! Kind regards, Petr
> > => which is IMHO nogo. I could redirect to a file and cut it after, but in that > > case v2 is IMHO much better. > But still we don't need that grep part, right? > So it should be something as: > if `df -hT 2>/dev/null >/dev/null`; then > df -hT > else > df > fi Merged this version, thanks! Kind regards, Petr
diff --git a/ver_linux b/ver_linux index 824c39510..82b7468a6 100755 --- a/ver_linux +++ b/ver_linux @@ -138,6 +138,21 @@ echo echo 'cpuinfo:' tst_cmd_run lscpu || cat /proc/cpuinfo +echo +echo 'available filesystems:' +echo $(cut -f2 /proc/filesystems | sort -u) + +echo +echo 'mounted filesystems (/proc/mounts):' +cat /proc/mounts + +echo +echo 'mounted filesystems (df):' +df_opt= +if ! (df -h 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -h"; fi +if ! (df -T 2>&1 | grep -i -q -e 'unknown option' -e 'invalid option'); then df_opt="$df_opt -T"; fi +df $df_opt + echo if is_enabled /sys/module/apparmor/parameters/enabled; then echo 'AppArmor enabled'
both available and mounted. check for options as aosp toybox does not support -h, -T option requires IF_FEATURE_HUMAN_READABLE on busybox. Signed-off-by: Petr Vorel <pvorel@suse.cz> --- changes v1->v2: properly check options ver_linux | 15 +++++++++++++++ 1 file changed, 15 insertions(+)