Sample Shell Script
Here is what you need to put in a shell script:#!/bin/bash # script to send simple email # email subject SUBJECT="SET-EMAIL-SUBJECT" # Email To ? EMAIL="admin@somewhere.com" # Email text/message EMAILMESSAGE="/tmp/emailmessage.txt" echo "This is an email message test"> $EMAILMESSAGE echo "This is email text" >>$EMAILMESSAGE # send an email using /bin/mail /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
Ref: http://theos.in/shell-scripting/send-mail-bash-script/
Change sender's email address
Use the following: mail -s "subject" mail1@server.com -- -r "from@fromserver.com" -f </path/to/file>
Ref: http://www.linuxquestions.org/questions/linux-newbie-8/option-to-specify-senders-address-in-mail-command-374223/
Change the lines
this command: echo “first line \nsecond line” will result in the below line:first line \nsecond line (as you can see there is no new line)
but this one: echo -e “first line \nsecond line” (with the -e) will result in what you want:
echo -e “first line \nsecond line”
first line
second line
http://techteam.wordpress.com/2008/09/25/n-not-creating-new-line-in-bash-script/
String contain test
string='My string';
if [[ $string =~ .*My.* ]]
then
echo "It's there!"
fi
Ref: http://stackoverflow.com/questions/229551/string-contains-in-bash
No comments:
Post a Comment