The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK - conditional cause Rafael.Buria Shell Programming and Scripting 2 01-28-2008 01:24 PM
Else in If Statements chapmana UNIX for Dummies Questions & Answers 8 11-30-2006 08:07 AM
Conditional Statements cstovall Shell Programming and Scripting 1 05-15-2005 06:58 PM
or statements? Blip Shell Programming and Scripting 1 01-19-2004 04:08 PM
if statements lilas UNIX for Dummies Questions & Answers 2 03-22-2001 11:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-13-2007
xgringo xgringo is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
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 (permalink)  
Old 12-13-2007
xgringo xgringo is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
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 (permalink)  
Old 12-13-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0