Unwanted Files
In this example, we report the existence of unwanted files--for example, system startup files--also possibly move or delete them.
The SystemFileExist script might send an alert message like the following:
PIKT ALERT Thu Jun 13 9:55:43 2003 padua URGENT: SystemFileExist Report the existence of unwanted files, and possibly move or remove them /etc/rc3.d/S50apache found! doing exec: /usr/bin/mv /etc/rc3.d/S50apache /etc/rc3.d/xS50apache
SystemFileExist makes reference to the =files_unwanted_obj macro, which resolves to the name of the FilesUnwanted.obj file. The script follows.
SystemFileExist // use this to warn about /etc/nologin files, or // unwanted service startup files (in /etc/rc?.d), // for example init status =piktstatus level =piktlevel task "Report the existence of unwanted files, and possibly move or remove them" input file "=files_unwanted_obj" seps ":" dat $name [1] dat $cmd [2] keys $name rule if -e $name set $state = "+" if $cmd eq "." if $state ne %state =daily(output mail "$name found!", ) endif else if %state eq "+" // existed last run, // hence possible rm // or mv $cmd failed // before =daily(output mail "$name found!", ) else =outputmail "$name found! doing exec: $cmd" =execwait $cmd endif endif else set $state = "-" endif
For more examples, see Samples.