Enhancing Script (using loops) to go through for each group


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Enhancing Script (using loops) to go through for each group
# 1  
Old 05-01-2008
Enhancing Script (using loops) to go through for each group

Currently I have written a shell script that will add departments for one group (displayed below with configuration file). I want to enhance the script in order to add departments to multiple groups by:

1. Making changes to allow the script to loop through and write each dept/group combo into the DEPTFILE.

2. After I get the dept list from the config file, check to see if the Group flag is on and if it is, then create a loop to go through for each group.

In the original configuration file, only one country was passed in (Brazil). Since then, I changed the variable to ${Cntry_code} (instead of just Brazil) and I added US in the config file.
Please let me know if anymore information is needed

Thanks in advance

Here is the script that I have currently:

bin/ksh

############################################################################
# Program: add_BING_group.sh
# Desc : this manually executed script will allow you to add a group
# and/or depts in BING
# Notes : To run this script pass in the country code.
# add_BING_group.sh <country_code>
# It uses addGroup.cfg to get the correct information to add
# Be sure that you make the correct changes in the cfg file before
# running the script
#
#################################################################

## checking a script call for the proper number of arguments
if [ "$#" -ne 1 ]
then
echo "USAGE: $0 <country_code>"
exit 0
fi

Cntry_code=$1
GROUP=`stanzaget addGroup.cfg ${Cntry_code} group`
BINGDB=`stanzaget addGroup.cfg ${Cntry_code} database`
GROUPFLAG=`stanzaget addGroup.cfg ${Cntry_code} addGroupFlag`
DEPTFLAG=`stanzaget addGroup.cfg ${Cntry_code} addDeptFlag`

dept_groupSQL="/tmp/dept_group.sql"
text_SQL="/tmp/groupText.sql"
DEPTFILE="/tmp/deptfile.unl"
DEPT_GRP_UNL="/tmp/dept_back.unl"

PATH=$PATH:$ITOOLSDIR/bin
`rm ${DEPTFILE}`
if [ ${GROUPFLAG} = "ON" ]
then
PLANG_CODE=`stanzaget addGroup.cfg ${Cntry_code} pri_lang_code`
PGRP_TXT=`stanzaget addGroup.cfg ${Cntry_code} pri_text`
SLANG_CODE=`stanzaget addGroup.cfg ${Cntry_code} sec_lang_code`
SGRP_TXT=`stanzaget addGroup.cfg ${Cntry_code} sec_text`

echo " Begin work; " > ${dept_groupSQL}
echo " insert into ${BINGDB}:dept_group values(${GROUP}); " >> ${dept_groupSQL}
echo " commit work; " >> ${dept_groupSQL}

echo " Begin work; " > ${text_SQL}
echo " insert into ${BINGDB}:dept_group_text values(${GROUP},${PLANG_CODE},'${PGRP_TXT}'); " >> ${text_SQL}
echo " insert into ${BINGDB}:dept_group_text values(${GROUP},${SLANG_CODE},'${SGRP_TXT}'); " >> ${text_SQL}

echo " insert into ${BINGDB}:dept_group_text values(10,103,'${TGRP_TXT}'); " >> ${text_SQL}

echo " commit work; " >> ${text_SQL}
dbaccess ${BINGDB} < ${dept_groupSQL}
echo "Loaded the group table"
dbaccess ${BINGDB} < ${text_SQL}
echo "Loaded the text table"

fi

if [ ${DEPTFLAG} = "ON" ]
then
DEPTLIST=`stanzaget addGroup.cfg ${Cntry_code} dept_list`

`iunload -d ${BINGDB} -t dept_dept_group -compress -isolation dirty ${DEPT_GRP_UNL}`

if [ ${DEPTLIST} = "ALL" ]
then
DEPTLIST=`stanzaget addGroup.cfg ${Cntry_code} dept_list_all`

for d in `echo $DEPTLIST | sed 's/,/ /g'`
do

echo "$d|${GROUP}|" >> ${DEPTFILE}

done
fi

`iload -d ${BINGDB} -t dept_dept_group ${DEPTFILE}`

Fi






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Configuration File (addGroup.cfg)



US:
database = bingusa
group=0,1,2,3,4,5,6,7,8,9,10
group_text =
#addGroupFlag = OFF
addGroupFlag = ON
addDeptFlag = ON
dept_list=ALL
dept_list_all=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,75,77,80,81,82,8 3,84,85,87,88,90,91,92,93,94,95,96,97,98,99


Brazil:
database = bingbrazil
group = 11
#group = 10
#addGroupFlag = OFF
addGroupFlag = ON
addDeptFlag = ON
pri_lang_code = 101
pri_text=FALL/WINTER
sec_lang_code = 103
sec_text=AUTOMNE/HIVER
third_text=Printemps/Été
dept_list=ALL
dept_list_all=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,75,77,80,81,82,8 3,84,85,87,88,90,91,92,93,94,95,96,97,98,99
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looking to minimize 'for' loops in script

Hi, Below is the script that I came up with but looking to see if there is a more appropriate way to achieve this by reducing number of "for" loops or something. Regards, mbak #!/usr/bin/ksh status=missing for disk in `lspv | awk '{print $1}'` do MISSPATH=`lspath -l ${disk} -s... (3 Replies)
Discussion started by: mbak
3 Replies

2. Android

Enhancing the very limited Command Line.

Sometime ago, somewhere on here, I said I was going to do some coding for Android. I installed the full dev kit and a few months ago this MBP developed a failed HDD consequently destroying the dev environment. I got an Android phone for XMAS and downloaded a terminal program. I then found... (1 Reply)
Discussion started by: wisecracker
1 Replies

3. Shell Programming and Scripting

Script loops again and again and again and ...

Hi, Linux newbie here with what I'm guessing is silly questions. My script below is working in that it correctly copies files from the backup IP (10.0.91.1) back down to the Linux server but trouble is it loops continuously. It correctly downloads 100 files from the the IP 10.0.91.1... (1 Reply)
Discussion started by: MOWS
1 Replies

4. Shell Programming and Scripting

Expect script - going in loops can't stop

Hi First of all I tried lot of forums to create my first expect script. But I am totally stumped at the last step. I am no Linux Admin or ever trained in Linux. I just tried to create the script logically History : I need to to change my password across lot of servers in Linux over ssh ... (4 Replies)
Discussion started by: radioactive9
4 Replies

5. Red Hat

Enhancing security of temporary folder

While enhancing security of my temporary folder in the post described in Secure temporary folders on existing Unix or Linux systems | SysAdmin.MD my redirection fails. This commands always fails echo "/mnt/tmp /tmp ext3 loop,noexec,nosuid,rw 0 0" >> /etc/fstab Can anybody please tell my why? (1 Reply)
Discussion started by: synthea
1 Replies

6. Shell Programming and Scripting

Mailing script using loops

Hi all.. I'm not a scripter but I'm trying to set up a mail script that emails out once a file has been written to. Is there some way of writing a while read loop or something, so that it reads each line of the file and then ends when a specific number of lines have been written... We're... (2 Replies)
Discussion started by: Jazmania
2 Replies
Login or Register to Ask a Question