![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Copying multiple folders to local machine (don't know folder names) | leenyburger | UNIX for Dummies Questions & Answers | 5 | 06-12-2008 04:38 AM |
| Parse the .txt file for folder name and FTP to the corrsponding folder. | MeganP | Shell Programming and Scripting | 3 | 07-03-2007 10:54 AM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 02:25 AM |
| To get the file names. | surjyap | Shell Programming and Scripting | 1 | 10-10-2005 04:11 AM |
| File names | giantflameeater | UNIX for Dummies Questions & Answers | 9 | 11-24-2004 04:03 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I need help to create a shell script that does following: - do ls -1 and let all file names in the current folder - do wc for each file and if wc > 0 then send a mail. I am new to unix and do not know how to get filename one by one in a loop, so that wc can be done. I have done rest of the things but just looping all files is left. Please help! Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
can you try this:
Code:
ls -1 > flist
for f in `cat flist`
do
x=`wc $f | cut -c1-8`
if [ x -gt 0 ]
then
echo "send mail"
else
echo "do nothing"
fi
done
extract the character column from a wc command, instead of cut -c1-8... any idea, anyone ?? HTH....any comment is appreciated. thanks. added code tags for readability --oombera Last edited by oombera; 02-19-2004 at 07:27 AM. |
|
#3
|
|||
|
|||
|
Wonderful.
Quite not all, but your code gave me enough idea to implement this. Following is what I have done and its working great. Thanks a lot for your help. For your thinking about using cut, well I used awk as its easier and will give me complete field regardless of its size. Code:
#!/bin/ksh
strPath=`echo "/app70s/d001/staging/Test/BadFiles/"$1`
for file in `ls -l $strPath | grep -v drwx | awk '{print $9}'`
do
echo ":" $file
intCount=`wc $strPath/$file | awk '{print $1}'`
if [ $intCount != 0 ]
then
echo $file " contains bad records. Rows are failing." | mailx -s "Session Failed" mail.address@mail.server.com;
fi
done
Last edited by oombera; 02-19-2004 at 07:27 AM. |
|
#4
|
|||
|
|||
|
a problem with what you have writen is if the file/dir in question is not rwx for the owner. ie drx-
i would try something to the effect of Code:
case "$1" in
'-d')
DIR=${2:?"bad or missing Directory"}
for filelist in `ls $DIR`;do
filesize=`ls -l $DIR/$filelist|awk '{ print $5 }'`
if [[ $filesize == 0 ]];then
echo "$filelist is $filesize"|mailx -s "SUBJECT" user@host
fi
done
;;
*)
echo ""
echo "Usage: for $0 [-d] /directory/to/search"
echo ""
;;
esac
Last edited by Optimus_P; 06-28-2001 at 01:31 PM. |
|
#5
|
|||
|
|||
|
Totally agree. Actually my application is custom for my environment and so I did not bothered about finding any dir because BadFiles folder should not have any sub-folders.
But what you told me is totally acceptable and I'm sure going to implement this. Just in case if someone creates a folder in future! Thanks a lot for your inputs. Adarsh |
|
#6
|
|||
|
|||
|
ok i posted something completely diffearnt and works for any env.
|
|||
| Google The UNIX and Linux Forums |