LinuxQuestions.org
Visit Jeremy's Blog.
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-28-2015, 05:49 AM   #1
beere.bhargava1
LQ Newbie
 
Registered: Oct 2015
Posts: 4

Rep: Reputation: Disabled
Smile Need Urgent help on Shell Scripting!!


Hi Experts,

I'm really delighted to see this kind of a great forum for discussions and to help others!

Here is my first post on this forum I'm new to shell scripting and just started learning the things. Could someone please help me with your suggestions,As I'm stuck with my shellscript

I have a huge list of Projects (Almost 20) and each Project has 4 UAT Environments which has atleast 4 application servers (JVMs) installed.

And each application server(JVM) has a specific configuration file called "Change_Config.xml" which will be used for internal purpose. I am getting continuous requests to change a single value of one parameter manually to "true/false" from my app team.

I would like to automate the same and need you guys help on this please.
I have developed a script,where

1) It reads the Input of the "Project" where each project have 4 UAT ENVironments and each UAT Environment has 4 AppServers installed (2 JVMs on one Linux Server + Other 2 JVMs on another Linux server)

1.Project1 2.Project2 3.Project3
4.Project4 5.Project5 5.Project6


2) Once the user Selected any of the Project from above, my Script again reads the input from user for "Environment"

UAT1 (or) UAT2 (or) UAT3 (or) UAT4

3) Once the user selects both the options for eg. "PROJECT2 -- UAT3", Based on these two above values, The Script should again select the "AppServer (JVM)" name automatically without asking the User for the Input.

This is where I'm stuck right now (I can't hardcode the AppServer value in the script as it is NOT allowed!!)

Could someone please help me how can I achieve this. Something like,Creating some plain text file and dumping all the PROJECT & ENVIRONMENT values and based on the above values selection, AppServer name needs to be selected.


Your help is much appreciated!!

Thanks in Advance and Apologies for the lenghty explanation of question.
 
Old 10-28-2015, 06:42 AM   #2
ntu929
Member
 
Registered: Jun 2010
Location: India
Distribution: Ubuntu
Posts: 128

Rep: Reputation: 4
Hi,

Well you have not posted any of the code coupled with explanations. Possibly that may not be the companies policy...

But as far as I can understand, you intend to develop User's Acceptance Testing (UAT) Environment with JVMs running onto them.

Now, these JVM are having xml file which keeps track of internal changes.

And your intend is to automate the selection of project and UAT environments.

I can say following ways of addressing you concerns:-

1. As what you have suggested, it is possible to place all of the values in text file and then choose according to user's choice. But from security point of view, the text file should encrypted.

2. Also you can make the user's screen more interactive. Telling the user about list of active UAT and projects. And at run time allocating them to the user.

Rest its upto the gurus/experts here to say.

Hope it helps.


Quote:
Originally Posted by beere.bhargava1 View Post
Hi Experts,

I'm really delighted to see this kind of a great forum for discussions and to help others!

Here is my first post on this forum I'm new to shell scripting and just started learning the things. Could someone please help me with your suggestions,As I'm stuck with my shellscript

I have a huge list of Projects (Almost 20) and each Project has 4 UAT Environments which has atleast 4 application servers (JVMs) installed.

And each application server(JVM) has a specific configuration file called "Change_Config.xml" which will be used for internal purpose. I am getting continuous requests to change a single value of one parameter manually to "true/false" from my app team.

I would like to automate the same and need you guys help on this please.
I have developed a script,where

1) It reads the Input of the "Project" where each project have 4 UAT ENVironments and each UAT Environment has 4 AppServers installed (2 JVMs on one Linux Server + Other 2 JVMs on another Linux server)

1.Project1 2.Project2 3.Project3
4.Project4 5.Project5 5.Project6


2) Once the user Selected any of the Project from above, my Script again reads the input from user for "Environment"

UAT1 (or) UAT2 (or) UAT3 (or) UAT4

3) Once the user selects both the options for eg. "PROJECT2 -- UAT3", Based on these two above values, The Script should again select the "AppServer (JVM)" name automatically without asking the User for the Input.

This is where I'm stuck right now (I can't hardcode the AppServer value in the script as it is NOT allowed!!)

Could someone please help me how can I achieve this. Something like,Creating some plain text file and dumping all the PROJECT & ENVIRONMENT values and based on the above values selection, AppServer name needs to be selected.


Your help is much appreciated!!

Thanks in Advance and Apologies for the lenghty explanation of question.
 
1 members found this post helpful.
Old 10-28-2015, 07:16 AM   #3
beere.bhargava1
LQ Newbie
 
Registered: Oct 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
@ntu929,Thank you for the quick response!!!

To keep this simple, I have a "Change_Config.xml" which resides in Webpshere Appserver location
(/opt/IBM/Websphere/AppServer/profiles/Project1/UASPROJ0101JVM/Change_Config.xml)
(/opt/IBM/Websphere/AppServer/profiles/Project1/UASPROJ0102JVM/Change_Config.xml) for the case of "Project1 -- UAT1".

And the value of "UASPROJ****JVM" varies based on the user selection of "PROJECT -- ENVIRONMENT" as I stated above.

I'm just trying to automate to change the value of paramater to true (or) false in the "Change_Config.xml" for tag "<env name="agent/enable" value="true" />""

Content of "Change_Config.xml"::

<?xml version="1.0" encoding="UTF-8"?>
<project>
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<env name="envvar" value="/opt/environment/environment.properties" />
<env name="JDBC_Driver" value="/opt/JDBC/ojdb6.jar" />
<env name="agent/enable" value="true" />
</project>


But I'm stuck how the AppServer Value ("UASPROJ****JVM") can be passed based on the User Input of "PROJECT -- ENVIRONMENT" while running the shell script

Thanks again for your valuable time on this
 
Old 10-28-2015, 08:33 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,921

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by beere.bhargava1 View Post
Hi Experts,
I'm really delighted to see this kind of a great forum for discussions and to help others! Here is my first post on this forum I'm new to shell scripting and just started learning the things. Could someone please help me with your suggestions,As I'm stuck with my shellscript

I have a huge list of Projects (Almost 20) and each Project has 4 UAT Environments which has atleast 4 application servers (JVMs) installed. And each application server(JVM) has a specific configuration file called "Change_Config.xml" which will be used for internal purpose. I am getting continuous requests to change a single value of one parameter manually to "true/false" from my app team.

I would like to automate the same and need you guys help on this please. I have developed a script,where

1) It reads the Input of the "Project" where each project have 4 UAT ENVironments and each UAT Environment has 4 AppServers installed (2 JVMs on one Linux Server + Other 2 JVMs on another Linux server)

1.Project1 2.Project2 3.Project3
4.Project4 5.Project5 5.Project6


2) Once the user Selected any of the Project from above, my Script again reads the input from user for "Environment"

UAT1 (or) UAT2 (or) UAT3 (or) UAT4

3) Once the user selects both the options for eg. "PROJECT2 -- UAT3", Based on these two above values, The Script should again select the "AppServer (JVM)" name automatically without asking the User for the Input.

This is where I'm stuck right now (I can't hardcode the AppServer value in the script as it is NOT allowed!!)

Could someone please help me how can I achieve this. Something like,Creating some plain text file and dumping all the PROJECT & ENVIRONMENT values and based on the above values selection, AppServer name needs to be selected.
First, please read both the LQ Rules and the "Question Guidelines" links in my posting signature. This is NOT URGENT for anyone here...asking for/expecting 'urgent' help from VOLUNTEERS is fairly rude. Secondly, we will be happy to help (that is, ASSIST) you with your script, so POST IT. We are not going to write a script for you, but will be happy to help you if you're stuck.

Post what you've written, and we can help. Otherwise, see any of the many thousands of easily-found bash scripting tutorials.
 
Old 10-28-2015, 08:54 AM   #5
beere.bhargava1
LQ Newbie
 
Registered: Oct 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by TB0ne View Post
First, please read both the LQ Rules and the "Question Guidelines" links in my posting signature. This is NOT URGENT for anyone here...asking for/expecting 'urgent' help from VOLUNTEERS is fairly rude. Secondly, we will be happy to help (that is, ASSIST) you with your script, so POST IT. We are not going to write a script for you, but will be happy to help you if you're stuck.

Post what you've written, and we can help. Otherwise, see any of the many thousands of easily-found bash scripting tutorials.

@TB0ne,Thanks for your reply and APOLOGIES for NOT following the guidelines on this forum.

Also, I'm afraid I didn't ask to write a script for me. I just needed the advice how the better approach would be to achieve the thing that I'm looking for. Sorry again if it meant to you so.

Cheers
 
Old 10-28-2015, 09:05 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,921

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by beere.bhargava1 View Post
@TB0ne,Thanks for your reply and APOLOGIES for NOT following the guidelines on this forum.
Also, I'm afraid I didn't ask to write a script for me. I just needed the advice how the better approach would be to achieve the thing that I'm looking for. Sorry again if it meant to you so.
Great...so why haven't you posted what you've written/done so far, as we asked??? We can't give you advice without knowing where you're stuck, can we?
 
Old 10-28-2015, 09:48 AM   #7
beere.bhargava1
LQ Newbie
 
Registered: Oct 2015
Posts: 4

Original Poster
Rep: Reputation: Disabled
#!/bin/bash
echo -e "\n\n\t--------------------------------------------------------------------------------------"
echo -e "\t ***** Please select the PROJECT where the VALUE should be Altered*****"
echo -e "\t--------------------------------------------------------------------------------------\n"
echo -e "\n\t1.Project1\t\t\t\t5.Project5\t\t\t9.Project9\t\t\t13.Project13\n"
echo -e "\n\t2.Project2\t\t\t\t6.Project6\t\t10.Project10\t\t\t14.Project14\n"
echo -e "\n\t3.Project3\t\t7.Project7\t\t11.Project11\n"
echo -e "\n\t4.Project4\t\t8.Project8\t\t12.Project12\n"
echo -e "\n\n"
echo -n " Enter your response(Numeric Value) from above list: "

read Component

case $Component in

1)X=`echo "Project1"`;;2)X=`echo "Project2"`;; 3)X=`echo "Project3"`;;4)X=`echo "Project4"`;;5)X=`echo "Project5"`;;6)X=`echo "Project6"`;;7)X=`echo "Project7"`;;
8)X=`echo "Project8"`;;9)X=`echo "Project9"`;;10)X=`echo "Project10"`;;11)X=`echo "Project11"`;;12)X=`echo "Project12"`;;13)X=`echo "Project13"`;;14)X=`echo "Project14"`;;
*)if [ $Component -ge 15 ]
then
echo -e "\t\t-----------------------------------------------------------------"
echo -e "\t\t\t!!!!!!!!!!!! [*** ERROR ***] !!!!!!!!!!!!!!"
echo -e "\t\t-----------------------------------------------------------------"
echo -e "\n\t\t\t SELECTED PROJECT DOESN'T EXIST!!!\n\n\t\t\t\t****EXITING THE SCRIPT****\n\n"
exit
fi;;

esac

echo -e "\n\n\t------------------------------------------------------------"
echo -e "\t ***** Please select the PROJECT's Environment *****"
echo -e "\t------------------------------------------------------------\n"


echo -e "\t @@@ USAGE:: Enter your response as - UAT1 (UAT[1|2|3|4|5]):- If script should run on UAT1 (UAT[1|2|3|4|5]) Environment\n\t\t\t\t\t\tDEV2 (DEV[1|2|3|4|5]):- If script should run on DEV2 (DEV[1|2|3|4|5) Environment\n\t\t\t\t\t\tSIT3 (SIT[1|2|3|4|5]):- If script should run on SIT3 (SIT[1|2|3|4|5) Environment\n"



ENV_ARRAY=('DEV1' 'DEV2' 'DEV3' 'DEV4' 'DEV5' 'SIT1' 'SIT2' 'SIT3' 'SIT4' 'SIT5' 'UAT1' 'UAT2' 'UAT3' 'UAT4' 'UAT5')

echo -e "\n\n"
echo -n " Enter your response: "
read Environment

i=0
for ENV in "${ENV_ARRAY[@]}"
do
if [[ "$Environment" == "$ENV" ]]
then
i=1
else
echo ""
fi
done

if [ "$i" -eq 1 ]
then
echo -e "\t\t\t\t######Match Found######"
else
echo -e "\n\t\t~~~~~!!!Input doesn't match with available ENVs...Hence Exiting!!!~~~~~\n"
exit 1
fi

Option=`echo "$X - $Environment"`

echo -e "\n"
echo -e " Entered Response is @@@@@@@@@@@@@ $Option @@@@@@@@@@@@@@\n"
echo -e "\n"
echo -n " Please confirm to proceed[Y|N]:: "

read Confirmation

if [[ ( $Confirmation == Y ) || ( $Confirmation == y ) ]]
then
echo -e "Script should run on USER Selected ENV (For Eg. PROJECT1 - UAT1) to change the value in change_config.xml which resides in /opt/IBM/Websphere/Appserver/My_Project/**UASPROJ0101JVM**/change_config.xml"
else

echo -e "Exiting the Script"
fi
###################END#####################

Contents of "change_config.xml"::

<?xml version="1.0" encoding="UTF-8"?>
<project>
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<env name="envvar" value="/opt/environment/environment.properties" />
<env name="JDBC_Driver" value="/opt/JDBC/ojdb6.jar" />
<env name="agent/enable" value="true" />
</project>
####################################################

And I'm trying to change the value of the parameter #<env name="agent/enable" value="true" /># using shell script.


As I said I'm just a beginner, So just started learning the things and implementing. This is what I had done so far with my basic knowledge on shell scripting!

I'm stuck with how the **UASPROJ0101JVM** JVM value can be passed (As the name of JVM varies for every Project & Enviroment) based on the USER input of PROJECT -- ENVIRONMENT variables.

Thanks again for your valuable time and Sorry again for this lenghty one!
 
Old 10-28-2015, 11:05 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I can see you've had a good go at this, but for menus, the 'select' built-in is usually the right tool.
See http://tldp.org/LDP/Bash-Beginners-G...ect_09_06.html & https://askubuntu.com/questions/1705...a-shell-script.
The latter also uses zenity for more user friendly appearance.

I would seriously consider re-doing your code the basis of these, then solving the final step.


HTH

PS please use code tags when posting code/data https://www.linuxquestions.org/quest...do=bbcode#code
 
1 members found this post helpful.
Old 10-28-2015, 11:32 PM   #9
jwizardc
LQ Newbie
 
Registered: Jul 2004
Posts: 12

Rep: Reputation: 0
I hate to be the asshole who brings this up, but are you asking us to do your homework for you?

-jimc
 
Old 10-28-2015, 11:49 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I don't think so; certainly sounds like work to me AND he's shown his code so far, which is really the requirement for help.
 
Old 10-29-2015, 06:12 AM   #11
ntu929
Member
 
Registered: Jun 2010
Location: India
Distribution: Ubuntu
Posts: 128

Rep: Reputation: 4
Thank you for the code.

General pointer for solving this issue:-

1. Introduce display of all the necessary variables at regular intervals in your code. This will help to understand if all the statements/variables are performing the intended functions or not(debugging).
 
Old 10-29-2015, 08:21 AM   #12
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 804

Rep: Reputation: 186Reputation: 186
My understanding:
Except for true/false for the last env_name, the scripts in all UATs of all projects are identical and have to be selected. So have 2 basic master scripts one for true and the other for false and simply overwrite them to the destination file in the corresponding chosen sub directory. (like **UASPROJ0101JVM**).

So you have to tell us the coding scheme for **UASPROJ0101JVM**. Presumably the beginning ** is the project number and the ending ** the UAT

Let us consider the UAT portion first. Think of 2 arrays. ENV_ARRAY which you have defined and ENV_DEST_ARRAY that would contain ('01' '02' '03' and so on til '15'). ie. corresponding to the respective element in ENV_ARRAY

Then when you search for validity in your code, change as below
i=0
for ENV in "${ENV_ARRAY[@]}"
do
if [[ "$Environment" == "$ENV" ]]
then
break ;
else
i=i+1

fi
done

Now have another loop for ENV_DEST_ARRAY to pick out the i the element and break; Clearly ENV_DEST_ARRAY can contain any text (path component).

So your path becomes
/opt/IBM/Websphere/Appserver/My_Project/UASPROJ{$component}{i}JVM/change_config.xml"

Now changing or toggling should be the easy part.

OK
PS: I have to test it out.
PPS:What does SIT in (SIT[1|2|3|4|5) in websphere jargon usually stand for?

OK

Last edited by AnanthaP; 11-02-2015 at 04:42 AM.
 
Old 10-29-2015, 11:23 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
SIT = System Integration Testing - not just a websphere thing.

There's a whole load of xxxT test acronyms, although ime its rarely adhered to in actuality.
Usually Test envs are just used to test whatever needs testing at that time ...
 
Old 10-30-2015, 01:55 AM   #14
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,102

Rep: Reputation: 181Reputation: 181
I'm stuck with how the **UASPROJ0101JVM** JVM value can be passed (As the name of JVM varies for every Project & Enviroment) based on the USER input of PROJECT -- ENVIRONMENT variables.

Pass the value to where?
 
Old 10-30-2015, 09:59 PM   #15
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
The code in bold below may help with formatting a string to suit your need.
Code:
Option=`echo "$X - $Environment"`
 
Jstr=${Environment:0:2}"PROJ"
echo "$Jstr"

printf -v Projpart "02d" $Component
Jstr=$Jstr$Projpart
echo "$Jstr"

temp=${Environment:3:1}
printf -v Envpart "%02d" $temp

Jstr=$Jstr$Envpart"JVM"
echo "$Jstr"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 09:03 AM
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-13-2013 12:20 AM
reading a file and sending mail by shell scripting..?? Plz help urgent..!! sukhdip Linux - Newbie 10 10-03-2011 03:16 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM


All times are GMT -5. The time now is 02:10 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration