![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New User/Mail setup question. PLEASE help. | Rotting | UNIX for Dummies Questions & Answers | 3 | 09-27-2007 03:19 AM |
| mail question here | lostinfaith | UNIX for Dummies Questions & Answers | 1 | 05-12-2006 11:42 AM |
| question on mail server | piltrafa | UNIX for Dummies Questions & Answers | 1 | 07-26-2005 12:12 PM |
| Mail question? | yxiao | UNIX for Dummies Questions & Answers | 2 | 10-15-2002 07:53 AM |
| MAIL question for HP-Unix O/S | dsthompson | How do I send email? | 3 | 03-26-2002 06:55 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Question on SCP and Mail command
Hey Guys,
I created a script where i am trying to do scp from one machine to another and then from another to another remote machine. I am having a log file also with the current date and time stamp in which i have been successful. I would like to delete the log files older than 30 days in which i have been successful also. My only problem is that how can i write an if statement if any one of the scp fails? Meaning if my first scp fails then store a message in a log file that scp failed and send an email to appropriate person. same thing goes for second scp also. Anyone can help me out ? Code:
EXIT_STATUS="?"
LOCAL_LOG_FILE="category_`date +%m%d%Y`.log"
date +"%m/%d/%Y %H:%M:%S" >$LOCAL_LOG_FILE
scp -p /az/web/ezap.abc.com/docs/*.gif saloo:/az/web/vendornet.abc.com/docs/tester/bkup>$LOCAL_LOG_FILE 2>&1
scp -p recon:/az/web/vendornet.abc.com/docs/tester/mike/priceops/*.txt audi:/az/web/ezap.abc.com/docs
# if['$EXIT_STATUS != 0']
echo "File copied Successfully `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE
find /home/test/bin -name 'category_[0-9][0-9]*.log' -atime +30 -exec 'rm' { } \;
Last edited by chris1234; 01-18-2008 at 07:50 AM. |
| Forum Sponsor | ||
|
|
|
|||
|
try this -- but not tested
EXIT_STATUS="?"
LOCAL_LOG_FILE="category_`date +%m%d%Y`.log" date +"%m/%d/%Y %H:%M:%S" >$LOCAL_LOG_FILE scp -p /az/web/ezap.abc.com/docs/*.gif saloo:/az/web/vendornet.abc.com/docs/tester/bkup>$LOCAL_LOG_FILE 2>&1 if [ $? != 0 ]; then echo "error occurred" mailx -s "Subject" "abc@abc.com" <<-EOT scp failed `date` EOT fi scp -p recon:/az/web/vendornet.abc.com/docs/tester/mike/priceops/*.txt audi:/az/web/ezap.abc.com/docs if [ $? != 0 ]; then echo "error occurred" mailx -s "Subject" "abc@abc.com" <<-EOT scp failed `date` EOT fi echo "File copied Successfully `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE find /home/test/bin -name 'category_[0-9][0-9]*.log' -atime +30 -exec 'rm' { } \; |
|
|||
|
Thanks dude
Thanks dude. Well even if there is an error in any one of the SCP my log file is still generated. So i thought to add an if statement if the test pass then only log it .
Code:
if [ $? >= 0]; then echo "File Transfer Successful" mailx -s "Scp Passed Successful" <<-EOT All the files havve been transfered successfully `date EOT echo "File copied Successfully `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE fi Last edited by chris1234; 05-09-2008 at 10:15 PM. |
|
|||
|
you are sending success message on error...think it is wrong
Quote:
if [ $? -ge 0 ]; then means if there is an error |