Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Shell script to check if any file exists in 4 folders

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-02-2009
a1_win a1_win is offline
Registered User
 
Join Date: Apr 2005
Last Activity: 21 August 2014, 2:37 PM EDT
Posts: 86
Thanks: 3
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 Unix and Linux 04-02-2009
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 12 March 2015, 5:33 AM EDT
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 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 Unix and Linux 04-02-2009
cfajohnson's Unix or Linux Image
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 5 July 2015, 1:27 AM EDT
Location: Toronto, Canada
Posts: 2,893
Thanks: 0
Thanked 127 Times in 112 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 09:21 AM.