How we can use pointer in script
Hi Team,
I have built script to start & stop SAP application. In this script i have given system SID & now my script is too big. I want to do some changes in this script so the single code can execute for multiple SIDs. For Ex- I have 20 systems like ECD,BWD,CXD...etc & right now i have built script for all SIDs now i just want to keep all SIDs & host name in one text file & create some varible like "SID" & so script can read thi value from text file & than execute my script ./stsrtsap <SID> . My script #!/bin/sh # # Start / stop SAP Action=$1 Inst=$2 case "$Action" in "start") case "$Inst" in PIN) su - orapin -c "lsnrctl start LISTENER_PIN" su - pinadm -c "startsap" su - pinadm -c "sapccm4x -DCCMS pf=/usr/sap/sapmnt/PIN/profile/ERN_DVEBMGS50_vhscpinapp01" su - daaadm -c "startsap" ;; BWN) su - orabwn -c "lsnrctl start LISTENER_BWN" su - bwnadm -c "startsap" su - bwnadm -c "sapccm4x -DCCMS pf=/usr/sap/sapmnt/BWN/profile/BWN_DVEBMGS60_vhscbwnapp01" su - daaadm -c "startsap" ;; *) esac ;; "stop") PIN) su - daaadm -c "stopsap" su - pinadm -c "sapccm4x -stop pf=/usr/sap/sapmnt/PIN/profile/ERN_DVEBMGS50_vhscpinapp01" su - pinadm -c "startsap" su - orapin -c "lsnrctl stop LISTENER_PIN" ;; BWN) su - daaadm -c "stopsap" su - bwnadm -c "sapccm4x -stop pf=/usr/sap/sapmnt/BWN/profile/BWN_DVEBMGS600_vhscbwnapp01" su - bwnadm -c "stopsap" su - orabwn -c "lsnrctl stop LISTENER_BWN" ;; *) esac ;; *) echo "Usage: $0 { start|stop }" exit 1 ;; esac exit 0 I am a SAP Basis guy & trying to learn linux shell scripting ,Please help me to built this script. |
the basic way to read a var from a file is like so
Code:
[schneidz@hyper clips]$ cat karan4141.txt |
Thanks for reply !!
I want to crete file like below $ cat ihost PIN PINAPP001 BWN BWNAPP01 CXN CXNAPP01 Now when i execute my script "startsap.sh" this scpript can read SID from ihost. ./startsap PIN than this PIN replace <sid> in my script & than execute script for PIN. case "$Inst" in PIN) su - ora<sid> -c "lsnrctl start LISTENER_<SID>" su - pin<sid> -c "startsap" su - pin<sid> -c "sapccm4x -DCCMS pf=/usr/sap/sapmnt/<SID>/profile/<SID>_DVEBMGS50_vhscapp01" su - daaadm -c "startsap" |
Modifying schneidz's technique slightly and extending it, startsap.sh could contain something like
Code:
while read sid something_else |
in case you want to convert a variable to upper or lower case, here is a list about the possibilities, see in the middle (in bash 4): http://stackoverflow.com/questions/2...hell-scripting
|
Hi Catkin,
Thanks for reply !! You informaion is very helpful. Should i add code provided by you like below #!/bin/sh # # Start / stop SAP Action=$1 Inst=$2 case "$Action" in "start") case "$Inst" in SID) while read sid something_else do su - ora{$sid..} -c "lsnrctl start LISTENER_$sid" su - ${sid,,}adm -c "startsap" <more commands using $sid and maybe $something_else> done < ihost cat ihost PIN CXN ECH .....etc |
Please use CODE tags when posting code. It is most easily done by using Advanced editing and using the # button.
Assuming startsap.sh is called with arguments/parameters "start" and "SID" then it looks OK (subject to testing) as long as you replace "<more commands using $sid and maybe $something_else>" with what you need. |
Thanks for reply !!
I have done the change & try to execute but i am getting syntex error ###################################################################################### Code:
#!/bin/sh Below is the output of this script [root@HSCDEV9 /tmp]# ./test start BWU ./test: line 27: syntax error near unexpected token `)' ./test: line 27: `*)' [root@HSCDEV9 /tmp]# |
remove esac on line 27 and 29
|
Indentation makes that sort of error obvious. For example
Code:
case "$Action" in |
Thanks for reply !!
I have removed the entries but also getting the same error. Below is my full script & output Code:
typeset sid Code:
[root@HSCDEV9 /tmp]# ./test start BWD Code:
#!/bin/sh |
Before the stop case there is a ;; after *)
In the stop case there is an unmatched brace in su - ${sid,,)adm -c "stopsap" After that there is Code:
*)esac After the closing esac there is Code:
echo "Usage: $0 { start|stop }" Fixing all that and using indentation so such errors would be obvious Code:
typeset sid |
Hi Catkin,
I have done the same you have pasted here but i am still getting error Code:
typeset sid Code:
[root@DEV9 tmp]# ./test start BWU |
i am not very familiar with cases but for your embedded case, you dont define anything for *). maybe it needs something like ;;.
|
Sorry !! for trhe late reply but i am getting the same error after removing *) from inner case statment.
Code:
typeset sid |
All times are GMT -5. The time now is 06:47 PM. |