Basically, I am gathering data and storing the data into file "test.txt". I have specified the Day for which email will be sent to Specified Condition with "test.txt" file as an attachment. Every time I run that bash file it will append the data to an existing file.
USAGE:
1) Install MUTT Mail Sending application in your machine.
I have tried with this command `sudo apt-get install mutt`
2) Save the below given code with `.sh` extension.
3) To Run this File type following code: `sh filename.sh`.
4) Create one file named as "test.txt".
5) Keep both 'test.txt' and `filename.sh` in same Directory(Demo).
let path for file = /var/www/Demo/
#!/usr/bin/sh
{
now=$(date +"%m_%d_%Y")
today_date=$(date +"%A")
MAIL_BODY=$(cat <<'END_HEREDOC'
Hi Guest,
This is just a Test mail
END_HEREDOC
)
echo "The following commands executes at: " `date`;
echo " This is the Test Data that will stored in Test File";
if [ "$today_date" = "Friday" ]; then
echo "$MAIL_BODY" | mutt -a "/var/www/Demo/test.txt" -s "Mail Subject - $now" -- danish@bhea.co.in
fi
echo "\n\n";
} >> test.txt
NOTE: I have written this script for ubuntu system and it works fine. In case of other platform you have to check the dependency of your system.
USAGE:
1) Install MUTT Mail Sending application in your machine.
I have tried with this command `sudo apt-get install mutt`
2) Save the below given code with `.sh` extension.
3) To Run this File type following code: `sh filename.sh`.
4) Create one file named as "test.txt".
5) Keep both 'test.txt' and `filename.sh` in same Directory(Demo).
let path for file = /var/www/Demo/
#!/usr/bin/sh
{
now=$(date +"%m_%d_%Y")
today_date=$(date +"%A")
MAIL_BODY=$(cat <<'END_HEREDOC'
Hi Guest,
This is just a Test mail
END_HEREDOC
)
echo "The following commands executes at: " `date`;
echo " This is the Test Data that will stored in Test File";
if [ "$today_date" = "Friday" ]; then
echo "$MAIL_BODY" | mutt -a "/var/www/Demo/test.txt" -s "Mail Subject - $now" -- danish@bhea.co.in
fi
echo "\n\n";
} >> test.txt
NOTE: I have written this script for ubuntu system and it works fine. In case of other platform you have to check the dependency of your system.
No comments:
Post a Comment