Mailing Results from the Server

You can use mail to obtain the report results generated when an Production Reporting program is run asynchronously. This avoids having to do a "check if complete" operation when you use asynchronous mode.

You can attach the SPF report as a file to a mail message and mail it out. Since Production Reporting registers the SPF file type in the Windows system registry, many mail programs, such as Outlook, can launch Production Reporting Viewer to view the SPF file attachment.

*  To use mail to obtain the results of an Production Reporting program:

  1. Log into the server.

    Use a login configured to work with SQR Production Reporting Activator; in particular, a login that you can use with the RemoteRun method.

  2. Create the script as the file mailsqr.sh and set its execute permission.

    The first parameter to the script is the user ID of the mail account to which you wish to mail the results. The second parameter is the Production Reporting program filename. The third parameter is the database connectivity.

    The script uses the $$ value to generate a unique SPF filename and ERR filename to avoid multi-user conflicts. The script passes the -f$SPF_FILE and ‑e$ERR_FILE parameters to Production Reporting to cause Production Reporting to generate the SPF and ERR files, respectively. The script also uses the UNIX command uuencode to uu‑encode the generated SPF output file into the mail message. This allows a mail program such as Outlook to display the SPF results as a file attachment. Finally, the script uses the UNIX command mail to send the results using mail.

    The following example shows a Bourne shell script. Adjust the script to the needs of your particular server environment.

    #!/bin/sh
    . . profile
    SPF_FILE=$$.spf
    ERR_FILE=$$.err
    sqr "$2" "$3" -f$SPF_FILE -e$ERR_FILE -nolis < /dev/null
    if [ $? -eq 0 ]; then
    {
    echo "attached is report output: $SPF_FILE"
    uuencode $SPF_FILE #SPF_FILE
    } | mail -s "report $2 run successfully" $1
    else
    {
    echo "error messages follow"
    echo
    cat $ERR_FILE
    } | mail -s "failed to run report $2" $1
    fi
  3. Start the SQR Production Reporting Activator sample program on the client.

  4. Open a connection to the server using Production Reporting Remote.

    To do this, select Remote Connect under theProduction Reporting menu, enter the login information appropriate for your server login, and click OK.

  5. Copy the sampleProduction Reporting program customer.sqr to the server account.

    To do this, select RemotePut under the Production Reporting menu. Then:

    1. Enter customer.sqr into the local file and remote file input fields.

    2. Select the radio button text transfer, and click OK.

  6. Execute the following command asynchronously (with no wait) on the server by selecting Remote Exec No Wait under the Production Reporting menu.

    mailsqr.sh. mailuser customer.sqr dblogin/dbpasswd
  7. Adjust the values of myserver, mylogin, mypasswd, mailuser, dblogin, and dbpasswd to fit your particular environment.

    To run an Production Reporting program other than customer.sqr, specify the filename of the program.

Following is the Visual Basic code that invokes the mailsqr.sh: script on the server:

Sqr0cx.RemoteConnect("myserver", "mylogin", "mypasswd"," ")
Sqr0cx.RemoteExecNoWait("mailsqr.sh mailuser customer.sqr
dblogin/dbpasswd", "output.txt")
Sqr0cx.RemoteDisconnect

Note how this code assumes that the Production Reporting program already exists on the server. This avoids the performance problem of copying the Production Reporting program file to the server upon each run, and it avoids multi-user conflicts.