Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

Commands, scripts, and execution examples

Suggest changes
Table of contents

Command or script execution

Execute a command, for instance to start a MySQL service. Note that simple shell commands like rm or mkdir cannot be managed by CFEngine, so none of the protections that CFEngine offers can be applied to the process. Moreover, this starts a new process, adding to the burden on the system.

code
bodycommoncontrol{bundlesequence=>{"my_commands"};inputs=>{"$(sys.libdir)/stdlib.cf"};}bundleagentmy_commands{commands:Sunday.Hr04.Min05_10.myhost::"/usr/bin/update_db";any::"/etc/mysql/start"contain=>setuid("mysql");}

Change directory for command

code
bodycommoncontrol{bundlesequence=>{"example"};}bodycontaincd(dir){chdir=>"${dir}";useshell=>"true";}bundleagentexample{commands:"/bin/pwd"contain=>cd("/tmp");}

Commands example

code
bodycommoncontrol{bundlesequence=>{"my_commands"};inputs=>{"$(sys.libdir)/stdlib.cf"};}bundleagentmy_commands{commands:Sunday.Hr04.Min05_10.myhost::"/usr/bin/update_db";any::"/etc/mysql/start"contain=>setuid("mysql");}

Execresult example

code
bodycommoncontrol{bundlesequence=>{"example"};}bundleagentexample{vars:"my_result"string=>execresult("/bin/ls /tmp","noshell");reports:"Variable is$(my_result)";}

Methods

code
bodycommoncontrol{bundlesequence=>{"testbundle"};version=>"1.2.3";}bundleagenttestbundle{vars:"userlist"slist=>{"mark","jeang","jonhenrik","thomas","eben"};methods:"any"usebundle=>subtest("$(userlist)");}bundleagentsubtest(user){commands:"/bin/echo Fix$(user)";reports:"Finished doing stuff for$(user)";}

Method validation

code
bodycommoncontrol{bundlesequence=>{"testbundle"};version=>"1.2.3";}bodyagentcontrol{abortbundleclasses=>{"invalid"};}bundleagenttestbundle{vars:"userlist"slist=>{"xyz","mark","jeang","jonhenrik","thomas","eben"};methods:"any"usebundle=>subtest("$(userlist)");}bundleagentsubtest(user){classes:"invalid"not=>regcmp("[a-z][a-z][a-z][a-z]","$(user)");reports:!invalid::"User name$(user) is valid at 4 letters";invalid::"User name$(user) is invalid";}

Trigger classes

code
bodycommoncontrol{any::bundlesequence=>{"insert"};}bundleagentinsert{vars:"v"string=>"                One potato                Two potato                Three potahto                Four                ";files:"/tmp/test_insert"edit_line=>Insert("$(insert.v)"),edit_defaults=>empty,classes=>trigger("edited");commands:edited::"/bin/echo make bananas";reports:edited::"The potatoes are bananas";}bundleedit_lineInsert(name){insert_lines:"Begin$(const.n)$(name)$(const.n)End";}bodyedit_defaultsempty{empty_file_before_editing=>"true";}bodyclassestrigger(x){promise_repaired=>{$(x)};}

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp