Reputation: 1
I'm trying to execute the following loop inside my script in order to send mail to all users in a certain file that I write in earlier in the script. I check if the file $eUsers is not empty I execute the following:
for name in `cat $eUsers | cut -d' ' -f2`
do
echo "message" > /letter
cat /letter | mail -s "message" $name
done
cat $eUsers | cut -d' ' -f2
gets back the user name. I tried it out in the terminal, and it's working. I tried putting the above code in a separate file and replaced "$eUsers" with its path (/filename), and it worked without any problems. However, when I use that code in my script, after writing in the file $eUsers, it goes into an infinite loop. I dont' understand why it's doing so. In the original file, the infinite loop seems to occur because of the line cat /letter | mail -s "message" $name
.
Upvotes: 0
Views: 342
Reputation: 140237
#!/bin/bash
while read junk name; do
echo "message" | mail -s "message" "$name"
done < "$eUsers"
Upvotes: 2