Forum: Cfengine Help
Subject: Parsing fstab
Author: Beto
Link to topic: https://cfengine.com/forum/read.php?3,20565,20565#msg-20565
Hey folks, this is going to be a bit lengthy so fasten your seat belts.
I have a simple requirement: ensure nfs file sytems in fstab are mounted.
My method is to read fstab into a list and then grep the nfs entries from the
list. But I cannot get the grep to work at all. This is what I'm testing with:
body common control
{
bundlesequence => { "test" };
}
bundle agent test
{
vars:
"Fstab" string => "/home/root/fstab";
"fstab"
slist => readstringlist(
"/home/root/fstab",
"#.*",
"\n",
"32",
"2048"
);
"nfs"
slist => grep(".* nfs .*","fstab");
"list1"
slist => { "nfs$(const.n)", "nfs1", "anfs", "anfs1", "xxx nfs
xxx" };
"list2"
slist => { "/dev/vg02/lvol3 /var/opt/applmgr vxfs
rw,suid,largefiles,delaylog,nodatainlog 0 2",
"adama:/var/opt/applmgr/PRISTINE
/var/opt/applmgr/PRISTINE nfs rw,suid,soft 0 0"
};
"grep1"
slist => grep(".*nfs.*","list1");
"grep2"
slist => grep(".*nfs.*","list2");
classes:
"nfsfound"
expression => reglist("@(fstab)",".*nfs.*");
reports:
linux|hpux::
"------------ All mounts -----------";
"$(fstab)";
"------------ NFS mounts -----------";
"$(nfs)";
"------------ grep test 1 ----------";
"$(grep1)";
"------------ grep test 2 ----------";
"$(grep2)";
"----------- reglist test -----------";
nfsfound::
"NFS found in list";
}
and
/dev/vg00/lvol3 / vxfs log 0 1
/dev/vg00/lvol1 /stand vxfs tranflush 0 1
/dev/vg00/lvol4 /tmp vxfs delaylog 0 2
/dev/vg00/lvol5 /home vxfs nosuid,delaylog 0 2
/dev/vg00/lvol6 /opt vxfs delaylog 0 2
/dev/vg00/lvol7 /usr vxfs delaylog 0 2
/dev/vg00/lvol8 /var vxfs delaylog 0 2
/dev/vg01/lvol1 /u01 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg01/lvol2 /u02 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg01/lvol3 /u03 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg01/lvol4 /u04 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg01/lvol5 /u05 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg01/lvol6 /u06 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg02/lvol1 /opt/oracle vxfs rw,suid,largefiles,delaylog,nodatainlog 0 2
/dev/vg02/lvol2 /u07 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
/dev/vg02/lvol3 /var/opt/applmgr vxfs rw,suid,largefiles,delaylog,nodatainlog 0
2
adama:/var/opt/applmgr/PRISTINE /var/opt/applmgr/PRISTINE nfs rw,suid,soft 0 0
adama:/var/opt/applmgr/TEST /var/opt/applmgr/TEST nfs rw,suid,soft 0 0
I am never able to grep nfs entries from fstab or from list2 as shown by the
lack of report output under "NFS mounts" and "grep test 2":
plucky:/home/root/inputs# /usr/local/sbin/cf-agent -Kf ./nfs_mount.cf
R: ------------ All mounts -----------
R: /dev/vg00/lvol3 / vxfs log 0 1
R: /dev/vg00/lvol1 /stand vxfs tranflush 0 1
R: /dev/vg00/lvol4 /tmp vxfs delaylog 0 2
R: /dev/vg00/lvol5 /home vxfs nosuid,delaylog 0 2
R: /dev/vg00/lvol6 /opt vxfs delaylog 0 2
R: /dev/vg00/lvol7 /usr vxfs delaylog 0 2
R: /dev/vg00/lvol8 /var vxfs delaylog 0 2
R: /dev/vg01/lvol1 /u01 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg01/lvol2 /u02 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg01/lvol3 /u03 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg01/lvol4 /u04 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg01/lvol5 /u05 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg01/lvol6 /u06 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg02/lvol1 /opt/oracle vxfs rw,suid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg02/lvol2 /u07 vxfs rw,nosuid,largefiles,delaylog,nodatainlog 0 2
R: /dev/vg02/lvol3 /var/opt/applmgr vxfs
rw,suid,largefiles,delaylog,nodatainlog 0 2
R: adama:/var/opt/applmgr/PRISTINE /var/opt/applmgr/PRISTINE nfs rw,suid,soft 0 0
R: adama:/var/opt/applmgr/TEST /var/opt/applmgr/TEST nfs rw,suid,soft 0 0
R: ------------ NFS mounts -----------
R: ------------ grep test 1 ----------
R: nfs1
R: anfs
R: anfs1
R: xxx nfs xxx
R: ------------ grep test 2 ----------
R: ----------- reglist test -----------
R: NFS found in list
Anyone have any ideas? I'm testing and get the same result with 3.0.5p1 and
3.1.5a1.
Is there a better way to address the requirement?
Thanks in advance for any suggestions.
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine