Here is a gallery of simple-minded scripts to give you ideas for making your own. The absence of explicit testing in cfengine programs also makes these scripts transparent while offering a higher level of checking for no cost to the programmer. Similar shell scripts with this property would be complex indeed.
Here is an example script for tidying old files in your own login area.
If you want a long diagnostic, add the option -v
to the first
line of the script, before -f
.
#!/usr/local/bin/cfengine -f # # Tidy # control: actionsequence = ( tidy ) tidy: $(HOME) pat=core r=inf age=0 $(HOME) pat=*~ r=inf age=1 $(HOME) pat=#* r=inf age=7 $(HOME)/code pat=*.o r=inf age=7 $(HOME)/tex pat=*.dvi r=inf age=7 $(HOME)/tex pat=*.log r=inf age=7 $(HOME)/tex pat=*.aux r=inf age=7 $(HOME)/ftp pat=*.zip r=inf age=7
#!/local/gnu/bin/cfengine -f # # Open my shared directory for others in my group # # control: actionsequence = ( files ) gr = ( myshare ) files: $(HOME) mode=0755 action=fixdirs r=0 $(HOME)/share mode=0664 action=fixall r=inf group=$(gr)
In this example, first your home directory is opened for the world, then
all files in the subdirectory share
and subdirectories are
opened to the group myshare
. This script could be made to run
from a login/logout script of some kind (either .login
or
.xsession
) so that any new files would automatically be
controlled.
A straightforward script could be used to clear space in cases where the disk hits the overflow level. This script tidies the whole system, not just the affected disk.
#!/local/gnu/bin/cfengine -f # # Emergency tidyup! # # (Users read their cfengine.rm files to see what got deleted!) # control: site = ( mysite ) mountpattern = ( $(site)/$(host) ) homepattern = ( u? ) actionsequence = ( tidy ) tidy: home pattern=core R=inf age=0 home pattern=*~ R=inf age=0 home pattern=*.dvi R=inf age=1 home pattern=*.o R=inf age=0 /tmp pattern=* R=inf age=0 # could be risky /usr/tmp pattern=* R=inf age=0 # " ignore: .X11
The following script could be used as part of a software installation procedure.
Note that the link types can be made relative to the from-link by using
type=relative
See section links.
#!/tmp/cfengine -v -f # # Simple example script to make links # control: actionsequence = ( links ) links: host:: /usr/local/bin +> /usr/local/lib/soft/bin /usr/local/X11/lib/app-defaults +> /usr/local/lib/soft/app-defaults
It makes links from every binary file in the packages `bin' directory to
the more standard binary directory /usr/local/bin
. This avoids
having to place another search directory into the users' path
variable. The second statement links the package's application defaults
files (for the X-windows system) to a directory in the
XAPPLRESDIR
search path.
This script provides only one way of making the necessary files available to users. It is not the only solution to the problem.
This script carries out the necessary for setting up a safe anonymous ftp server on a sun workstation running SunOS4.1.
#!/local/gnu/bin/cfengine -f ############################################################## # # Cfengine script to set up an outgoing ftp server under # SunOS 4.1.*. Suitable for anonymous access. # ############################################################### control: addclasses = ( local global ) actionsequence = ( editfiles.global directories shellcommands files editfiles.local ) ftp_root = ( /oih/saga/local/ftp ) # macro for convenience ftp_id = ( 99 ) # uid/gid for ftp ################################################################ editfiles: # Note the file /etc/ftpusers can contain a list of users # who can NOT use ftp to access files. global:: { /etc/passwd AppendIfNoSuchLine "ftp:*:$(ftp_id):$(ftp_id): (line continues) Anonymous ftp:$(ftp_root):/usr/ucb/ftp" } { /etc/group AppendIfNoSuchLine "ftp:*:$(ftp_id):" } ################################################################ directories: $(ftp_root) mode=0555 owner=ftp $(ftp_root)/pub mode=0555 owner=ftp $(ftp_root)/bin mode=0555 owner=root $(ftp_root)/usr mode=0555 owner=root $(ftp_root)/dev mode=0555 owner=root $(ftp_root)/etc mode=0555 owner=root $(ftp_root)/dev mode=0555 owner=root $(ftp_root)/usr/lib mode=0555 owner=root ############################################################### shellcommands: "/bin/cp /bin/ls $(ftp_root)/bin/ls" "/bin/cp /lib/libc.so.1.8* $(ftp_root)/usr/lib" "/bin/cp /usr/lib/ld.so $(ftp_root)/usr/lib" "/bin/cp /usr/lib/libdl.so.1.0 $(ftp_root)/usr/lib/libdl.so.1.0" "/usr/etc/mknod $(ftp_root)/dev/zero c 3 12 > /dev/null 2>&1" ########################################################################## files: $(ftp_root)/bin/ls mode=111 owner=root action=fixall $(ftp_root)/usr/lib mode=555 owner=root action=fixall r=1 $(ftp_root)/etc/passwd mode=444 owner=root action=touch $(ftp_root)/etc/group mode=444 owner=root action=touch $(ftp_root)/pub mode=644 owner=root action=fixall ################################################################ editfiles: local:: { $(ftp_root)/etc/passwd AppendIfNoSuchLine "ftp:*:$(ftp_id):$(ftp_id): (line continues) Anonymous ftp:$(ftp_root):/usr/ucb/ftp" } { $(ftp_root)/etc/group AppendIfNoSuchLine "ftp:*:$(ftp_id):" }
Go to the first, previous, next, last section, table of contents.