Working with OS level from SAP

We have a task – manage OS level requests from SAP job scheduling tool (SM36 transaction). You know, there are a lot of tools to perform OS level tasks, that are built into OS or some 3rd party tools, which support command line access.

For example, I’ve created a simple executable file with just one command:

echo “SAP running” >> sap.log

We want to run this script from OS level locally on the server where SAP is running. Then, remotely, where no SAP system is installed.

Running OS level commands in SAP step by step guide

To start we need to allow SAP run these scripts on OS level. Open SM69 transaction and create a new record like this.

SAP SM69 transaction

Run it.

Pay attention, the command was run from one folder, but the result is shown in SAP work directory. To avoid this we need to specify full file paths or use OS level environment variables for adm user.

If look closer, there is one more way to run the script remotely on the screen, setting Target or Remote host, but it works only for SAP systems.

In SM36 transaction there is an interesting option:

It allows running OS level script from the scheduler.

If we want to use ABAP to run something interesting, then there are options to do that:
Functional module SXPG_COMMAND_EXECUTE or OPEN DATASET command.

RSBDCOS0 program can run a script without any records in SM69.

Running OS level commands from SAP remotely

All we need is to find how to run a script remotely, where no SAP installed. From my experience, all I could imagine is using remote shell calls like PowerShell for windows or ssh for unix-like systems. On SAP side we write a script, which connects remotely and runs script there.

ssh osuser@host “cd testdir;./test.sh”

Or for Windows:
Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-UICulture}

Prooflink: https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/running-remote-commands?view=powershell-5.1

So, typical integration process looks like:
– develop File Event Scheduler, which watches files on OS level
– if a file appears, HR program is run to read file with data. The program reads a file and deletes a flag file from step one.

Or
– run program to export data to OS level
– run OS level file monitor which would upload a file over FTP/CURL or send a signal to SAP

Or everything mentioned above could be developed with ABAP calling FTP/HTTP/SMTP/WebService services of external systems.

The only one situation I believe ABAP can’t do is to run a script with another user permissions but adm. Yes, I know about SUDO :)