pythonwebspherejythonwas

How to pass argument from bash to wsadmin


So basically i have .sh script which includes some bash and then ./wsadmin.sh launching some .py scripts which i've made. I need to somehow pass the argument of script from bash to .py script.

As example i have now test.sh $1:

cd /tmp/$1

./wsadmin.sh -lang jython -f /WAS/deploySQL.py

And inside deploySQL.py

I have some as example: AdminConfig.showAttribute(cluster, 'value')

I want to pass that $1 argument to the inside of deploySQL.py "value" field.

Sorry im a beginner could someone help me out?


Solution

  • you can use sys.argv take a look to this example :

    #!/usr/bin/python
    
    import sys
    
    print 'Number of arguments:', len(sys.argv), 'arguments.'
    print 'Argument List:', str(sys.argv)
    

    so if you want to run this script you will

    $ python test.py arg1 arg2 arg3
    

    the result will be

    Number of arguments: 4 arguments.
    Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
    

    in your case, you should run

    ./wsadmin.sh -lang jython -f /WAS/deploySQL.py $1
    

    and replace the value variable in deploySQL.py with sys.argv[1]