Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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.
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
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.
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
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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.