As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Submiting SAS Jobs From a Windows Text Editor to a Linux SAS Server

From sasCommunity
Jump to: navigation, search

Here is a simple Linux Bash script which can be used to submit SAS jobs on a Linux or Unix server via a standard text editor which has macro functionality.

Click Here to download Bash script file


!/bin/bash

Script created by Ray Cloutier and maintained by Ray Cloutier and Bret Yarrison. This script allows analysts to use an Ultra Edit macro to submit SAS jobs to the respective server without actually logging onto the server.

Change directory into the launchpad directory so the script can scrape up the launch files created by each user via UE

cd /hdas/sys/ue_launchpad

Start the loop, doing clean up, creating/setting user context, and checking for launch files

while true
   do

Remove UltraEdit .BAK files to keep the directory clean and cut down on warning messages in any log files

    if [ -a ./*.bak ]
    	then
			rm ./*.bak
    fi

Cheking for server specific launch files, i.e. submitSAS1.*, and more specifically submitSAS1.$USERNAME which is used for launch file differentiation

    for FILE in 'submitSAS1.*'
    	do
     	if  [ -a $FILE ]
     		then
              

For logging purposes we check who the user is prior to the script launch. It should be null or nothing and after the check it should be the username of the analyst submitting the job

              echo "CURRENT_USER before =" $CURRENT_USER >> `echo $HOSTNAME|cut -d"." -f1`_sasd.log

To get the submitting user's name the launch file's ownership is parsed out using awk and assigned to the variable CURRENT_USER

              CURRENT_USER=$(ls $FILE | grep -v txt |awk -F . '{print $2}')
              

For logging purposes we check who the user is AFTER the launch file has been submitted and the variable defined from the set above.

              echo "CURRENT_USER after =" $CURRENT_USER >> `echo $HOSTNAME|cut -d"." -f1`_sasd.log

The oraSecret file sets several environment variable required to run SAS via the UE macro. It is CHMOD'd to make sure ONLY the user can read it, security. This file includes the Oracle username and password of the submitting user, the ORACLE_HOME and LD_LIBRARY_PATH variables for Oracle function properly, and the customized PATH statement

        chmod 700 "/home/$CURRENT_USER/oraSecret"              

This is where we build the master launch file with ORA user and pass AND sas code to run First get the oraSecret values into the launch file

 	 cat "/home/$CURRENT_USER/oraSecret">/hdas/sys/ue_launchpad/run_sas1

Next get the submitted values from the analyst/UE into the launch file

        cat ./$FILE>>/hdas/sys/ue_launchpad/run_sas1

Next CHOWN the file launch file so the submitting user account has ownership

        chown $CURRENT_USER /hdas/sys/ue_launchpad/run_sas1

Next CHMOD the launch file so that it can be executed in bash

        chmod 700 /hdas/sys/ue_launchpad/run_sas1

This is the run mechanism. Since we are running this script as root we are using SUDO to emulate the submitting user. This allows the SAS job to run as if submitted by a user (not root) and keeps the owner and group permissiosn consistent across the file system

        sudo -u $CURRENT_USER ./run_sas1

Clean up the submitted files

        rm $FILE

Clean up the launch files created

        rm ./run_sas1

Set the CURRENT_USER variable back to null/nothing

        CURRENT_USER=""

fi done

   sleep 2;

done



Here is the corresponding text editor macro which is used to submit the current file in the text editor to the Linux SAS server (this macro is for the UltraEdit text editor.)


InsertMode
ColumnModeOff
HexOff
UnixReOff
CopyFilePath
NewFile
"nohup /usr/local/SAS/SAS_9.1/sas "
Paste 
" -log "
Paste 
" -print "
Paste 
Key HOME
Find "f:"
Replace All "/hdas"
Find "\"
Replace All "/"
Key HOME
Find ".sas"
StartSelect
Find ".sas"
EndSelect
".log"
StartSelect
Find ".sas"
EndSelect
".lst   -sasuser /home/rcloutier/sasuser.v91 -noterminal &"
SaveAs "F:\sys\ue_launchpad\submitSAS1.rcloutier"
CloseFile Save