| | |
Script use command mail
![]() |
•
•
Join Date: Jul 2005
Posts: 4
Reputation:
Solved Threads: 0
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
**************************************
#!/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
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 17
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
you also need to use command substitutuion for some of your lines for example:
you can do substitiuion using these two different techniques, first
you can also use back ticks(not single quotes) for command substitution
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
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
I have never used the mail command, I just used yours as an example
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)
while [ $nummail -gt 0 ]
you also need to use command substitutuion for some of your lines for example:
Shell Scripting Syntax (Toggle Plain Text)
nummail= ls | wc -l nummail=' expr $nummail-1'
Shell Scripting Syntax (Toggle Plain Text)
nummail=$(ls | wc -l) nummail=$(expr $nummail - 1) # notice the space on both sides of the minus operater
Shell Scripting Syntax (Toggle Plain Text)
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
Shell Scripting Syntax (Toggle Plain Text)
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)
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
•
•
Join Date: Jul 2005
Posts: 4
Reputation:
Solved Threads: 0
when i start the script occurs an error in the line of the command
that say:
$(email): ambiguos redirect
email: command not found
emal: command non found
why???? :cry:
Shell Scripting Syntax (Toggle Plain Text)
mail -s "prova prova" Administrator@dominio.loc < $(email)
$(email): ambiguos redirect
email: command not found
emal: command non found
why???? :cry:
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 17
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.
or using your syntax as a guide you could try this
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)
Shell Scripting Syntax (Toggle Plain Text)
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)
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)
![]() |
Similar Threads
- Mail command (Shell Scripting)
- A simple script to execute a command package (Shell Scripting)
- [Bash] problem with script in sed command (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: (Need Help !Urgent) In dump Command
- Next Thread: Shell Scripting help
Views: 7815 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





