One of the key issues faced when setting up a new PI landscape or migrating to a new one is change in network topology. PI team needs to work with network team to ensure the connections are open. This is easily done if the number of hosts to test is small. However, if the number of target hosts runs into hundreds or thousands, an automated approach is required as it’s not possible to check the connectivity manually. Ideally, servers should belong to groups and testing one connection for each scenario should suffice. However, there can be errors and there is a need to identify the connections status in advance.


1) Outbound from PI:

For our scenario let’s consider a PI host running on a linux OS which connects to lot of Windows hosts and a few AIX/ other unix hosts.

Hence, we need to test connectivity :

– From linux host to other hosts which could be in hundreds or thousands:

Screen Shot 2016-02-05 at 8.48.03 AM.png


How to identify hosts:

SAP’s directory API can be used to retrieve the host and port details in communication channels. Please refer to this excellent blog from William Li.

It can be retrieved using a Java program. In our case however, we had generated ABAP proxies and created an ABAP report to retrieve the target hosts and ports.

Choice of languages: For quick use and throw programs, I normally use Python / Java and wasn’t sure if the system admins will allow me to install a JVM or will allow additional libraries for Python. Hence, I decided to create a shell script to test the connections.

Input Data

The file will be a text file with the same parameters we give for telnet. This is a sample file with hosts and ports separated by a space.

host1 99

host2 99

dummy 99

2) Inbound to PI:

– From ( primarily ) Windows hosts to PI linux system:

Screen Shot 2016-02-05 at 8.48.56 AM.png

Here we’re interested in checking connections in the reverse direction from Windows based servers to PI host running on Linux OS.


Identifying hosts: This was somewhat easier as all hosts for us were in a centralised repository and the target will be the same linux PI host.

Choice of language: Again higher level languages as Java/ Python couldn’t be used as the servers are fairly controlled. Then we realised that all windows machines come preinstalled with Windows Powershell – it’s very powerful and compact.

Execution on multiple hosts. If we have one thousand windows hosts, the command has to be executed from all the thousands of hosts and the result should be stored in a single location for us to view the logs.


Outbound from PI: Let’s look at first scenario where we need to execute the script for multiple hosts from a single linux host. We can execute bash scripts like netcat or nc and get the result. However, unfortunately netcat or nc wasn’t present as a command in our shell. So we’re forced to go down a bit deeper to the TCP layer.

Solution lies with /dev/tcp device file .

What is /dev/tcp file ?

/dev/tcp/hostname/port command will try to open a socket with the port on the remote host

We want to discard both the output and error. This can be achieved by sending the output to &>/dev/null – it’s a null device, which is a special device which will discard any information written to it. stdout =1 , stderr = 2.

Here is the script:


function checkport() {

( >/dev/tcp/$1/$2) &>/dev/null

if [ $? -eq 0 ]; then

        echo “++ $1:$2 is open”


        echo “– $1:$2 is closed”



This function will read host and port as input params, try to create a socket and discard the output and error.

After that $? will hold the value if the previous command was successful.

After this , we just need to read a file, line by line, split the data into array of hostname and port and pass the value to the function.


while IFS=” read -r line || [[ -n “$line” ]]; do

read -r -a array <<< “$line”

checkport “${array[0]}” “${array[1]}”

done < “$filename”

if the script file is saved as, make it executable by the following command.

chmod +x

And then it can be executed.

Representative Output

userhost@linuxhost:/home/user> ./ data.txt

++ host1:99 is open

++ host2:99 is open

— dummy:99 is closed

This way we can identify all connections which are failing . Essentially this script is a mass telnet replacement script.

Scenario 2: Inbound to PI

The additional challenge here is that the script has to be executed from each of the remote hosts to PI server. Here, the power of Windows PowerShell comes to our rescue.

Any function can be executed over remote computers using Invoke-Command.

Invoke-Command -ComputerName $server -ScriptBlock ${function:function_name}

Let’s define out function:

function connectToPI




$socket = new-object System.Net.Sockets.TcpClient(“pi_host”, “pi_port”);


Catch [PSRemotingTransportException] { }

Finally { }

if($socket -eq $null)


return “Connection failed from ” + $env:computername;


else{ return “Connection successful from ”  + $env:computername; }


Here again, we try to create a socket using PowerShell and check if the socket object gets created . We print remote host name as $env:computername so that we can log from which hosts connections are successful/ failing.

Then, we can read the list of servers from a file and each server invoke out function.

$Servers = Get-Content F:\serverlist\server.txt

foreach ($server in $Servers) {

Invoke-Command -ComputerName $server -ScriptBlock ${function:connectToPI}


Representative Output:

Connection successful from WIN_SERVER1

Connection successful from WIN_SERVER2

Connection failed from WIN_SERVER3

Thus we’re able to identify connection issues for the reverse direction as well.


This was as an example of using scrips to automate connection tests for unix systems using shell scripts and windows systems using PowerShell. In general, various system administration activities can be more efficiently achieved using scripts . Further, the scripts can be used as post processing scripts with PI as well.

Source code can be accessed at this Github Link : GitHub – viksingh/SAP_PI_SCRIPTS: Scripts used with PI

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply