Too many for loops


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Too many for loops
# 1  
Old 05-27-2011
Too many for loops

My apologies for the long post....

I have a structure problem with my ksh script on linux.

right now it does what i want (which i know is the point) but its really really ugly and i know there must be a simpler way to achieve my task.

The data is a list of usernames. This list will help me get the system administrator responsible for the account.

The way i'm getting the information is this way.

List of users -> List of AD zones for account -> List of computers in that AD zone and with the list of computers ... i get the sysadmin's name.

Code:
USERNAMES:
toto1
toto2
toto3
toto4
LISTZONE:
dev_perf
uat_perf
prd_web
uat_web
LISTCOMPS:
compprd01
comdev01
comuat01

This is what i have right now.

Code:
sysresp()
{
print -n "ZONE: " $i "  HOST: " $comps " USER: " $n "   "
mysql "call gethostinfo('$comps')" | $AWK '
NR != 1 {
        for ( x=1; x<=2; x++) {
                if (length($4) == 0)
                 next
                if ($4 != LASTKEY)
                print "SYSRESP: " $4,$5
                LASTKEY = $4
        }
}'

for n in `awk '$3 !~ /^.*:$/ {print $3}' /tmp/gecos_check.txt | sed '/^$/d'`; do
        for i in `ListZones4Account $n`; do
                echo "ZONE: $i"
                for comps in `ListComputersInZone $i | awk -F. '{print $1}'`; do
                        sysresp
                        continue
                done
       done
       echo "Done for user $n"
done

sysresp is a mysql call that will list something like this.

Code:
APP1    DEV    JOHN DOE
APP2    DEV    MARIA DE SMITH
APP3    UAT     TOMMY GUN

What i would like is just something like this:

toto1 john doe
toto2 maria de smith
toto3 john doe

What i have right now

Code:
ZONE: dev_perf
ZONE:  dev_perf  HOST:  compdev1  USER:  toto1    SYSRESP: MARIA DE
SYSRESP: JOHN DOE
SYSRESP: STAN DAN
ZONE: uat_perf
ZONE:  uat_perf  HOST:  compdev2  USER:  toto1  SYSRESP: MARIA DE
SYSRESP: STAN DAN
SYSRESP: JOHN DOE
ZONE:  prd_perf  HOST:  compprd1  USER:  toto1    SYSRESP: STAN DAN
SYSRESP: MARIA DE
SYSRESP: JOHN DOE
######################
Done for user toto1
######################

As you can see its not really exploitable AND the same user can have multiple SYSRESP. Dont care to get them all. I just need one :-)

There must be a way to simplify this and most importantly a cleaner way to get the output.

Thanks.
# 2  
Old 05-27-2011
I don't know if it can do what you need, but i think you can still have a look at AD Explorer

A tool that is included in the excellent freeware "sysinternals Suite" from Mark Russinovich

Sysinternals Suite
# 3  
Old 05-27-2011
Thanks for the info. Will look it up.

Problem is that the functions (lookup this and that) are all house scripts which i haven't had the time to check out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help with for loops

Why wont my for statements work? Im trying to get this script to swich to a user an if you put in a start/stop/or restart paramater to do just that for each user. I commented out the actual start/stop actions to test it just by using echos and not do anything hasty in the environment but it... (0 Replies)
Discussion started by: LilyClaro
0 Replies

2. UNIX for Dummies Questions & Answers

loops with tr

Hello, I'm not sure if this is more appropriate for the 'unix for dummies' or the 'unix for experts' forum because I'm new to this forum and this is the second topic I've discussed, but if you could let me know which one was more appropriate for something like this, please do! So in tr (an... (2 Replies)
Discussion started by: juliette salexa
2 Replies

3. Shell Programming and Scripting

Loops

Hi All, I want to execute a script the number of times a user enters. Please can you advise on hor can I do the same. Many Thanks, Shazin (4 Replies)
Discussion started by: Shazin
4 Replies

4. Shell Programming and Scripting

Help with the 2 for loops

#!/bin/bash IFS=$'\n' A= a c b t g j i e d B= t y u i o p counter=0 found="" for i in $(cat $A) do for j in $(cat $B) do if then found="yes" fi done if then (1 Reply)
Discussion started by: vadharah
1 Replies

5. UNIX for Dummies Questions & Answers

Help with While Loops

I am traversing down a list, and I am not quite sure how to tell the loop to break when it's done going through the file. #!/bin/sh while : do read list <&3 echo $list done is the code. The file "list" is simply 5 4 3 2 1 any advice on how to break the loop after the file is... (1 Reply)
Discussion started by: MaestroRage
1 Replies

6. Shell Programming and Scripting

while loops

Hi I've a file like so: Now, I want to read my file and take ex. the Media ID and the Type for each groups of Media (Media1,Media2,...,Media(n): cat /tmp/file|\ while read FILE do while $(FILE|cut -d: -f1)=Media$i do #here will be some test, ex: #if Media ID < 23 ... (4 Replies)
Discussion started by: nymus7
4 Replies

7. UNIX for Dummies Questions & Answers

two loops

Hi, how can I use "for" to have two loops : this is my script : for i in (A B C) do for j in (a b c) do echo $i$j done done #End I want to print out Aa Ab Ac .... But I have error message : syntax error at line 1 : `(' unexpected Many thanks before. How should I use "for" ?? (2 Replies)
Discussion started by: big123456
2 Replies

8. UNIX for Dummies Questions & Answers

While Loops

I'm trying to create a loop that will prompt the user for 15 values, not forcing them to enter all 15. If the user enters through one or more of the prompts the null value needs to be converted to 0, otherwise set the parameter = to the value entered: ex. Please enter file no #1: 17920 ... (4 Replies)
Discussion started by: vdc
4 Replies

9. Shell Programming and Scripting

Loops within loops

I am running on HPUX using ksh. I have a script that uses a loop within a loop, for some reason the script seems to hang on a particuliar record. The record is fine and hits the condition in Blue. If I kill the 1st loop process the script continues on with no problem. Begin code> <Some... (8 Replies)
Discussion started by: bthomas
8 Replies

10. UNIX for Dummies Questions & Answers

loops?

hello....very new user to unix...and i have a question..i am not sure if there is such a thing For example...the user is asked if he likes Bananas....if he says yes.... echo You like Bananas $name at the end of the script it echos all that the user has entered so they can read it.... but... (1 Reply)
Discussion started by: jonas27
1 Replies
Login or Register to Ask a Question