function

exec . files . sncode

VERSIONlatest Use to exec file.

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:

  • YYYY-MM-DD HH:MM:SS using parameter date
  • at format using paramater atdate. This is OS dependent. The at utility allows some moderately complex time specifications. It accepts times of the form HHMM or HH:MM to run a job at a specific time of day. (If that time is already past, the next day is assumed.) As an alternative, the following keywords may be specified: midnight, noon, or teatime (4pm) and time-of-day may be suffixed with AM or PM for running in the morning or the evening. The day on which the job is to be run may also be specified by giving a date in the form month-name day with an optional year, or giving a date of the forms DD.MM.YYYY, DD.MM.YY, MM/DD/YYYY, MM/DD/YY, MMDDYYYY, or MMDDYY. The specification of a date must follow the specification of the time of day. Time can also be specified as: [now] + count time-units, where the time- units can be minutes, hours, days, weeks, months or years and at may be told to run the job today by suffixing the time with today and to run the job tomorrow by suffix- ing the time with tomorrow.

    For example, to run a job at 4pm three days from now, use at 4pm + 3 days, to run a
    job at 10:00am on July 31, use at 10am Jul 31 and to run a job at 1am tomorrow, use at
    1am tomorrow.

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.*

AUTHOR

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