Skip to Content
Author's profile photo Former Member

Script to start SAPRouter on Unix


I just want to share a script to start the saprouter in a easy way on unix. Just put the content bellow in a sh file, and pay attentio on the variables.

Then, just execute “sh” for example, or put some schedule on it.

I hope it is useful.


Richard W. L. Brehmer

### Variables ###




DNAME=”p:CN=server, OU=0001000000, OU=SAProuter, O=SAP, C=DE”;

### Variables end ###

### Check if saprouter is already running:

pid1=”`netstat -nlp | grep ‘'”$porta”‘.*saprouter’ | sed -n 1p |awk ‘{print $7}’ | cut -f1 -d “/” `”;

if [ -f $pid1 ]

then # Not running.

  ### check if the port is free:

  echo -e “\nChecking port…”;

  processo=”`netstat -nlp | grep”$porta” | sed -n 1p |awk ‘{print $7}’ | cut -f1 -d “/”`”;

  sleep 2;

  # If port free:

  if [ -f $processo ]


  echo -e ‘\nStarting SAPRouter on port: ‘ $porta;

  sleep 2;


  export SNC_LIB=$SNC_LIB

  /usr/sap/saprouter/./saprouter -r -R “$SECUDIR/saprouttab” -W 60000 -G “$SECUDIR/saprouterlog.txt” -S $porta -K “$DNAME” &

  pid=”`netstat -nlp | grep ‘'”$porta”‘.*saprouter’ | sed -n 1p |awk ‘{print $7}’ | cut -f1 -d “/” `”;

  echo -e “\n\nSAPRouter is running on PID: “$pid;

  echo -e “\n”;


  # if the port isnot free.


  echo -e ‘——————————————————-\n’;

  echo -e ‘ It is not possible to start SAPRouter\n’;

  echo -e ‘ The PID: ‘$processo’ is already using the port: ‘ $porta;

  echo -e ‘——————————————————-\n’;



else # Its already running.

  echo -e “\nSAPRouter is already running”;

  pid=”`ps -ef |grep saprouter | sed -n 1p |awk ‘{print $2}’ `”;

  echo -e “\nPID: “$pid;

  echo -e “\n”;

  sleep 2;


Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Kevin Laevers
      Kevin Laevers

      Thanks for the script. The HTML editor seems to mess up some of the single and double quotes, making copy / paste difficult.

      Missing at the begin of the file :

      • #!/bin/sh

      One small error :

      • pid1=”`netstat -nlp | grep ‘'”$porta”‘.*saprouter’ | sed -n 1p |awk ‘{print $7}’ | cut -f1 -d “/” `”;

      Converts the output of command to a String because the output can contain spaces etc, but can also return nothing, resulting in an empty string.

      In your test, if [ -f $pid1 ] the -f stand for exists. The string will always exist, empty or not :  'saprouter is running' will always be true, regardless of the actual status.

      Better is to use if [ "$pid1" == "" ]

      Keep up the good work!