I am curious why you would feel the need to write such a script, doesn't most shells do that automagically if the MAIL environmental variable is set - see the bash and ksh manual pages. But should you feel the need:
Use the -e option, for as per the mail manual page on my (linux) system:
-e Just check if mail is present in the system mailbox. If yes, return an exit status of zero, else, a non-zero value. -E If an outgoing message does not contain any text in its first or only message part, do not send it but discard it silently, effectively setting the skipemptybody variable at program startup. This is useful for sending messages from scripts started by cron(8).
mail -E always returns true because you are not sending anything.
stat=`echo $status`
I am making an assumption, but it appears you are writing a Bourne-shell derived shell script (ksh, bash, etc), not a csh script. At any rate, the built-in shell variable $? contains the exit status of the previous command. So this statement should have been:
When assigning a value of a variable to another variable, there is no need to echo that value, you can simply assign it:
I highly recommend the use of quotes, it prevents unexpected behavior when a variable contains meta-characters such as "*" or "?". For example:
will assign the variable b to be the names of all the files in the current working directory.
In your case, use:
(Quotes even though $? is always be numeric? Can't be too careful!)
So now your script begins with:
Once you eliminate the echo statement, you eliminate the need for a temporary variable for mail's exit status, so you can simplify to: test (which "[" is an alias for) returns with an exit status of 0 if the expression evaluated to true. And since your are checking if the exit status of mail was 0, you really don't need the expression to check if it is zero, you can simply:
Hope this helps!
I need assistance with following requirement, I am new to Unix.
I want to do the following task but stuck with file creation date(sysdate)
Following is the requirement
I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
in Solaris 10 I am able to run:
find . -type f -name "copy*" exec grep example.com {} \;
and I get results.
but when I try to find and sed:
find . -type f -name "copy*" exec sed -e 's/user@example\.com/user2@example\.com' {} \;
the command executes correctly but doesn't change... (6 Replies)
Hi
I have a query that some of you may be able to help me with if poss? I'd appreciate it very much.
I've got a few log files, that I would like to search for a string. When the string is found, i'd then like to email out the line/sting.
If not found, i'd like to email out 'no found'... (2 Replies)
How to search for all files with matching strings -->
find + tar + gzip + uunecode/email them in one command?
I am sure there is a right way to pass list of files to tar, then compress tar file. Then send that as attachment using uuencode in one command.. Can we do that!? (3 Replies)
I am trying to come up with a script that will search for selected files and then email them to me.
For example, say I have a directory that has the following files:
AA_doug.txt
AA_andy.txt
BB_john.txt
APPLE_mike.txt
GLOBE_ed.txt
GLOBE_tony.txt
TOTAL_carl.txt
what is the best way to... (2 Replies)
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)
running a suse linux 10.
I'm trying to write a script that searches for a file with certain name and that has been modified less than 30 minutes ago, then search for a certain string in that file and email this string out. I have tried different combinations of find, grep and email but no luck... (7 Replies)
This is probably simple so forgive me...
I just want to find all files in a folder created within the last 10 minutes...
This is easy:
# find /home/folder -cmin -10
If the find command locates any files created in the last ten minutes I want it to send an email alert.
I just want to... (3 Replies)
Hi,
I have a datafile which has the following data and it can have much more records. The data set is as follows:
ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051215~184
3~U~00200~000011432~0~P~<
GS~FA~TC11A~U1CAD~051215~1843~000011432~X~002002
ST~997~0001... (6 Replies)