Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script for checking file existance

Status
Not open for further replies.

pfildes

Programmer
Jun 17, 2004
54
GB
I have a problem of trying to identify whether a certain set of files in a source folder exist in a target folder.

I'm looking to create a HP-UX KSH script which when given the following as command line args would check if a file exists in both directories;

a) File pattern e.g. *.txt
b) Source directory
c) Target directory

Can anybody point me in the right direction, or explain how I begin to tackle this problem? [ponder]
 
Nothing to be honest!.

I have some experience of UNIX scripting but currently only regard myself as a novice. I am learning though or at least trying to.

With having some experience of Solaris I was thinking of something along the lines of;

lc $2 | foreach $1 in $2.......

however the "foreach" or even "for" command is not available on my HP-UX machine.

Any help with this would be greatly appreciated
 
Sorry - I wasn't trying to be flippant, just don't have much time at the moment! I take it lc is supposed to be ls?

You might want to look into find and the -mtime and -newer switches (search this forum too).

I want to be good, is that not enough?
 
ls SOURCE > source.lst
ls TARGET > target.lst

diff source.lst target.lst
 
pfildes,
If I understand your question correctly, this should work too:

#!/bin/ksh
SRC=/tmp
TRGT=/home/oracle/scripts
find $SRC $TRGT -name "*.txt"
exit
 
I managed to resolve my problem with the following script code;

Code:
cd $srcFolder
for aFile in `ls -C *.*`; do
    if [ ! -f $trgFolder/$aFile ]; then
        echo "Missing file: $aFile"
    fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top