mrjigglez
Goto Top

Sourcen - Einbinden externer Konfigurationsdateien - Linux-UNIX

Ich bin fast am verzweifeln:

Ich habe ein Shellskript geschrieben, welches seine verwendeten Standardvariablen mittels source (aka .) aus
einer externen Konfigurationsdatei bezieht. In dieser befinden sich nur Variablen mit Wertzuweisungen.

Nach der vollständigen Abarbeitung des Shellskripts wird ein Kommando aus festen Strings und diesen gesourcten
Variablen erstellt. Und dieses erstellte Kommando ist der Casus Knaxus:

Unter Debian und Cent OS Linux klappt das Shellskript wunderbar. Aber unter allen Suse Linux Distributionen
ist das erstellte Kommando falsch. Der erstellte String sieht aus als ob er fehlerhaft subsituiert wurde und
außerdem geshiftet wurde. Ich weiß jetzt auch nicht mehr weiter. Hat einer von Euch schon mal ein Ähnliches
Problem gehabt? Oder habt ihr dafür eine Lösung bzw. einen Workaround. Über jegliche Hilfe und Anregungen
bin ich dankbar.

Und bitte nur antworten wenn ihr wisst was ich meine. Mutmaßungen nützen mir nicht weiter. Ich habe
lange genug gebraucht um zu verfizieren, dass es an SUSE Linux liegt und habe so ziemlich alle
Kombinationen ausprobiert, Tutorials gelesen ... weil ich mir wie ein Anfänger vorkam.


1. Das Shellskript


#!/bin/sh

#   ************************************************************************************************
#   ***   @program:       start6.sh
#   ***   @description:   This shellscript runs a java program which delivers information about
#   ***                               all installed webmodules and portlets on a specified system. Then it 
#   ***                               sorts them and returns them sorted as html-file and prints them to STDOut.
#   ***   @author:           Mr.Jigglez
#   ***   @version:         1.1
#   ***   @date:               23.10.2009
#   ***   @copyright:      xxxxxxxxxxxxxxxxxxxxxxxxxxx
#   ************************************************************************************************


#   ********************************* main configuration part **************************************
#inputFile=config/export.all.portlets.xml
#outputFile=output/all.installed.portlets.unsorted.xml
#hostname=hostname
#portalServer=localhost
#port=9081
#portalDir="/opt/WebSphere/PortalServer" 
#user=xxxxxxxxx
#password=xxxxxxxx

#typeset configFile
configFile='config/xmlaccess.default.configuration.for.linux.cfg'  
#source ./config/xmlaccess.default.configuration.for.linux.cfg
#. ./${configFile}
#source ./${configFile}
#   ************************************************************************************************

echo "ausserhalb parameteranzahl:"  
echo $#

#   ************************************************************************************************
#   ***                           function usage - the help function                             ***
#   ************************************************************************************************
function syntax()
{
  #echo "function:syntax()"  
  prog=`basename $0`
  echo ""  
  echo "This program starts DIAIWAP. The Program delivers information about"  
  echo "installed webmodules and portlets and processes them accordingly"  
  echo ""  
  echo "SYNTAX: $prog"  
  echo ""  
}
#   ************************************************************************************************


#   ************************************************************************************************
#   ***     function which requests the execution options and configures them accordingly        ***
#   ************************************************************************************************
function optionsMenu()
{
  #echo "function:optionsMenu()"  
  echo run program with [d]efault or [u]ser defined options?
  echo ""  
  echo "Please note that the default option is options=[d]efault !!!"  
  echo -n "program options [d]efault or [u]ser defined:"  
  read options
  #check if user defined options are chosen
  if [ "$options" == "u" ] ; then  
    echo "user defined options:"  
    echo -n "portalDir="  
    read portalDir
    echo -n "inputFile="  
    read inputFile
    echo -n "user="  
    read user
    echo -n "password="  
    read password
    echo -n "portalServer="  
    read portalServer
    echo -n "port="  
    read port
    echo -n "outputFile="  
    read outputFile
  else
    echo "default options:$options"  
  fi
}
#   ************************************************************************************************


#   ************************************************************************************************
#   ***                           function which prints all set variables onto the screen                          ***
#   ************************************************************************************************
function printParameters()
{
  #echo "function:printParameters()"  
  echo ""  
  echo The following parameters are configured for this program 
  echo ...
  echo '$hostname:'"$hostname"  
  echo '$portalServer:'"$portalServer"  
  echo '$port:'"$port"  
  echo '$portalDir:'"$portalDir"  
  echo '$user:'"$user"  
  echo '$password:'"$password"  
  echo '$inputFile:'"$inputFile"  
  echo '$outputFile:'"$outputFile"  
  echo ""  
}
#   ************************************************************************************************


#   ************************************************************************************************
#   ***         function runSortingProgram calls the java programm und run the sorting ...      ***
#   ************************************************************************************************
function runSortingProgram()
{
  #echo "function:runSortingProgram()"  
  java -jar diaiwap.sdk.1.5.compatible.jar
  echo ""  
  echo "Export, creation and sorting for DIAIWAP succesfully done ..."  
  echo ""  
}
#   ************************************************************************************************


# check that programm is called without parameters

#function main()
#{
  #echo "function:main()"  
  echo "innerhalb parameteranzahl:"  
  echo '$paramCount:'$paramCount  

  #check if program is called without parameters else exit with statuscode 1
  #if [ $paramCount -ne 0 ] ; then
  if [ $# -ne 0 ] ; then
    syntax
    exit 1
  fi

  echo "*************************************************************************"  
  echo "***       Started DIAIWAP - Program to deliver information about     ***"  
  echo "***               installed webmodules and portlets.                                ***"  
  echo "*************************************************************************"  
  echo ""  
  echo "Running ..."  
  echo ""  
  echo "Should xmlaccess be called and export information about all"  
  echo "installed portlets and webdmodules? Please note that by pressing"  
  echo "[n]o the already exported default file all.installed.portlets.xml"  
  echo "which includes all installed webmodules and portlets is used!"  
  echo ""  
  echo "Please also note that the default is: xmlaccess=[y]es !!!"  
  echo -n "run xmlaccess [y]es or [n]o:"  
  read xmlaccess

  #check if xmlacces should not be called and then sort the already existing default file and exit with status 0
  if [ "$xmlaccess" == "n" ] ; then  
    echo '$xmlaccess=no'  
    printParameters
    runSortingProgram
    exit 0
  else
    test=0
    #optionsMenu
  fi



  # check whether the configurationfile with all needed parameters exists, is a file and is readable
  if [ -e "$configFile" ] && [ -f "$configFile" ] && [ -r "$configFile" ]; then  
    # source (include) the configfile
    #. ./config/xmlaccess.default.configuration.for.linux.cfg
    . ./$configFile
    printParameters
    optionsMenu
    #runSortingProgram
    echo '$portalDir'":$portalDir"  
    echo '$inputFile'":$inputFile"  
    echo '$user'":$user"  
    cmd=""  
    cmd="${portalDir}""/bin/xmlaccess.sh -in ""${inputFile}"" -user ""${user}"" -pwd ""${password}"" -url http://""${portalServer}"":""${port}""/wps/config/ -out ""${outputFile}"  
    echo $cmd

    a1="test1"  
    a2="test2"  
    a3="test3"  
    a4="test4"  
    a5="test5"  
    a6="test6"  
    a7="test7"  
    cmd2="${a1}""/bin/xmlaccess.sh -in ""${a2}"" -user ""${a3}"" -pwd ""${a4}"" -url http://""${a5}"":""${a6}""/wps/config/ -out ""${a7}"  
    echo $cmd2

    cmd3="${portalDir}/bin/xmlaccess.sh -in ${inputFile} -user ${user} -pwd ${password} -url http://${portalServer}:${port}/wps/config/ -out ${outputFile}"  
    echo $cmd3

  else
    echo "Error:  The configuration-file which is needed for xmlaccess is missing, or not readable!"  
    echo "Please make sure that $configFile is ok!"  
    exit 1
  fi
#}
#paramCount=$#
#main $paramCount $inputFile $outputFile $hostname $portalServer $port $portalDir $user $password


inputFile="config/export.all.portlets.xml"  
outputFile="output/all.installed.portlets.unsorted.xml"  
hostname="hostname"  
portalServer="localhost"  
port="9081"  
portalDir="/opt/WebSphere/PortalServer"  
user="XXXXXXXX"  
password="XXXXXXXX"  



3. Wesentlicher Teilausschnitt der Programmausgabe:

*************************************************************************
***       Started DIAIWAP - Program to deliver information about      ***
***               installed webmodules and portlets.                  ***
*************************************************************************

Running ...

Should xmlaccess be called and export information about all
installed portlets and webdmodules? Please note that by pressing
[n]o the already exported default file all.installed.portlets.xml
which includes all installed webmodules and portlets is used!

Please also note that the default is: xmlaccess=[y]es !!!
run xmlaccess [y]es or [n]o:

The following parameters are configured for this program
...
$hostname:hostname
$portalServer:localhost
$port:9081
$portalDir:/opt/WebSphere/PortalServer
$user:XXXXXXXX
$password:XXXXXXXX
$inputFile:config/export.all.portlets.xml
$outputFile:output/all.installed.portlets.unsorted.xml

run program with [d]efault or [u]ser defined options?

Please note that the default option is options=[d]efault !!!
program options [d]efault or [u]ser defined:
default options:
$portalDir:/opt/WebSphere/PortalServer
$inputFile:config/export.all.portlets.xml
$user:XXXXXXXX
/wps/config/ -out output/all.installed.portlets.unsorted.xml
test1/bin/xmlaccess.sh -in test2 -user test3 -pwd test4 -url http://test5:test6/wps/config/ -out test7
/wps/config/ -out output/all.installed.portlets.unsorted.xml


PS: Ich habe so ziemlich alle Quotingvarianten ausprobiert. Daran hat es nicht gelegen. Um zu sehen
ob das Konkatenieren auch klappt habe ich eine Testausgabe mit direkt vorher konfigurierten Variablen
gebastelt. Diese Ausgabe ist korrekt. Sie ist anders quotiert aber ich habe auch schon gleiche Varianten.
Es hat immer nix gebracht. Und wichtig: Unter Debian und Cent OS klappts. Die Zeile in welcher ich konkateniere
ist ab Zeile 170 auffindbar (cmd3=...)



Hier nochmal die wichtigen Ausgaben


/wps/config/ -out output/all.installed.portlets.unsorted.xml
test1/bin/xmlaccess.sh -in test2 -user test3 -pwd test4 -url http://test5:test6/wps/config/ -out test7
/wps/config/ -out output/all.installed.portlets.unsorted.xml

Content-Key: 128008

Url: https://administrator.de/contentid/128008

Ausgedruckt am: 19.03.2024 um 06:03 Uhr