Shell script to check if any file exists in 4 folders | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Shell script to check if any file exists in 4 folders

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-02-2009
a1_win a1_win is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 9 October 2013, 3:37 AM EDT
Posts: 81
Thanks: 0
Thanked 1 Time in 1 Post
Shell script to check if any file exists in 4 folders

Hi All,

working on AIX 5.3.

Requirement is:

Shell script in ksh to check if any file exists in 4 folders as below:

1. /FILE/INB/INT1
2. /FILE/INB/INT2
3. /FILE/INB/INT3
4. /FILE/INB/INT4

Thanks a lot for your time!

a1_win.
Sponsored Links
    #2  
Old 04-02-2009
vino's Avatar
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 9 April 2013, 8:19 AM EDT
Location: Sydney, Down Under
Posts: 2,847
Thanks: 0
Thanked 12 Times in 12 Posts
Quote:
Originally Posted by a1_win View Post
Hi All,

working on AIX 5.3.

Requirement is:

Shell script in ksh to check if any file exists in 4 folders as below:

1. /FILE/INB/INT1
2. /FILE/INB/INT2
3. /FILE/INB/INT3
4. /FILE/INB/INT4

Thanks a lot for your time!

a1_win.
Here is one way


Code:
#!/bin/ksh
#
for dir in 1 2 3 4
do
  cnt=$(ls /FILE/INB/INT{dir} | wc -l)
  if [[ $cnt -ne 0 ]] ; then
    echo "no file in /FILE/INB/INT{dir}"
  fi;
done;

Sponsored Links
    #3  
Old 04-02-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 12 April 2014, 10:59 AM EDT
Location: Toronto, Canada
Posts: 2,875
Thanks: 0
Thanked 108 Times in 101 Posts


Code:
filecount()
{
  [ -e "$1" ] && numfiles=$# || numfiles=0
}

for dir in /FILE/INB/INT1 /FILE/INB/INT2 /FILE/INB/INT3 /FILE/INB/INT4
do
  filecount "$dir"/*
  if [ $numfiles -gt 0 ]
  then
    printf "%d files in %s\n" "$numfiles" "$dir"
  fi
done

    #4  
Old 04-02-2009
d.f. d.f. is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 25 January 2012, 10:23 AM EST
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure how find behaves in AIX (or if this counts as a "script"), but...


Code:
 RESULTS = `find ./FILE/INB/INT[1-4] -type f | wc -l` 
 if [ $RESULTS gt 0 ] ; then
   echo "There are $RESULTS files"
 fi

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
HOW TO CHECK ONLY .C FILES EXISTS OR NOT IN A FOLDER using IF in C shell script? p.hemadrireddy Shell Programming and Scripting 17 02-08-2009 11:17 PM
Chek if a file exists in Ubuntu and Cent OS using shell script m_kk Shell Programming and Scripting 2 03-26-2008 10:32 AM
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 10:53 AM
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-05-2008 02:56 AM
Need Script to check whether user exists in the remote machine Srini75 SCO 1 09-07-2005 11:23 AM



All times are GMT -4. The time now is 08:40 PM.