Register
It is currently Fri Oct 31, 2014 6:48 am

script run mailto command to specific persons


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Sat May 31, 2008 4:35 pm   

Joined: Sat May 31, 2008 4:22 pm
Posts: 3
Hello everyone.
I have 2 files that I need to compare and send text messages to.

File one has the following.........
11111 Lastname FirstName ParentLastName ParentFirstName 10digitnumber@vtext.net
22222 Lastname FirstName ParentLastName ParentFirstName 10digitnumber@vtext.net
and so on and so on. The first field is the student number. Some of the entries have no last field like so
33333 Lastname FirstName ParentLastName ParentFirstName

My other file looks like the following.....

00001 11111 Subject 8 A
00002 11111 Subject 8 C+
00003 11111 Subject 8 B
00004 22222 Subject 12 A
00005 22222 Subject 11 F
00006 22222 Subject 12 C

What i would like to have done is an text message be send via the mailto command so that any students with a email addrs in file one get the grades corresponding to file 2. So that the text message would look like
22222 Subject 12 A
22222 Subject 11 F
22222 Subject 12 C

Any ideas would be greatly appreciated. I have been using awk to print the correct fields but am having trouble matching the student number in file to to mail the correct grades.
Again any input would be greatly appreciated.
Thank you
Bo


Top
 Profile  
 PostPosted: Mon Jun 02, 2008 10:48 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
I think there are a few ways you can do this sort of thing... once you find the student ID number, you should just be able to grep the grades file. For this type of data however, it might be worth learning MySQL.


Top
 Profile  
 PostPosted: Mon Jun 02, 2008 11:18 am   

Joined: Sat May 31, 2008 4:22 pm
Posts: 3
I can use awk to show the appropriate fields, but how do I set multiple variables so that I can store student ID and 10digit@vtext.com and then get the grades to the appropriate sections in my grade file? I guess a question to start would be how would I assign or re-assign a variable for each line. For example if I do
awk '/@/ {print $1,$6}' emailphonetest it returns
33539 10digit@message.alltel.com
31826 10digit@vtext.com

How would I set a variable for both of these entries so that I could grep the grades file?
Thanks


Top
 Profile  
 PostPosted: Mon Jun 02, 2008 4:26 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
rename files "filewithemails" and "filewtihgrades", this script does it, i hope all studen numbers like on example ;)
Code:
#!/bin/bash
#author:myownshadow
for ind in `cat filewithemails|cut -d " " -f1`
do
   cat filewithgrades|cut -c6-100 | grep $ind  > $ind.txt
   emailaddress=`cat filewithemails|grep $ind|cut -d " " -f6`
   mail -s "Your grades"  $emailaddress < $ind.txt
   echo "mail sent to $emailaddress"
   rm $ind.txt
done


Top
 Profile  
 PostPosted: Tue Jun 03, 2008 7:08 am   

Joined: Sat May 31, 2008 4:22 pm
Posts: 3
All student numbers are the same length 5. Just so I understand this a little better....Could you explain
for ind in `cat filewithemails|cut -d " " -f1`
Thanks again for all your help


Top
 Profile  
 PostPosted: Tue Jun 03, 2008 9:24 am   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
Code:
#!/bin/bash   #interpreter
#author:myownshadow   #me and myself
for ind in `cat filewithemails|cut -d " " -f1`     # for  loop for each student number in file with emails  , cut -d " " -f1 for taking only student number from the line, f1 means its the first fragment exploded by space
do
   cat filewithgrades|cut -c6-100 | grep $ind  > $ind.txt
   #cut -c6-100   cuts the line number out for line number and student number mismatch
   #grep $ind     getting the for loop indexed student number grade lines
   #> $ind.txt     saving them to a file named as student number
   emailaddress=`cat filewithemails|grep $ind|cut -d " " -f6`
   #relook for email in first file -f6  (its the 6th parameter if we explode for spaces)
   mail -s "Your grades"  $emailaddress < $ind.txt
   #nothing to explain
   echo "mail sent to $emailaddress"
   #ok what  i do
   rm $ind.txt
   #remove the crap
done  #finished




Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP