Sponsored Content
Full Discussion: Counting up files
Operating Systems Solaris Counting up files Post 302204399 by Pablo_beezo on Wednesday 11th of June 2008 12:16:30 PM
Old 06-11-2008
Counting up files

Hi,

I have a load of if statements that look for files in a directory, I want to be able to count them up and the total files confirmed in an email? I ahve tried expr but i this does not work and it only reads in the first if and ignores the rest.

Please see script,

#!/bin/ksh

###########
#VARIABLES#
###########

RUNREF=`date +%Y%m%d`
DIR="../files/"
EMAIL="cdmspb"
MAIL_FROM="******"

email_user()
{
#Email
mail -t "$1" << EOF
Subject: $3
From: $2
$4
$5
$6
EOF
}

##########################################################################
#check files are in a directory and once it has checked, email out to user#
##########################################################################

TOTAL_FOUND="0"

#echo "Look for file $DIR/abc.txt"
if [ -f ${DIR}abc.txt ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/def.out"
if [ -f {$DIR}def.out ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/ghi.dat"
if [ -f {$DIR}ghi.dat ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/jkl.csv"
if [ -f {$DIR}jkl.csv ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/mno.txt"
if [ -f {$DIR}mno.txt ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/pqr.dat"
if [ -f {$DIR}pqr.dat ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/stu.txt"
if [ -f {$DIR}stu.txt ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/vw.dat"
if [ -f {$DIR}vw.dat ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file $DIR/xy.dat"
if [ -f {$DIR}xy.dat ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi

#echo "Look for file z.dat"
if [ -f {$DIR}z.dat ]
then
TOTAL_FOUND=`expr $TOTAL_FOUND + 1`
fi


FILE_LIST=`find $DIR`

# email all users
email_user "$EMAIL" "$MAIL_FROM" "Finished Running File Check : $RUNREF" "$TOTAL_FOUND File/s Found" "File/s available are" "$FILE_LIST"

##################################################

it is the TOTAL_FOUND that is not adding up at the end and when i get an email it only reads the first file lookup??

any help would greatly be appreciated!
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting Occurances in Two Files

I have two files I want to compare, one is a list of variables and the other is a text file COBOL program. Basically what I want to do is display only those variables that appear in the COBOL program only once. However I would also accept a count of each variable as it appears in the COBOL... (2 Replies)
Discussion started by: Keith Gergel
2 Replies

2. UNIX for Dummies Questions & Answers

counting files

Which one line command can count and print to the screen the number of files containing "a" or "A" in their name (5 Replies)
Discussion started by: Edy
5 Replies

3. UNIX for Dummies Questions & Answers

Counting lines and files

Hi experts, First of all thanks for all your help. How can i count the lines within a text file and send this number to another text file? And by the way how can i count the number of files inside a tape ("/dev/rtp") that as one pattern (Ex. "/CTA/") and send this number to a text file? I... (6 Replies)
Discussion started by: jorge.ferreira
6 Replies

4. Shell Programming and Scripting

Help with counting files please

Hi all. If I have a unix directory with multiple files, lets say, I have some with .dat extensions, some with .txt extensions, etc etc. How in a script would I provide a count of all the different file types (so, the different extensions, I guess) in the directory?? So if I had: test.dat... (6 Replies)
Discussion started by: gerard1
6 Replies

5. UNIX for Dummies Questions & Answers

Counting rows in many files

I'm regularly counting the number of rows in a number of files. I need to know how many rows their are in all files together. Counting rows in one file I can handle, but how do I count rows in all at once? I'd be grateful for any answer. (7 Replies)
Discussion started by: DrZoidberg
7 Replies

6. Shell Programming and Scripting

counting prefixes of files

Hello, at the moment I'm on with programming some kind of version history script for network devices. The configration files are uploaded in the form: devicename-confg_date_time. For keeping the last 10 configurations I want to split the devicename from the rest. This works well with... (5 Replies)
Discussion started by: Sally[-_-]
5 Replies

7. Shell Programming and Scripting

multiple files: counting

In a directory, I have 5000 multiple files that contains around 4000 rows with 10 columns in each file containing a unique string 'AT' located at 4th column. OM 3328 O BT 268 5.800 7.500 4.700 0.000 1.400 OM 3329 O BT 723 8.500 8.900... (7 Replies)
Discussion started by: asanjuan
7 Replies

8. Shell Programming and Scripting

Counting Files

In a script, how would I go about finding the number of files for the first parameter after my script name? For instance, my script name is myscript.sh and the folder I am checking is not the current working directory, lets say it's folder1. so I type myscript.sh folder1 This script below... (2 Replies)
Discussion started by: Confirmed104
2 Replies

9. UNIX for Dummies Questions & Answers

Counting files without ls or wc

i need to write a shell script to "count the number of files in the current directory but without using either ls or wc command"..... please help! (1 Reply)
Discussion started by: lexicon
1 Replies
AUTOCONF(1)						      General Commands Manual						       AUTOCONF(1)

NAME
autoconf2.13 - creates scripts to configure source code packages using templates SYNOPSIS
autoconf2.13 [ --help | -h ] [ --localdir=dir | -l dir ] [ --macrodir=dir | -m dir ] [ --version ] DESCRIPTION
To create configure from configure.in, run the autoconf2.13 program with no arguments. autoconf2.13 processes configure.in with the m4 macro processor, using the Autoconf macros. If you give autoconf2.13 an argument, it reads that file instead of configure.in and writes the configuration script to the standard output instead of to configure. If you give autoconf2.13 the argument -, it reads the standard input instead of configure.in and writes the configuration script on the standard output. The Autoconf macros are defined in several files. Some of the files are distributed with Autoconf; autoconf2.13 reads them first. Then it looks for the optional file acsite.m4 in the directory that contains the distributed Autoconf macro files, and for the optional file aclo- cal.m4 in the current directory. Those files can contain your site's or the package's own Autoconf macro definitions. If a macro is defined in more than one of the files that autoconf2.13 reads, the last definition it reads overrides the earlier ones. autoconf2.13 accepts the following options: --help -h Print a summary of the command line options and exit. --localdir=DIR -l DIR Look for the package file aclocal.m4 in directory DIR instead of in the current directory. --macrodir=DIR -m DIR Look for the installed macro files in directory DIR. You can also set the AC_MACRODIR environment variable to a directory; this option overrides the environment variable. --version Print the version number of Autoconf and exit. SEE ALSO
autoheader2.13(1), autoreconf2.13(1), autoscan2.13(1), autoupdate2.13(1), ifnames2.13(1) AUTHORS
David MacKenzie, with help from Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor, Roland McGrath, Noah Friedman, David D. Zuhn, and many others. This manpage written by Ben Pfaff <pfaffben@debian.org> for the Debian GNU/Linux autoconf2.13 package. Autoconf AUTOCONF(1)
All times are GMT -4. The time now is 11:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy