Script use command mail

Reply

Join Date: Jul 2005
Posts: 4
Reputation: ciccio81 is an unknown quantity at this point 
Solved Threads: 0
ciccio81 ciccio81 is offline Offline
Newbie Poster

Script use command mail

 
0
  #1
Jul 30th, 2005
i have a problem :rolleyes: i have write this script
**************************************

#!/bin/bash
#use command mail for send a mail present in a directory

# i repeat this for how many e-mail are stored in my directory
# count number of file in directory
nummail= ls | wc -l
while [$nummail -gt 0]
do
email=$(ls ./email/*.eml | more)
nummail=' expr $nummail-1'
mail -s "PROVA PROVA "Administrator@dominio.loc < $(email)
done

***************************

nummail i have the number of file in directory....but i don't know how i can extract the single name of file present in the directory and used in the var email in the command mail.and repeat for all the file in the directory

i hope i explain well the problem sorry for my English.
Thanks a lot.

P.S i'm not a spammer is for thesis at university :o
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 17
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Script use command mail

 
0
  #2
Jul 30th, 2005
first off if your want you code to look better when posting to this forum use bb code tags
http://www.daniweb.com/techtalkforum...ment113-3.html

Bash is kind of picky, you need to use spaces with alot of stuff, but no spaces can be used when setting variables.

you need to space the following condition like this
Shell Scripting Syntax (Toggle Plain Text)
  1. while [ $nummail -gt 0 ]

you also need to use command substitutuion for some of your lines for example:
Shell Scripting Syntax (Toggle Plain Text)
  1. nummail= ls | wc -l
  2. nummail=' expr $nummail-1'
you can do substitiuion using these two different techniques, first
Shell Scripting Syntax (Toggle Plain Text)
  1. nummail=$(ls | wc -l)
  2. nummail=$(expr $nummail - 1) # notice the space on both sides of the minus operater
you can also use back ticks(not single quotes) for command substitution
Shell Scripting Syntax (Toggle Plain Text)
  1. nummail=`ls | wc -l`
  2. nummail=`expr $nummail - 1`

you can extract the first file with a .eml extention like this, and set it to a variable like this. I am assuming you are running the script from you mail directory
Shell Scripting Syntax (Toggle Plain Text)
  1. email=$(ls *.eml | head -n 1)


your code using a while statment works well. If you just need to do something to a list of files in a directory a for statment is much more efficient. This should work also
Shell Scripting Syntax (Toggle Plain Text)
  1. for email in *.eml
  2. do
  3. mail -s "PROVA PROVA" Administrator@dominio.loc < ${email}
  4. done

I have never used the mail command, I just used yours as an example
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 17
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Script use command mail

 
0
  #3
Jul 30th, 2005
just one more thought. for your code thie the while statment to work, the mail program must be deleteting the emails as they are sent. If it does not delete them, it will just send the first email over and over in the list indefinately.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 4
Reputation: ciccio81 is an unknown quantity at this point 
Solved Threads: 0
ciccio81 ciccio81 is offline Offline
Newbie Poster

Re: Script use command mail

 
0
  #4
Jul 31st, 2005
when i start the script occurs an error in the line of the command

Shell Scripting Syntax (Toggle Plain Text)
  1. mail -s "prova prova" Administrator@dominio.loc < $(email)
that say:

$(email): ambiguos redirect
email: command not found
emal: command non found

why???? :cry:
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 17
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Script use command mail

 
0
  #5
Jul 31st, 2005
I had my doubls about that command, I have never used 'mail' before. I do not have it installed, so I have no way of testing it. If I was to guess it would be something like this.
Shell Scripting Syntax (Toggle Plain Text)
  1. mail $email -s "prova prova" Administrator@dominio.loc

or using your syntax as a guide you could try this

Shell Scripting Syntax (Toggle Plain Text)
  1. mail -s "prova prova" Administrator@dominio.loc < ${email}

part of the problem was I enclosed email in () instead of {}, so that caused command substitiution. Make sure you use ${email} (like you did originally)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 7815 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC