LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help Me Please!! Script to email users from a list of directories they own (https://www.linuxquestions.org/questions/programming-9/help-me-please-script-to-email-users-from-a-list-of-directories-they-own-4175498218/)

Joejr4u 03-14-2014 03:20 PM

Help Me Please!! Script to email users from a list of directories they own
 
Hello,

I am sort of a newbie in scripting. I would like some tips and maybe a starting template for a script I can use in sending emails (read from a file) a message to multiple users based off another list I generated. This list has directories owned by the users and their usernames. What would be the best conditional statements to use?

Thanks

TB0ne 03-14-2014 03:38 PM

Quote:

Originally Posted by Joejr4u (Post 5134683)
Hello,
I am sort of a newbie in scripting. I would like some tips and maybe a starting template for a script I can use in sending emails (read from a file) a message to multiple users based off another list I generated. This list has directories owned by the users and their usernames. What would be the best conditional statements to use?

Thanks

The man pages on ls contain options you should check out. A simplistic way of doing it would be to do shovel an "ls -l" through awk to get the owner field and the file name, then operate on it.

Post what you've written/tried and tell us where you're stuck. Otherwise, there are MANY script templates/tutorials/sample code you can find easily. My posting signature has one, and the bash scripting tutorials on TLDP are excellent.

Joejr4u 03-14-2014 05:38 PM

#!/bin/bash

FILE=/path/to/file/listing # contains information of directory paths and server it resides. there are 3 different servers
TMPFILE=TEMPF # contains listing of users with most files
SCRIPT=/path/to/script
MAIL=/path/to/mail/message
#TMPDIR=TEMPD

for i in `awk '{print $3}' FILE` # column3 shows directory names

do

# script creates a listing of users with most directories (from most to least) and then output for each iteration into a temporary listing
echo $SCRIPT $i > $TEMPF

# The top two users will be sent a mail. TEMPF will be appended to body of MAIL
done

# next statements not complete
while "${TMPFILE}"/*; do
mailx -s "TEST EMAIL" -r test@mail.com "${MAIL##*/}" <"${}"
rm -r "${TMPFILE}"
done


I will appreciate your help in piecing together what I'm trying to achieve. I understand the logic of what I am trying to do but cannot translate it properly into scripting code.

Any suggestions will be helpful.

Thanks for the inputs,

Silverhawk

NevemTeve 03-16-2014 01:55 AM

Code:

while "${TMPFILE}"/*; do
While doesn't work this way. Try help for in bash.

Please read this topic: What information to include in a post and how to use code tags


All times are GMT -5. The time now is 01:12 PM.