Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i want to write bash file perform the following steps :-

copy file from server1 to server2

if (copy success )

do nothing

if (copy failed )

send e-mail to admin@company.com contain the following information

file name [copy failed]

share|improve this question

1 Answer 1

up vote 5 down vote accepted

On server1 --

SOURCE=a.txt
DEST=a.txt
R_HOST=server2

scp $SOURCE $R_HOST:$DEST || mutt -s "[copy failed] Copy of $SOURCE failed" admin@company.com

Requires you have mutt installed. If you don't, get mutt, or replace the mutt portion with a sendmail alternative.

share|improve this answer
4  
Almost all variants of Unix and Linux (including AIX) include the ancient mail program. You can just replace mutt with mail in your command and get the same result and it's basically guaranteed to work. –  mattdm Nov 27 '10 at 19:45
    
@mattdm - agreed. No reason to create an un-needed dependency here. –  EEAA Nov 27 '10 at 20:06
    
cool, thanks guys. i use mutt every day, so it's my go-to... Osama, do what they say :) –  linkedlinked Nov 27 '10 at 20:13
    
thanks for all ... i used mail because i didn't install mutt :) –  Mohammad AL-Rawabdeh Nov 28 '10 at 10:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.