Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need some help here. I have a directory which has "x" no of files.
For each file it has data separated by "," !!! wow !! that is nice , we got delimiter now that makes life easy !!!
Now all what I want to do is any row(each row has 6 fields separated by ",") if it has 3 rd field as "abcdefgh" then I want to send that file as an attachment to user.
I have implemented the logic but it seems it send emails(spam) but all i want is just one email with that file(sending with uuencode).
Here is the code.
Code:
cd $BASE_DIRECTORY
for i in $(find $BASE_DIRECTORY -type f -mtime -7)
do
while IFS="," read -r rec1 rec2 rec3 _
do
if [[ "$rec3" == "abcdefgh" ]]; then
echo -e "$i is the requested file"
uuencode $i $i|mailx -s "Invalid record $i file" test@testme.com
else
echo "file $i is fine and does not need to sent"
fi
done<$i
done
Thank you ! It did worked. Anything else cool stuff or smart thing we can do make script faster? or anything cool thing which you can think at this stage?
Pretty down, shame we don't have mpack any other better alternative you can think of?
Don't have, can't find or not allowed to install?
Quote:
Originally Posted by sysmicuser
can you explain every line of it?
Sure:
Code:
# This is just a hedge as some tools tend to produce unexpected output if those environment variables are set differently:
LANG=C; LC_ALL=C; export LANG LC_ALL
# If the variable is empty then exit with a distinctive exit value:
[ -z "${BASE_DIRECTORY}" ] && exit 127
# If we can't cd into that directory then exit with a distinctive exit value:
cd "${BASE_DIRECTORY}" || exit 127
# Most of the time using a "while" loop is preferable [0]:
find "${BASE_DIRECTORY}" -type f -mtime -7|while read ITEM; do
# Using the comma as separator check the third value for that string
# and fill the variable with it.
RES=$(awk -F',' '{if ($3 == "abcdefgh") print}' "${ITEM}")
# if the variable isn't empty then do something with it:
[ ${#RES} -eq 0 ] || mpack -s "Invalid record in \"${ITEM}\"" \
"${ITEM}" test@testme.com
done
# Always exit nicely:
exit 0
How to do if I want to exit at the same time echo message and send it via email? means in addition to exit I want to echo some message and send some critical email. How to do?
---------- Post added 05-10-13 at 09:40 AM ----------
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.