I am looking to parse a text file output and set variables based on what is cropped from the parsing.
Below is my script I am looking to add this feature too.
All it does is scan a certain area of users directories for anyone using up more than X amount of disk space. It then writes to the output file and emails the output file when done to a number of people that is defined in the script.
I want it to also email the username found in the output file.
Below the script is a sample output of what is emailed.
#!/bin/bash
_dufile="/tmp/testing-results.log"
MAILTO=myname@mydomain.com
rm -rf /tmp/testing-results.log
du -m -s /home/project_A/users/* | perl -ne '@l = split();print "@l\n" if $l[0]>=1960' > /tmp/testing-results.log
if [ -s "$_dufile" ]
then
echo "$_dufile has found user with over allowed data amount, emailing "
cat /tmp/testing-results.log | mailx -s " Testing user exceeded 2GB limit Quota Notification" $MAILTO
else
echo "$_dufile is empty."
fi
--------------------------
output file data in /tmp/testing-results.log :
39292 /home/project_A/users/jdoe
49200 /home/project_A/users/bsmith
89019 /home/project_A/users/rguy
Basically, I need to read the output of /tmp/testing-results seen above, and crop out everything except the username "jdoe" and "bsmith" and "rguy" and set each one to a variable. Then just plugging in those variables to my mailx list with a domain name added.
This will then send the output to myname@mydomain, and also the output sent to each person/user "jdoe" "bsmith" ect...
I'm sure there are a million ways of doing this and would highly appreciate any suggestions of the read and parse of my output file /tmp/testing-results
Thanks in advance.