hello,
i've just wrote the following :
more ./*.csv | grep -i XXX | echo "Dear XXX, This email is for informative purposes. Your total number of hours for the week of `date` is: `cut -d, -f2` hours Kindly note that the average weekly working hours is : 40." | /usr/sbin/sendEmail -t mail@domain.com -u Test email- disregard it -f othermail@subdomain.com -s smtp.domain.com:25
this looks in a csv file that exists in the same directory for XX and outputs the field right next to it as you notice from : `cut -d, -f2`
It's working pretty fine for just one user, but i have to do the same for 432 person. and its obviously not as professional as it should be due to the following reasons:
1. i have to fill the name for each person in place of XXX as well as their MAIL@domain.com 2. the date command gives the hour as well which is a bit annoying
can anyone guide me on how to proceed? as you notice im a bit of a newbie with bash and im trying my best to improve my one liners/scripts
thanks :)
_________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969
From: Roland RoLaNd r_o_l_a_n_d@hotmail.com
i've just wrote the following : more ./*.csv | grep -i XXX | echo "Dear XXX, This email is for informative purposes. Your total number of hours for the week of `date` is: `cut -d, -f2` hours Kindly note that the average weekly working hours is : 40." | /usr/sbin/sendEmail -t ymailto="mailto:mail@domain.com" href="mailto:mail@domain.com">mail@domain.com -u Test email- disregard it -f href="mailto:othermail@subdomain.com">othermail@subdomain.com -s smtp.domain.com:25
this looks in a csv file that exists in the same directory for XX and outputs the field right next to it as you notice from : `cut -d, -f2` It's working pretty fine for just one user, but i have to do the same for 432 person. and its obviously not as professional as it should be due to the following reasons:
- i have to fill the name for each
person in place of XXX as well as their href="mailto:MAIL@domain.com">MAIL@domain.com 2. the date command gives the hour as well which is a bit annoying
I don't really get if you have 1 csv file with one person, per line, or one file per person, or...but:
IFS=, cat *.csv | while read do set $LINE USER=$1 TIME=$2 WEEK=`date +"%V"` ... done
JD
From: John Doe jdmls@yahoo.com
cat *.csv | while read
Oops, add LINE after the read
IFS=, cat *.csv | while read LINE do set $LINE USER=$1 TIME=$2 WEEK=`date +"%V"` ... done
JD
On 03/24/2010 04:48 AM, Roland RoLaNd wrote:
hello,
i've just wrote the following :
more ./*.csv | grep -i XXX | echo "Dear XXX, This email is for informative purposes. Your total number of hours for the week of `date` is: `cut -d, -f2` hours Kindly note that the average weekly working hours is : 40." | /usr/sbin/sendEmail -t mail@domain.com -u Test email- disregard it -f othermail@subdomain.com -s smtp.domain.com:25
this looks in a csv file that exists in the same directory for XX and outputs the field right next to it as you notice from : `cut -d, -f2`
It's working pretty fine for just one user, but i have to do the same for 432 person. and its obviously not as professional as it should be due to the following reasons:
- i have to fill the name for each person in place of XXX as well as their MAIL@domain.com
- the date command gives the hour as well which is a bit annoying
can anyone guide me on how to proceed? as you notice im a bit of a newbie with bash and im trying my best to improve my one liners/scripts
How about:
for i in *.csv do HOURS=`cat $i | cut -d, -f2` USER=`cat $i | cut -d, -f<user name field>` DATE=`date <plus formatting options>` echo "Dear $USER, This email...for week of $DATE is: $HOURS ..." done
The <text> portions are bits you will need to change for your environment. You can also put this in a file and script it instead of having to type it out every time. To be more specific we would need to know if there is just one .csv file or one file per user and the format of each line.
John
On Wed, Mar 24, 2010 at 4:48 AM, Roland RoLaNd r_o_l_a_n_d@hotmail.com wrote:
hello,
i've just wrote the following :
more ./*.csv | grep -i XXX | echo "Dear XXX, This email is for informative purposes. Your total number of hours for the week of `date` is: `cut -d, -f2` hours Kindly note that the average weekly working hours is : 40." | /usr/sbin/sendEmail -t mail@domain.com -u Test email- disregard it -f othermail@subdomain.com -s smtp.domain.com:25
this looks in a csv file that exists in the same directory for XX and outputs the field right next to it as you notice from : `cut -d, -f2`
It's working pretty fine for just one user, but i have to do the same for 432 person. and its obviously not as professional as it should be due to the following reasons:
- i have to fill the name for each person in place of XXX as well as their MAIL@domain.com
- the date command gives the hour as well which is a bit annoying
can anyone guide me on how to proceed? as you notice im a bit of a newbie with bash and im trying my best to improve my one liners/scripts
:D I had a similar assignment once.. The cleanest approach is to use awk instead of grep and cut. With awk you can specify fields in the input as $2, $3, etc..
Kwan wrote:
On Wed, Mar 24, 2010 at 4:48 AM, Roland RoLaNd r_o_l_a_n_d@hotmail.com wrote:
i've just wrote the following :
^^^^^ written
more ./*.csv | grep -i XXX | echo "Dear XXX, This email is for informative purposes. Your total number of hours for the week of `date` is: `cut -d, -f2` hours Kindly note that the average weekly working hours is : 40." | /usr/sbin/sendEmail -t mail@domain.com -u Test email- disregard it -f othermail@subdomain.com -s smtp.domain.com:25
<snip>
- i have to fill the name for each person in place of XXX as well as
their MAIL@domain.com 2. the date command gives the hour as well which is a bit annoying
can anyone guide me on how to proceed?
<snip>
:D I had a similar assignment once.. The cleanest approach is to use awk instead of grep and cut. With awk you can specify fields in the input as $2, $3, etc..
Yep. awk's the tool you want (I can hear the perl Is The Answer believers yelling <g>). awk -v DATE=`date` -f yourscript.awk would pass the system date in. Beyond that, the script's incredibly simple, if all your data is in the .csv, and all on one line. The final email could be sent either by doing cmd = "echo " awkvariable " | email -s woohoo " $<whatver field number the username is>"; system cmd; or you can have awk print it out, and pipe the output of awk through mail. I think the former's cleaner.
mark
On 3/24/2010 3:48 AM, Roland RoLaNd wrote:
hello,
i've just wrote the following :
more ./*.csv | grep -i XXX | echo "Dear XXX, This email is for informative purposes. Your total number of hours for the week of `date` is: `cut -d, -f2` hours Kindly note that the average weekly working hours is : 40." | /usr/sbin/sendEmail -t mail@domain.com -u Test email- disregard it -f othermail@subdomain.com -s smtp.domain.com:25
this looks in a csv file that exists in the same directory for XX and outputs the field right next to it as you notice from : `cut -d, -f2`
It's working pretty fine for just one user, but i have to do the same for 432 person. and its obviously not as professional as it should be due to the following reasons:
- i have to fill the name for each person in place of XXX as well as their MAIL@domain.com
You need to provide more information here. Does each XXX have its own directory (like /home/user)?
cd /home for USER in * do ... done
Or are the names all in one csv file in another field you can find on the same line as the hours?
while read LINE do USER=`cut -d, -f<name_field_number> $LINE` ... done <file.csv
- the date command gives the hour as well which is a bit annoying
date can give about any format you want with a +format option.
can anyone guide me on how to proceed? as you notice im a bit of a newbie with bash and im trying my best to improve my one liners/scripts
Just remember the perl can do everything the shell can do and much more, so if you run into trouble you can always switch to perl.