The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: Apr 2006
Posts: 73
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: May 2007
Posts: 59
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' { } \;
Reply With Quote
  #3 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: Apr 2006
Posts: 73
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.
Reply With Quote
  #4 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: May 2007
Posts: 59
you are sending success message on error...think it is wrong

Quote:
Originally Posted by chris1234 View Post
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" "suleman.zia@autozone.com" <<-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
you are sending success message on error...think it is wrong

if [ $? -ge 0 ]; then

means if there is an error
Reply With Quote
  #5 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: Apr 2006
Posts: 73
I got it. thanks rakesh for your help
Reply With Quote
  #6 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: Apr 2006
Posts: 73
Nope still doing the same thing. My last if statement always executes even if there is an error also. But i need my last if statement to work only if both scp are successful..
Reply With Quote
  #7 (permalink)  
Old 01-18-2008
Registered User
 

Join Date: Sep 2006
Posts: 1
Yes, I was thinking the same /similar thing......something like:

status=$?
if [status != 0]
then print "$(date) File copy to blah failed" > logfile.log
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0