Simple Email Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Email Script
# 1  
Old 03-15-2013
Linux Simple Email Script

Hi All,

Im completely new to scripting but I was wondering can somebody show me how to write a bash script so that if any file enters a specific directory that an email gets sent?

I am running a few backups on a few different machines and rysncing them to a remote device, For each server I have a directory name of each server so when a new backup file is received by the backup device I want it to send me a simple mail saying that the backup device got it.

The backup device is a readynas 1100 and runs linux so theres no hassle running cron jobs and scripts etc

I have the backups named by date so the file names are different each time for instance

When this file is received i need a mail sent
/ns2/named-2013-03-13_0940.tar

The File name the next day will be
/ns2/named-2013-03-14_0940.tar

Thanks in advance

James
# 2  
Old 03-15-2013
You can try with the following bash script but make sure you test it. There will be many more smart ways to do it.
Code:
#!/bin/bash
NOW=$(date +"%Y-%m-%e")
if ls *$NOW*
then
echo 'BACKUP DONE ' | mail -s backupreport ithelpdesk@enovatemedia.co.in
else 'file not found' | mail -s backupreport ithelpdesk@enovatemedia.co.in
fi


Last edited by Franklin52; 03-17-2013 at 05:59 AM.. Reason: code tags
# 3  
Old 03-15-2013
Linux

Thanks Kirfee

Is there somewhere i should enter where the files are in this script?

The output i am getting from this is :
Code:
ls: *2013-03-15*: No such file or directory
./rtapp1.sh: line 6: file not found: command not found
Null message body; hope that's ok

Im presuming that its because I didnt specify the directory

the directory is /RTAPP1/Dailybkup/

Sorry im completely new at this so i know I should add it but havent a clue where

Last edited by Franklin52; 03-17-2013 at 05:59 AM.. Reason: Code tags
# 4  
Old 03-15-2013
replace line as follows;
Code:
ls /RTAPP1/Dailybkup/*$NOW*


Last edited by Franklin52; 03-17-2013 at 06:00 AM.. Reason: Code tags
# 5  
Old 03-22-2013
Thanks Kirfee Im getting the hang of messing around with that script you gave me on other servers much appreciated. Think I will have to buy a book and teach myself,

I am having one issue on one server however is it possible to run yesterdays date in the script instead of todays date?

The issue I am having on one server is the backup runs close to midnight and sometimes it doesnt finish till after midnight so i was thinking if I can just see that the date before ran okay I can troubleshoot myself from there,

#!/bin/bash
NOW=$(date +"%e%m%y")
if ls /RTAPP1/Dailybkup/Dailybkup.$NOW.bz2
then
echo 'BACKUP Successfull RTAPP1' | mail -s BACKUP.Successfull.RTAPP1 support@xxx.com
else 'file not found' | mail -s Backup_Failed_RTAPP1_MOVE_TO_UNIX_QUEUE support@xxx.com
fi

SC-NAS1100:/emailscripts# cd /RTAPP!
-bash: cd: /RTAPP!: No such file or directory
SC-NAS1100:/emailscripts# cd /RTAPP1
SC-NAS1100:/RTAPP1# ls
Dailybkup
SC-NAS1100:/RTAPP1# cd Dailybkup/
SC-NAS1100:/RTAPP1/Dailybkup# ls
Dailybkup010113.bz2 Dailybkup051212.bz2 Dailybkup100313.bz2 Dailybkup150213.bz2 Dailybkup200113.bz2 Dailybkup251212.bz2
Dailybkup010213.bz2 Dailybkup060113.bz2 Dailybkup101212.bz2 Dailybkup150313.bz2 Dailybkup200213.bz2 Dailybkup260113.bz2
Dailybkup010313.bz2 Dailybkup060213.bz2 Dailybkup110113.bz2 Dailybkup151212.bz2 Dailybkup200313.bz2 Dailybkup260213.bz2
Dailybkup011212.bz2 Dailybkup060313.bz2 Dailybkup110213.bz2 Dailybkup160113.bz2 Dailybkup201212.bz2 Dailybkup261212.bz2
Dailybkup020113.bz2 Dailybkup061212.bz2 Dailybkup110313.bz2 Dailybkup160213.bz2 Dailybkup210113.bz2 Dailybkup270113.bz2
Dailybkup020213.bz2 Dailybkup070113.bz2 Dailybkup111212.bz2 Dailybkup160313.bz2 Dailybkup210213.bz2 Dailybkup270213.bz2
Dailybkup020313.bz2 Dailybkup070213.bz2 Dailybkup120113.bz2 Dailybkup161212.bz2 Dailybkup210313.bz2 Dailybkup271212.bz2
Dailybkup021212.bz2 Dailybkup070313.bz2 Dailybkup120213.bz2 Dailybkup170113.bz2 Dailybkup211212.bz2 Dailybkup280113.bz2
Dailybkup030113.bz2 Dailybkup071212.bz2 Dailybkup120313.bz2 Dailybkup170213.bz2 Dailybkup220113.bz2 Dailybkup280213.bz2
Dailybkup030213.bz2 Dailybkup080113.bz2 Dailybkup121212.bz2 Dailybkup170313.bz2 Dailybkup220213.bz2 Dailybkup281212.bz2
Dailybkup030313.bz2 Dailybkup080213.bz2 Dailybkup130113.bz2 Dailybkup171212.bz2 Dailybkup221212.bz2 Dailybkup290113.bz2
Dailybkup031212.bz2 Dailybkup080313.bz2 Dailybkup130213.bz2 Dailybkup180113.bz2 Dailybkup230113.bz2 Dailybkup291212.bz2
Dailybkup040113.bz2 Dailybkup081212.bz2 Dailybkup130313.bz2 Dailybkup180213.bz2 Dailybkup230213.bz2 Dailybkup300113.bz2
Dailybkup040213.bz2 Dailybkup090113.bz2 Dailybkup131212.bz2 Dailybkup180313.bz2 Dailybkup231212.bz2 Dailybkup301112.bz2
Dailybkup040313.bz2 Dailybkup090213.bz2 Dailybkup140113.bz2 Dailybkup181212.bz2 Dailybkup240113.bz2 Dailybkup301212.bz2
Dailybkup041212.bz2 Dailybkup090313.bz2 Dailybkup140213.bz2 Dailybkup190113.bz2 Dailybkup240213.bz2 Dailybkup310113.bz2
Dailybkup050113.bz2 Dailybkup091212.bz2 Dailybkup140313.bz2 Dailybkup190213.bz2 Dailybkup241212.bz2 Dailybkup311212.bz2
Dailybkup050213.bz2 Dailybkup100113.bz2 Dailybkup141212.bz2 Dailybkup190313.bz2 Dailybkup250113.bz2
Dailybkup050313.bz2 Dailybkup100213.bz2 Dailybkup150113.bz2 Dailybkup191212.bz2 Dailybkup250213.bz2
SC-NAS1100:/RTAPP1/Dailybkup# cd /emailscripts/
SC-NAS1100:/emailscripts# ls
notfound.txt rtapp1.sh rtapp1test.sh support@xxx.com
SC-NAS1100:/emailscripts# ./rtapp1.sh
ls: /RTAPP1/Dailybkup/Dailybkup.220313.bz2: No such file or directory
./rtapp1.sh: line 6: file not found: command not found
Null message body; hope that's ok
SC-NAS1100:/emailscripts#

---------- Post updated at 11:05 PM ---------- Previous update was at 10:52 PM ----------

Never mind some googling around helped me come up with

#!/bin/bash
#NOW=$(date +"%e%m%y")
yest=$(date --date="yesterday")
echo "$yest"
yest=$(date --date="yesterday" +"%e%m%y")

if ls /RTAPP1/Dailybkup/*$yest*
then
echo 'BACKUP Successfull RTAPP1' | mail -s BACKUP.Successfull.RTAPP1 support@xxx.com
else 'file not found' | mail -s Backup_Failed_RTAPP1_MOVE_TO_UNIX_QUEUE support@xxx.com
fi

thanks for your help
# 6  
Old 03-25-2013
Good to see....your issues resolved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

2. UNIX Desktop Questions & Answers

Need help with simple script

I work for a small internet company, and sometimes its useful to ping a certain IP over an open amount of time. I wrote a simple script that asks what IP you'd like to ping, and then pings it and puts it into a text file so that you can save the results. What i'd like though, is to have an infinite... (1 Reply)
Discussion started by: LelandSelene
1 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Simple Script Can u help please?

I have a file that contains these lines User ID Username -------- ---------- 7738626,zrazak 7783535,jvincigu 7805567,ldrennan 7805583,mtsakama I need to sort the names alphabetically How can I sort the lines based on the user names ? I would appreciate a quick reply anyone ... (1 Reply)
Discussion started by: mnassiri
1 Replies

5. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

6. Shell Programming and Scripting

help in my simple script

Hi friends I have a file with two colums separated by Tab, the second colum had some numbers like the following: koko 2 toto3 4 momo6 1 hoho 0 bobo5 3 I'm trying to make a script that give me the results for rows when the second colum value are greater than 1 I make the... (7 Replies)
Discussion started by: reaky
7 Replies

7. Shell Programming and Scripting

simple script

Experts, i've made a script in PHP. I'm looking for a script wat does the same but for Unix. Is there anyone who can make this for me (for free). I understand that normally you will only help and not make complete scripts but... With kindly regards Klaasjan Boven <?php // datum... (2 Replies)
Discussion started by: klaasjan
2 Replies

8. Shell Programming and Scripting

simple script help

TZ=`date +%Z`+24 ; a=`date +%Y-%m-%d`-----------greps 1 day ago date........ but this command greps date in files for 1 day ago date........even the current date is found inside the file..... is there any logic using this command that it will grep the last date entry made in file ,whether it... (4 Replies)
Discussion started by: ali560045
4 Replies

9. Shell Programming and Scripting

Need a simple script

I have just recently decided to install Unix on one of my home computers, and I am enjoying it so far. However, I have no knowledge of writing computer programs or scripts. What I need to accomplish is a way for me to create backup copies of certain files, but I want to be able to just type all of... (10 Replies)
Discussion started by: Relykk
10 Replies

10. UNIX for Dummies Questions & Answers

simple script

guys, I have a need for a simple script that scans all of our users home directories (/home/*) and looks to see if the executable bit is on. If it finds that a user has a file with an executable bit on, it will send an email to managment. (no users are supposed to have any programs of their own... (4 Replies)
Discussion started by: hedrict
4 Replies
Login or Register to Ask a Question