I am writing a perl script which uses some fields from "df" command.
my $command = "df -a";
my $output = `$command`;
# my $outputs = qx/df/;
print "$output\n\n\n";
This is giving me output as follows-
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 4096 8 4088 1% /dev
tmpfs 40925604 24 40925580 1% /dev/shm
tmpfs 9864920 9180 9855740 1% /run
tmpfs 4096 0 4096 0% /sys/fs/cgroup
/dev/sda3 20937708 12632092 8305616 61% /
/dev/sda2 20422 6266 14156 31% /boot/efi
/dev/sdb 41922560 5476428 36446132 14% /data
tmpfs 4932456 0 4932456 0% /run/user/0
bkpteam:/swdepot 587202560 308491328 278711232 53% /mnt
tmpfs 4932456 0 4932456 0% /run/user/58037
server_name:/db_share/Restore_NewDB/ABC_import/trans 25163737088 2580348928 22583388160 11% /xyz/ABC/trans
However, when I execute "df -a" command directly on Linux, i am getting the following output-
Filesystem Size Used Avail Use% Mounted on
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
devtmpfs 4.0M 8.0K 4.0M 1% /dev
securityfs 0 0 0 - /sys/kernel/security
tmpfs 40G 24K 40G 1% /dev/shm
devpts 0 0 0 - /dev/pts
tmpfs 9.5G 9.0M 9.4G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
cgroup2 0 0 0 - /sys/fs/cgroup/unified
cgroup 0 0 0 - /sys/fs/cgroup/systemd
pstore 0 0 0 - /sys/fs/pstore
efivarfs 0 0 0 - /sys/firmware/efi/efivars
bpf 0 0 0 - /sys/fs/bpf
cgroup 0 0 0 - /sys/fs/cgroup/cpu,cpuacct
cgroup 0 0 0 - /sys/fs/cgroup/net_cls,net_prio
cgroup 0 0 0 - /sys/fs/cgroup/perf_event
cgroup 0 0 0 - /sys/fs/cgroup/freezer
cgroup 0 0 0 - /sys/fs/cgroup/blkio
cgroup 0 0 0 - /sys/fs/cgroup/misc
cgroup 0 0 0 - /sys/fs/cgroup/hugetlb
cgroup 0 0 0 - /sys/fs/cgroup/devices
cgroup 0 0 0 - /sys/fs/cgroup/memory
cgroup 0 0 0 - /sys/fs/cgroup/cpuset
cgroup 0 0 0 - /sys/fs/cgroup/pids
cgroup 0 0 0 - /sys/fs/cgroup/rdma
/dev/sda3 20G 13G 8.0G 61% /
systemd-1 - - - - /proc/sys/fs/binfmt_misc
debugfs 0 0 0 - /sys/kernel/debug
mqueue 0 0 0 - /dev/mqueue
tracefs 0 0 0 - /sys/kernel/tracing
hugetlbfs 0 0 0 - /dev/hugepages
fusectl 0 0 0 - /sys/fs/fuse/connections
configfs 0 0 0 - /sys/kernel/config
none 0 0 0 - /run/credentials/systemd-sysusers.service
/dev/sda2 20M 6.2M 14M 31% /boot/efi
/dev/sdb 40G 5.3G 35G 14% /data
tracefs 0 0 0 - /sys/kernel/debug/tracing
tmpfs 4.8G 0 4.8G 0% /run/user/0
bkpteam:/swdepot 560G 295G 266G 53% /mnt
tmpfs 4.8G 0 4.8G 0% /run/user/58037
binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
/dev/sdb 40G 5.3G 35G 14% /usr/FFF
/dev/sdb 40G 5.3G 35G 14% /xyz/ABC
servername:/db_share/Restore_NewDB/ABC_import/trans 24T 2.5T 22T 11% /xyz/ABC/trans
Later on in the script, i have a regex which captures lines containing the either "/xyz/ABC" or "/usr/FFF".
You can see that "df" command, when ran in linux, contain 3 such lines as follows-
servername:/db_share/Restore_NewDB/ABC_import/trans 24T 2.5T 22T 11% /xyz/ABC/trans
/dev/sdb 40G 5.3G 35G 14% /usr/FFF
/dev/sdb 40G 5.3G 35G 14% /xyz/ABC
However, the 'df -a' output in perl script does not capture the last two lines mentioned in the expected results. The filesystem in Linux is such that "/dev/sdb" has 3 mounts present on it and "df -a" executed vua perl script is able to capture only the first entry which does not contain either of the regex.
This is messing up with the flow of the script as we need the values "/xyz/ABC" or "/usr/FFF". We don't directly use "/xyz/ABC" or "/usr/FFF" as ABC and FFF are script inputs and further used in other logic involving some nested paths.
Please help in the situation, how to capture the entire "df" output by perl script.