LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-03-2012, 06:40 AM   #1
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Rep: Reputation: Disabled
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.
 
Old 10-03-2012, 07:09 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
the basic way to read a var from a file is like so
Code:
[schneidz@hyper clips]$ cat karan4141.txt 
hello
world
l33t
h4x0rz
chun-li
akuma
[schneidz@hyper clips]$ cat karan4141.txt | while read line
> do
>  echo line = $line
> done
line = hello
line = world
line = l33t
line = h4x0rz
line = chun-li
line = akuma
 
Old 10-03-2012, 08:15 AM   #3
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
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"
 
Old 10-03-2012, 08:44 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Modifying schneidz's technique slightly and extending it, startsap.sh could contain something like
Code:
while read sid something_else
do
    su - ora$sid -c "lsnrctl start LISTENER_$sid" 
    <more commands using $sid and maybe $something_else>
done < ihost
That presumes you have logon names oraPIN etc. which would be valid but unconventional. In case the logon is orapin, use ora${sid,,}. The technique is shell parameter expansion, here used to translate upper case to lower case.
 
2 members found this post helpful.
Old 10-03-2012, 09:05 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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
 
1 members found this post helpful.
Old 10-04-2012, 07:05 AM   #6
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-04-2012, 08:01 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
1 members found this post helpful.
Old 10-04-2012, 08:22 AM   #8
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thanks for reply !!

I have done the change & try to execute but i am getting syntex error

######################################################################################
Code:
#!/bin/sh

# Start / stop SAP

typeset  sid
Action=$1
Inst=$2

case "$Action" in

"start")

        case "$Inst" in
        sid)
while read sid
do
su - ora{$sid..} -c "lsnrctl start LISTENER_$sid"
su - ${sid,,}adm -c "startsap"
done < ihosts


;;
*)
      esac
          ;;
esac
*)


        echo "Usage: $0 { start|stop }"

        exit 1

        ;;

esac

exit 0
#######################################################################

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]#
 
Old 10-04-2012, 08:47 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
remove esac on line 27 and 29
 
Old 10-04-2012, 09:14 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Indentation makes that sort of error obvious. For example
Code:
case "$Action" in
    "start")
        case "$Inst" in
            sid)
                while read sid 
                do  
                   su - ora{$sid..} -c "lsnrctl start LISTENER_$sid"
                   su - ${sid,,}adm -c "startsap"
                done < ihosts
                ;;  
            *)  
        esac
        ;;  
    *)  
        echo "Usage: $0 { start|stop }"
        exit 1
        ;;  
esac

exit 0
 
Old 10-04-2012, 09:17 AM   #11
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thanks for reply !!

I have removed the entries but also getting the same error. Below is my full script & output

Code:
typeset  sid
Action=$1
Inst=$2

case "$Action" in

"start")

        case "$Inst" in
        sid)
while read sid
do
su - ora{$sid..} -c "lsnrctl start LISTENER_$sid"
su - ${sid,,}adm -c "startsap"
done < ihosts


;;
*)
      esac
          ;;
"stop")

      sid|SID)
      while read sid
do

        su - ${sid,,)adm -c "stopsap"
 done < ihosts
;;
*)esac
;;
*)

        echo "Usage: $0 { start|stop }"

        exit 1

        ;;
esac

exit 0
Code:
[root@HSCDEV9 /tmp]# ./test start BWD
./test: line 28: syntax error near unexpected token `)'
./test: line 28: `      sid|SID)  '
I have devloped the below script is working fine but the issue is i have to write code for each SID(Ex- PIN,BWN,CXN..etc). So i just want to devlop sigle code which can get SID from any text file & execute the below script .

Code:
#!/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"
            
        ;;
*)
      esac 
          ;;
"stop")

        PIN)
            
            su - pinadm -c "startsap"
            su - orapin -c "lsnrctl stop LISTENER_PIN"
;;
*)
      esac 
          ;;

*)

        echo "Usage: $0 { start|stop }"

        exit 1

        ;;

esac

exit 0
 
Old 10-04-2012, 12:03 PM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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
;;
*)
which is at least messy and probably wrong.

After the closing esac there is
Code:
        echo "Usage: $0 { start|stop }"
 
        exit 1
 
        ;;
esac
The ;; and esac are wrong.

Fixing all that and using indentation so such errors would be obvious
Code:
typeset  sid
Action=$1
Inst=$2

case "$Action" in
    "start")
        case "$Inst" in
            sid)
                while read sid
                do
                    su - ora{$sid..} -c "lsnrctl start LISTENER_$sid"
                    su - ${sid,,}adm -c "startsap"
                done < ihosts
                ;;
            *)
        esac
    "stop")
        sid|SID)
        while read sid
        do
            su - ${sid,,}adm -c "stopsap"
        done < ihosts
        ;;
    *)
        echo "Usage: $0 { start|stop }"
        exit 1
        ;;
esac

exit 0
For perfection, the typeset sid is not required (it has no effect) and the case statement does not require a ;; before esac (it's OK to hve it but not required)
 
Old 10-05-2012, 04:07 AM   #13
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi Catkin,

I have done the same you have pasted here but i am still getting error

Code:
typeset  sid
Action=$1
Inst=$2

case "$Action" in
    "start")
        case "$Inst" in
            sid)
                while read sid
                do
                    su - ora${sid,,} -c "lsnrctl start LISTENER_$sid"
                    su - ${sid,,}adm -c "startsap"
                done < ihosts
                ;;
            *)
        esac
    "stop")
        sid|SID)
        while read sid
        do
            su - ${sid,,}adm -c "stopsap"
        done < ihosts
        ;;
    *)
        echo "Usage: $0 { start|stop }"
        exit 1
        ;;
esac

exit 0
Code:
[root@DEV9 tmp]# ./test start BWU
./test: line 22: syntax error near unexpected token `)'
./test: line 22: `    "stop")'
[root@HSCDEV9 tmp]#
 
Old 10-05-2012, 07:01 AM   #14
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i am not very familiar with cases but for your embedded case, you dont define anything for *). maybe it needs something like ;;.
 
Old 10-09-2012, 05:41 AM   #15
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Sorry !! for trhe late reply but i am getting the same error after removing *) from inner case statment.

Code:
typeset  sid
Action=$1
Inst=$2

case "$Action" in
    "start")
        case "$Inst" in
            sid)
                while read sid
                do
                    su - ora${sid,,} -c "lsnrctl start LISTENER_$sid"
                    su - ${sid,,}adm -c "startsap"
                done < ihosts
                ;;

        esac
    "stop")
        sid|SID)
        while read sid
        do
            su - ${sid,,}adm -c "stopsap"
        done < ihosts
        ;;
    *)
        echo "Usage: $0 { start|stop }"
        exit 1
        ;;
esac

exit 0
[root@HSCDEV9 tmp]# ./test start BWU
./test: line 22: syntax error near unexpected token `)'
./test: line 22: `    "stop")'
[root@HSCDEV9 tmp]#
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to pointer segmentation fault Guilherme Programming 7 06-28-2009 09:47 AM
pass pointer,, return pointer??? blizunt7 Programming 3 07-23-2005 01:36 PM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 06:40 AM
move mouse pointer from shell script malo_umoran Slackware 1 11-06-2004 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration