Home » 2020 » February

Monthly Archives: February 2020

SAP Solution Manager Key Generator (linux version)


The following bash script should produce installation key for SAP Solution Manager (SOLMAN) basing on three input values: SID, SN and HOSTNAME.

The script is based on popular VB script available here: http://kohanov.com/tmp/sap_keys.vbs

Feel free to use/modify/redistribute the script for both private and commercial use.

#!/bin/bash
# SAP Solution Manager Installation Key Generator
# by: redloff (IRCnet: #+kwa)
# license: free for personal and commercial use
if [ $# -ne 3 ]; then
 echo "use: $0 "
 exit 1
fi
if [ ${#1} -ne 3 ]; then
 echo "SID has to consist of exactly 3 characters"
 exit 2
fi
if [ ${#2} -ne 2 ]; then
 echo "SN has to consist of exactly 2 characters"
 exit 2
fi
function ascii { echo -n $1 | od -d | sed -n "s/^.* //gp"; }
SIDSN=`echo $1$2 | tr [a-z] [A-Z]`
SERV=`echo $3 | tr [a-z] [A-Z]`
for i in `seq 0 $((${#SIDSN}-1))`; do
 SIDSNhex[$i]=`ascii ${SIDSN:${i}:1}`
done
##echo "SIDSNhex: ${SIDSNhex[*]}"
for i in `seq 0 $((${#SERV}-1))`; do
 SERVhex[$i]=`ascii ${SERV:${i}:1}`
done
for i in `seq ${#SERV} 14`; do
 SERVhex[$i]=0
done
##echo "SERVhex: ${SERVhex[*]}"
if [ ${#SERV} -gt 0 -a ${#SERV} -lt 5 ]; then
 for i in `seq ${#SERV} 4`; do
 SERVhex[$i]=32 #ascii space char
 done
##    echo "SERV between 0 a 5"
fi
if [ ${#SERV} -gt 5 -a ${#SERV} -lt 10 ]; then
 for i in `seq ${#SERV} 9`; do
 SERVhex[$i]=32 #ascii space char
 done
##    echo "SERV between 5 a 10"
fi
if [ ${#SERV} -gt 10 -a ${#SERV} -lt 15 ]; then
 for i in `seq ${#SERV} 14`; do
 SERVhex[$i]=32 #ascii space char
 done
##    echo "SERV between 10 a 15"
fi
##echo "SERVhex: ${SERVhex[*]}"
for i in `seq 0 4`; do
 reshex[$i]=`echo $(((((0^${SIDSNhex[$i]})^${SERVhex[$i]})^${SERVhex[$(($i+5))]})^${SERVhex[$(($i+10))]}))`
done
##echo "reshex: ${reshex[*]}"
reshex[0]=`echo $((${reshex[0]}^84^0))`
reshex[1]=`echo $((${reshex[1]}^131^11))`
reshex[2]=`echo $((${reshex[2]}^194^46))`
reshex[3]=`echo $((${reshex[3]}^52^105))`
reshex[4]=`echo $((${reshex[4]}^119^188))`
##echo "reshex: ${reshex[*]}"
hexstr=(0 1 2 3 4 5 6 7 8 9 A B C D E F)
for i in `seq 0 4`; do
 hihex=`echo $((${reshex[$i]}/16))`
 lohex=`echo $((${reshex[$i]}%16))`
 resstr=${resstr}${hexstr[$hihex]}${hexstr[$lohex]}
done
echo "Installation key: $resstr"

To use the code, just paste it into a file (ex: solmankg.sh)
Set execution rights (chmod 755 solmankg.sh)
Execute the script with three arguments: SID, SN, HOSTNAME (ex: ./solmankg.sh AA1 00 FLUFFY)