Posted a Question Yesterday


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Posted a Question Yesterday
# 1  
Old 12-18-2007
Tools Posted a Question Yesterday

Was wondering if it was too stupid and got deleted? Because it's gone now from the board.

I was asking about For Loops ----?


#!/usr/bin/bash

bank=`cat /export/home/usr/banklist.txt`
cdir=`cat /export/home/usr/mountlist.txt`
for d in $cdir
do
ls -l /apps/data/custdata/$d/$i/incoming/
ls -l /apps/data/custdata/$d/$i/outgoing/

for d in $bank
do

ls -l /apps/data/custdata/$d/$i/incoming/
ls -l /apps/data/custdata/$d/$i/outgoing/
done;
done;

The question was asking how to fill in the variables from two different lists of files and when they match peform an action ls -ltr for example?

If this gets deleted it must mean I need to go to the Unix for dummies thread? Smilie

Last edited by xgringo; 12-18-2007 at 04:18 PM..
# 2  
Old 12-18-2007
Sorry. We had a technical problem yesterday and lost the database. We restored a backup, but we lost a couple of hours of posts.

I don't understand your question, but you show two "for" loops, one nested inside the other. No problem there. But both are using the same variable d. The inner loop needs its own variable.
# 3  
Old 12-18-2007
Ok well not sure I have one list say

lisa a

1
2
3
4

list b

d
e
f
g

So I need something like if $a and $b exist at the same time, then do

ls -l /apps/data/custdata/$a/$b/incoming/
ls -l /apps/data/custdata/$a/$b/outgoing/

The problem being soemtimes there will be an /apps/data/custdata/1/d/incoming/ directory but there will be also times when an /apps/data/custdata/3/f/incoming/ won't exist --- I want to do an ls on the two combos from the two different list files that match?
# 4  
Old 12-18-2007
Try something like:

Code:
for a in 1 2 3 4 ; do
   for b in d e f g ; do
       if [[ -d /apps/data/custdata/$a/$b/incoming/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/incoming/
       fi
       if [[ -d /apps/data/custdata/$a/$b/outgoing/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/outgoing/
       fi
   done
done

That -d is just testing to see if a directory exists with that path.
# 5  
Old 12-18-2007
Quote:
Originally Posted by Perderabo
Try something like:

Code:
for a in 1 2 3 4 ; do
   for b in d e f g ; do
       if [[ -d /apps/data/custdata/$a/$b/incoming/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/incoming/
       fi
       if [[ -d /apps/data/custdata/$a/$b/outgoing/ ]] ; then
          ls -l /apps/data/custdata/$a/$b/outgoing/
       fi
   done
done

That -d is just testing to see if a directory exists with that path.
I got zero out put when I ran the script so I did set -xv

and I got data like this

+ [[ -d /apps/data/custdata/tmp2/noma/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/lima/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/urma/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/filoma/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/triloma/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/cbass/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/estate/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/fondu/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/kingson/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/lupra/incoming/ ]]
+ [[ -d /apps/data/custdata/tmp2/jag/outgoing/ ]]
+ [[ -d /apps/data/custdata/tmp2/tyson/incoming

So it looks like it passed the if statement but doesn't get a + for the ls ?
# 6  
Old 12-18-2007
Quote:
Originally Posted by xgringo
So it looks like it passed the if statement but doesn't get a + for the ls ?
Do those directories, as listed, exist?
# 7  
Old 12-18-2007
Yes they do exist so they exist but I don't get an ls of them.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Solaris

This must be the dumbest question ever posted -T5140 power button

I have a T5140 and cannot find the power switch -is there an on/off button? Good grief ! Thank you in advance. joe (3 Replies)
Discussion started by: joboy
3 Replies

2. Post Here to Contact Site Administrators and Moderators

Spam being posted by user

The second post in this thread is spam. All of the other posts that I looked at by the same user are also spam. https://www.unix.com/shell-programming-scripting/152728-using-grep-returns-partial-matches-i-need-get-exact-match-nothing.html Don't know if the individual reply can be scratched,... (2 Replies)
Discussion started by: agama
2 Replies

3. Forum Support Area for Unregistered Users & Account Problems

Posted thread

Hi, I joined yesterday and posted a thread and received emails from people suggesting solutions. My problem is that when I tried to access my posting this morning by clicking on the link in an emial, it said I wasn't registered and I had to re-register and I can't find my posting. The emial I... (1 Reply)
Discussion started by: hdixon
1 Replies

4. What is on Your Mind?

How many has posted over 1000 posts????

Hey all, does any one know how many out of 49000 odd members have crossed the postings over 1000 messages???? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies

5. Post Here to Contact Site Administrators and Moderators

posted twice on same thread..

sorry! accidentally posted the same post twice on a thread.. could you please remove the second .. thanx moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies

6. Post Here to Contact Site Administrators and Moderators

how to delete a posted thread?

if any user think that the thread posted by them is not good and want to delete it how to do that? (1 Reply)
Discussion started by: sekar sundaram
1 Replies

7. Post Here to Contact Site Administrators and Moderators

minor issue on question that i had posted !!

to the moderators of this site... i posted a question several weeks ago about a egep -e if you look through my posts you will see that my question was fully plausible as a reasonable post that could have been answered even it was to say that I should search the man pages myself and find the... (4 Replies)
Discussion started by: moxxx68
4 Replies
Login or Register to Ask a Question