Sponsored Content
Top Forums Shell Programming and Scripting Check Directory for files & Email Post 302968087 by MadeInGermany on Thursday 3rd of March 2016 03:00:30 PM
Old 03-03-2016
Quote:
Originally Posted by Peasant
You might want to try something like :
Code:
ls -al $dir > $file &&
if [ -s $file ]; then mail -s "$Subject" "$Recipients" < $file ; fi ||
printf "%s\n" "No files in directory or some other ls exit code error"

Hope that helps
Regards
Peasant.
Is the logic okay?
I would prefer a straight logic
Code:
if ls -al $dir > $file && [ -s $file ]
then
  mail -s "$Subject" "$Recipients" < $file
else
  printf "%s\n" "No files in directory or some other ls exit code error"
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if 3 files have same size in directory

I need to determine if any three files have the same file size in a specified directly? I have got as far as listing the file sizes but where to go from here? ls -al |sort -n -r +4 | awq '{print $5}' Thanks in anticipation (5 Replies)
Discussion started by: oggle
5 Replies

2. UNIX for Dummies Questions & Answers

Find & Copy Selected files to another Directory

I am wanting to find files within a directory that are over a certain number of days old and copy them to another directory. And unfortunately not having much luck.......is someone able to help. Would also like to add that there are literally thousands of files that I am wanting to copy in one... (3 Replies)
Discussion started by: hellfyre
3 Replies

3. UNIX for Advanced & Expert Users

Extracting the different files from directory & its sub directories

Hi Everyone, It would be helpful if someone helps me on this. Requirement: I have a directory which includes different types of files(for example *.java,*.class),but not restricted for only these types. I need to find the same types of file extensions from its directories and subdirectories... (3 Replies)
Discussion started by: rcvasu
3 Replies

4. Shell Programming and Scripting

Need to find occurrences of email domains in all files in a directory

Hello Everyone! I trust you are off to a great week! Trying to output the name and count of each uniquely occurring domain in the current directory for a portion of a script I'm building. Here's what I'm stuck on: - Need to find UNIQUE occurences of domains (*@domain.com) in ALL files in... (4 Replies)
Discussion started by: linuxhombre
4 Replies

5. Shell Programming and Scripting

Just listing size, timestamp & name of files in a directory

How can I list the files in a directory and just show the file size, date stamp, timestamp and file name.. I've been trying to ls -lrt the directory to a file and then use the cut command but I'm not having any luck with getting the proper results.. I thought i could use the -f switch and count... (4 Replies)
Discussion started by: Jazmania
4 Replies

6. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

7. Shell Programming and Scripting

How to check whether directory has files in it or not in shell script?

hi, I am having script in which i want to check if directory has any file in it or not. If directory contains a single or more files then and only then it should proceed to further operations... P.S.: Directory might have thousand number of files. so there might be chance of getting error... (4 Replies)
Discussion started by: VSom007
4 Replies

8. Shell Programming and Scripting

Check daily files arrival in a directory

Hi All, I wanted to write a script to check if set of files exist in a directory or not for a particular day. each file has a date stamp. Now i want to implement this - -i can check files of a particular date in a particular folder -generate log and send it to through email. Big THANKS !!... (5 Replies)
Discussion started by: flagboy2014
5 Replies

9. Shell Programming and Scripting

Compressing & removing files in a directory & subdirectory

Hi, I want a simple line of code that will compress files within a directory specified (parameter) and its subdirectories and also i want to remove files which are exactly 365 days old from the sysdate after this compression. Please help. Thanks, JD (8 Replies)
Discussion started by: Jesshelle David
8 Replies

10. UNIX for Beginners Questions & Answers

Check for files and move it to another directory - ksh

I'm trying to wirte ksh script for given requirement, but i unable to achive it. In dir1 directory I need to check for the files which suffixed with .csv or .txt, If there is no files, then i need to exit. If any files found I need to move the each file found to dir2 directory. I have to repeat... (4 Replies)
Discussion started by: Kayal
4 Replies
RAZOR-CHECK(1p)                                         User Contributed Perl Documentation                                        RAZOR-CHECK(1p)

NAME
"razor-check" - Razor Filtering Agent SYNOPSIS
razor-check [options] [ mail1 [ mail2 .. ] ] $ cat mbox | razor-check $ razor-check ./mbox $ razor-check -d mbox mail.1 mail.2 mail.3 DESCRIPTION
"razor-check" checks a mail against the distributed Razor Catalogue by communicating with a Razor Catalogue Server. It should be invoked before the mail is delivered or processed by a human. "razor-check" terminates with exit value 0 if the signature for the mail is catalogued on the server (spam) or 1 if the mail is not catalogued by the server (not a spam). "razor-check" should be invoked against every incoming mail by mail processors (like procmail) or MTAs (like sendmail). An alternate method would be to call "razor-check" from cron, at regular intervals, to identify and mark spam in queued mailboxes. If "razor-check" is passed more than one mail, it will check each against the database, printing out the serial number of every mail considered to be spam. "razor-check" supports mbox-formatted files with 1 or more mails in them as well as files containing a single RFC 822 (non-mbox) mail. More than one file may be present on the command line, can be either a non-mbox or mbox in any order. However, more than one non-mbox mail cannot be read from stdin. USAGE
"razor-check" is usually run by piping the contents of the mail to it, or by providing the name of the file that contains the mail message to be checked as the last argument. "razor-check" takes the following arguments: "-h" Print a usage message and exit. "-v" Print the version number and exit. "-d | --verbose" Print debugging information. "-debuglevel=n | -dl=n" Set debug level to 'n'. Default is 3 without "-d" option, 9 with. "-whitelist=file" Specify file to use for whitelisting. Overrides 'whitelist' option in "razor-agent.conf". "-s" Simulate a check. Do everything except talk to the server. "-conf=filename" Specifies an alternate configuration file. If not specified, it is computed, see razor-agents(1) manpage for details. See razor-agent.conf(5) manpage for various configuration options. The default is "<razorhome>/razor-agent.conf". "-home=dir" Specify razorhome directory. This is where the configuration file, logfiles, identities, and server files live. If not specified, it is computed, see razor-agents(1) manpage for details. "-logfile=file" Specify file to log to instead of what is in the configuration file. The default is "<razorhome>/razor-agent.log". "-rs=razor.server.com" Use this Razor Catalogue Server instead of reading "servers.catalogue.lst". "-H" Compute and print the signature of the mail contents and exit. If "-e=integer" is not specified, all supported engines will be used. "-S=string" Accept a list of pre-computed (with "-H") signatures on the command line, instead of computing one from mail content. Signatures can be submitted in hex or base64, but base64 is preferred. Requires "-e=integer". Usage: "razor-report -e 1 -S a8a3d545adb73f9733675571ffeaf10cba87745b" "-e=integer" Specify engine used to create signatures. Must be 1, 2, 3, or 4 in this version. Engine 1, or "-e=1", is used for Razor 1.x signatures. Used only with "-S=string" or "-H". "-ep4=string" String used by engine 4 when computing signatures. Published by the Razor Catalogue Servers and updated very frequently. Used only when "-e=4". RECIPES
"razor-check" is usually invoked from procmail(1). Here are some common ways of using it with procmail: To change the "Subject" header if mail is spam: :0 Wc | razor-check :0 Waf | formail -i "Subject: Razor Warning: SPAM/UBE/UCE" To add a "X-Razor2-Warning" header to spam: :0 Wc | razor-check :0 Waf | formail -A "X-Razor2-Warning: SPAM." To file spam in a mailbox :0 Wc | razor-check :0 Wa /home/foo/Mail/razor-caught AUTHORS
Vipul Ved Prakash <mail@vipul.net>, and Chad Norwood <chad@samo.org> SEE ALSO
razor-agents(1), razor-agent.conf(5), razor-admin(1), razor-report(1), razor-revoke(1), razor-whitelist(5) LICENSE
This is free software, distributed under the Artistic License 2.0. perl v5.14.2 2008-07-21 RAZOR-CHECK(1p)
All times are GMT -4. The time now is 11:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy