for i loop with conditional statements?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting for i loop with conditional statements?
# 1  
Old 12-13-2007
for i loop with conditional statements?

New to scripting in general, so patience plz. If I ask a stupid question or don't get it, I thank you for your kindness in advance.

That said, did a for i loops checks to see if a PB* file is there but I need to know two things before I copy the file.

I need to know if the file's create date is = to today and I also need to make sure I haven't copied it into the directory already. If I've already copied in the directory no need to copy it there again etc?

#!/bin/bash
oklist=`cat /export/home/jay01/scripts/oklist.txt`
for i in $oklist;
do
CHECKFILE="$(find /apps/migrate/output/rtdata/$i/Downloaded/ -name PB*)"
if [ -n "${CHECKFILE}" ]
then
echo "***************************************************************"
echo `date`
ls -ltr /apps/migrate/output/tdata/$i/Downloaded/
echo "***************************************************************"
cp -p /apps/migrate/output/tdata/$i/Downloaded/* /apps/migrate/usops/okdownload/
else
echo "***************************************************************"
echo " No Files to move in /apps/migrate/output/tdata/`echo $i`/Downloaded/ "
echo "***************************************************************"
fi
done;
# 2  
Old 12-13-2007
Ok how about I take out create date = today --- and just do if it's in the downloaded folder I don't want to repeat a copy.
# 3  
Old 12-13-2007
I'm reposting it reformatted so it's easier to understand...

Code:
#!/bin/bash
oklist=`cat /export/home/jay01/scripts/oklist.txt`
for i in $oklist
do
    CHECKFILE="$(find /apps/migrate/output/rtdata/$i/Downloaded/ -name PB*)"
    if [ -n "${CHECKFILE}" ]
    then
        echo "***************************************************************"
        echo `date` 
        ls -ltr /apps/migrate/output/tdata/$i/Downloaded/
        echo "***************************************************************" 
        cp -p /apps/migrate/output/tdata/$i/Downloaded/* /apps/migrate/usops/okdownload/
    else
        echo "***************************************************************"
        echo " No Files to move in /apps/migrate/output/tdata/`echo $i`/Downloaded/ "
        echo "***************************************************************"
    fi
done

now remember 'find' can return multiple answers, my general pattern with find is


Code:
find /apps/migrate/output/rtdata/$i/Downloaded -type f -name "PB*" | while read CHECKFILE
do
      if test -f "$CHECKFILE"
      then
                whatever
      fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For loop statements order of operations

Say I have a for loop that parse through a file....Say it look for the colors red and blue in sections of the file. Say it find red before it find blue in the file. Say I have two if statements in the for loop Something like if blue is found print blue is my favorite color is the first if... (7 Replies)
Discussion started by: scj2012
7 Replies

2. Shell Programming and Scripting

2 statements in for loop

Bash shell, variables i and rem are working fine in 2 separate for loops, but I'd like to consolidate them like this: for && This gives syntax error on &&. Thanks in advance for direction. (5 Replies)
Discussion started by: p1ne
5 Replies

3. Programming

Python Conditional Statements Based on Success of Last Command

In shell scripting, I can create a conditional statement based on the success or failure (exit status)of a command such as: pinger() { ping -c 2 $remote_host >/dev/null 2>&1 ping_stat=$? } pinger if ]; then echo "blahblahblah" exit 0 fi how is this done using Python using... (3 Replies)
Discussion started by: metallica1973
3 Replies

4. UNIX for Dummies Questions & Answers

Conditional execution of statements

Hi , I have a script which has multiple awk and sed commands like below. First one :- find /root/src/ -name "*csv" -size 0 -exec rm {} \; Second one: - ls *SRE*.txt > SRT_TRAN.dat rm *asr*.txt Third one :- find /root/src/ -name '*.csv' | while read FILENAME ; do awk... (2 Replies)
Discussion started by: shruthidwh
2 Replies

5. Shell Programming and Scripting

How to use awk or nawk by using Conditional Statements

Hi Guys! Anybody know how can I use a nawk or awk on a script and printing the NAME, SECTION (must be 410 or 411 or 414) and TOTAL COST of CLASS 1 and 3 combined must be greater than 50. See below desired output file. input.txt: NAME,CLASS,COST,SECTION JOHN,1,10,410 JOHN,2,20,410... (2 Replies)
Discussion started by: pinpe
2 Replies

6. Shell Programming and Scripting

vi and if statements

Hi I am very new to Unix programming and shell scripting. I am trying t figure out how to write a little script that will output the number of directories. I can find the number of directories using ls -l | grep "^d" | wc -l I can not figure out how to do it so when I type the name... (8 Replies)
Discussion started by: Reddoug
8 Replies

7. Shell Programming and Scripting

How to execute a no of SELECT COUNT(*) statements using a loop

HI Unix Gurus, I have a number of SELECT count(*) statements in an input file and I want to execute it using a shell script but one by one using loop in script.... How can I do this..... (7 Replies)
Discussion started by: ustechie
7 Replies

8. Shell Programming and Scripting

Logical and vs. conditional loop

Simple question. What's the difference (pros and cons) between these two: if ; then condition1 elif ; then condition2 fi \ && condition1 \ || condition2Is the second method faster as the whole line gets loaded into memory? Just looking for some tips of when I should use... (2 Replies)
Discussion started by: victorbrca
2 Replies

9. Shell Programming and Scripting

is that possible to keep statements in any loop??

Hi, Actually i stored all validdisks in one array and corresponding partitions required for all individual disks in other array.. Example: Validdisks=dsk2 dsk3 dsk5 ValidPartition=4 4 3 Now i have to create domain.. Domain creation can be done by below commands: fs_setup -d... (1 Reply)
Discussion started by: mansa
1 Replies

10. Shell Programming and Scripting

Conditional Statements

How can I compare two decimal values within a function using Bash? Function fun2 isn't comparing the decimal values. Is there a way to do this using Bash or Korn? #!/bin/bash set -x x=1 z=110 function fun1() { i=`bc << EOF 2>> /dev/null scale=3 ... (1 Reply)
Discussion started by: cstovall
1 Replies
Login or Register to Ask a Question

Featured Tech Videos