EXEC

NAME

exec - Use to exec file.

SYNOPSIS

exec([error:var, ldd:"parameters", date:"YYYY-MM-DD HH:MM:SS", atdate:"", timeout:"30",sleep_interval:1000 errofile:"…", outputfile:"…",keepfiles:true|false,] "path to exec file", "args…");

DESCRIPTION

This function is used to execute an external program.

The exec file must be own by root and be executable by root for security reason.

The function can also be used to execute the program via at. Using at a program can be executed at a later time. Date for at can be specified in 2 formats:

LDD can be used to insert commands at the beginnging of the exec file for command at.

TIMEOUT is used to stop the program after the number of seconds specified in timeout. If the timeout is zero, there is no timeout

SLEEP_INTERVAL is the sleep interval between each check for timeout. The sleep_interval is specified in micro-seconds.

KEEPFILES is a boolean parameters used to specified is we keep output file, error file.

OUTPUT is used to specified the output file. If none is specified, a temporary file is used.

ERROR is used to specified the error file. If none is specified, a temporary file is used.

RETURN

Exec will return the following variables:

- exitcode : Exit from from the script

- output : output of the script

- outputfile : where the output file is

- errorfile : where the error output file is

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

res={_{ exec(date:"...",atdate:"...","/tmp/xxx"); }}. return
.*Arguments date and atdate.*

res={_{ exec("/tmp/xxx"); }}. return .*stat file /usr/local/website/v5/tmp/xxx.*

res={_{ exec("/tests/exec"); }}. return .*does not belong to user 0.*

res={_{ exec("/logs"); }}. return .*is not a regular file.*

res={_{ exec("/tests/noexec"); }}. return .*is not executable.*

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec", "sleep", "10"); a.status;}}.
return res=kill.

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec", "sleep", "10");
a.status;a.exitcode}}. return res=kill9.

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec");
a.status; a.exitcode}}. return res=ok0.

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec", "exitcode", 4);
a.exitcode; }}. return res=4.

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec", "exitcode", 5);
a.exitcode; }}. return res=5.

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec", "exitcode", 5);
a.output; }}. return res=.*with code 5.*

res={_{ a=exec(timeout:2,sleep_interval:100000,"/tests/testexec", "exitcode", 5);
-e a.outputfile; }}. return res=false.

res={_{ a=exec(keepfiles:true,timeout:2,sleep_interval:100000,"/tests/testexec",
"exitcode", 5); -e a.outputfile; }}. return res=true.

res={_{ a=exec(outputfile:"/tmp/pierre",keepfiles:true,timeout:2,
sleep_interval:100000,"/tests/testexec", "exitcode", 5);
-e a.outputfile; a.outputfile}}. return res=true/tmp/pierre.

res={_{
                a=exec(atdate:"now+5m",timeout:2,sleep_interval:100000,
                "/tests/testexec", "exitcode", 5);
                if a.error =~ "^job\s+(\d+)" then
                        job=getre(1);
                        job;
                        a=exec("/tests/testexec","atrm",job);
                        a;
                endif
        }}. return res=.*atrm job.*

res={_{
                a=exec(date:"2017-05-06 11:32:44",timeout:2,sleep_interval:100000,
                "/tests/testexec", "exitcode", 5);
                if a.error =~ "^job\s+(\d+)" then
                        job=getre(1);
                        job;
                        a=exec("/tests/testexec","atrm",job);
                        a;
                else
                        a;
                endif
        }}. return res=.*atrm job.*

SEE ALSO

Files

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com