Script Execution
If an event handler executes a script, standard I/O redirection can be done within the script itself. This method provides a little more flexibility with respect to assigning unique names to files that store captured output. If unique names are needed, logic can be set up within the script to construct the name and to ensure that the file does not already exist.
The following figures illustrate sample scripts that contain logic for generating unique file names.
Bourne Shell Script
UNIX
This sample is a Bourne shell script that uses a combination of environment variables set by the UEM Server, the script's process ID, and the current system date/time in order to construct a unique file name used to store the output of the ls -al command.
#!/bin/sh rc=0 ## Set a date string in the format yyyy.mm.dd. dt=`date +%Y.%m.%d` ## Set a time string in the format hh.mm.ss tm=`date +%H.%M.%S` ## Save the process ID pid=$$ ## Remove the extension from the file tracked by UEM. uemFName=`basename "$UEMORIGFILE" | sed 's/(^.*).(.*)/1/'` ## Construct a filename using the name of the file tracked by UEM, the ## current date, the current time, and the process ID. fname=$uemFName.$dt.$tm.$pid.txt ## Execute the command. Redirect the output to the file name ## constructed above. ls -al >$fname ## Set the return code and exit the script rc=$? exit $rc
Windows Batch File
Windows
This sample is a Windows batch file that uses a combination of environment variables set by the UEM Server and the current system date/time in an attempt to construct a unique file name used to store the output of the dir command. Because multiple instances of this script can be executing at the same time, and a process ID is not available to a Windows batch file, a loop exists to retry the file name construction if a matching file is found.
Note
In both of these examples, the redirection is done at the point at which the process is invoked. If the script itself also generates output that needs to be captured, this file would need to be provided via the event definition's handler options (see Standard IO Redirection and Event Handler Processes - Handler Options.