Executing the SYSTEM statement on UNIX

In SPL procedures for UNIX™ platforms, a specification that evaluates to a valid UNIX operating system command must immediately follow the SYSTEM keyword.

Both of the program fragments that follow use the SYSTEM statement of SPL to send a message to the system administrator.
  • In the first example, the sensitive_update routine defines an SPL variable called mailcall to store a character string that specifies the name of the mail utility, and the user ID of the message recipient, and the message text.
  • In the second example, the sensitive_update2 routine similarly invokes the mail utility with a SYSTEM statement. The expression constructs a valid command line by concatenating three quoted strings and the SPL variables user1 and user2 to send to the system administrator a file called violations_file.

Sending email using the SYSTEM statement

The SYSTEM statement in the following example of an SPL routine causes the UNIX operating system to send a mail message to the system administrator whose user ID is headhoncho:
CREATE PROCEDURE sensitive_update()
   ...
   LET mailcall = 'mail headhoncho < alert';
   -- code to execute if user tries to execute a specified
   -- command, then sends email to system administrator
   SYSTEM mailcall;
   ...
END PROCEDURE; -- sensitive_update
You can use a double-pipe symbol ( || ) to concatenate expressions within a SYSTEM statement, as the following example shows:
CREATE PROCEDURE sensitive_update2()
   DEFINE user1 char(15);
   DEFINE user2 char(15);
   LET user1 = 'joe';
   LET user2 = 'mary';
   ...
   -- code to execute if user tries to execute a specified
   -- command, then sends email to system administrator
   SYSTEM 'mail -s violation' || user1 || ' ' || user2
                || '< violation_file';
   ...
END PROCEDURE; --sensitive_update2 

In both examples above, blank spaces separate elements of the command line, so the expression that follows the SYSTEM keyword evaluates to a character string that conforms to the syntax requirements of the operating system mail utility.