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

first off if your want you code to look better when posting to this forum use bb code tags
http://www.daniweb.com/techtalkforums/announcement113-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

while [ $nummail -gt 0 ]

you also need to use command substitutuion for some of your lines for example:

nummail= ls | wc -l   
nummail=' expr $nummail-1'

you can do substitiuion using these two different techniques, first

nummail=$(ls | wc -l)
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

nummail=`ls | wc -l`
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

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

for email in *.eml
do
mail -s "PROVA PROVA" Administrator@dominio.loc < ${email}
done

I have never used the mail command, I just used yours as an example

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.

when i start the script occurs an error in the line of the command

mail -s "prova prova" Administrator@dominio.loc < $(email)

that say:

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

why???? :cry:

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.

mail $email -s "prova prova" Administrator@dominio.loc

or using your syntax as a guide you could try this

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.