Question on SCP and Mail command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question on SCP and Mail command
# 1  
Old 01-18-2008
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 ?

Last edited by chris1234; 02-24-2009 at 12:57 AM..
# 2  
Old 01-18-2008
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' { } \;
# 3  
Old 01-18-2008
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-10-2008 at 02:15 AM..
# 4  
Old 01-18-2008
you are sending success message on error...think it is wrong

Quote:
Originally Posted by chris1234
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
# 5  
Old 01-18-2008
I got it. thanks rakesh for your help
# 6  
Old 01-18-2008
Thanks i read the book Unix Programming and was able to figure it out

Last edited by chris1234; 02-24-2009 at 12:58 AM..
# 7  
Old 01-18-2008
Yes, I was thinking the same /similar thing......something like:

status=$?
if [status != 0]
then print "$(date) File copy to blah failed" > logfile.log
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Unable to send mail with 'mail' command

I am unable to cause the 'mail' command to send mail from my linux ubuntu 15.10 computer. File 'mail.log' typically reports Connection timed out. I issue the command: mail -s "my subject" recipient@domain.com < filenamewhere filename is a file containing my message. Specifically, the... (3 Replies)
Discussion started by: tcnm
3 Replies

2. Linux

A simple question about mail command

Simple question: i read mail n°4,how to return to list of messages? (2 Replies)
Discussion started by: Linusolaradm1
2 Replies

3. Homework & Coursework Questions

Creating a function that sends a mail using mail command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The function will be called m and it will allow you to send an email to someone using the mail command. The... (1 Reply)
Discussion started by: Drucian
1 Replies

4. Shell Programming and Scripting

Not able to send the mail using mail and mailx command

Hi All, I am trying to send a mail from linux server but could'nt able to send the mail. I tried the below syntax's so far but no luck. mail -s “Hello world” abc@xyz.com < /usr/g/txt.log cat "txt.log" | mailx -s "Hello world" abc@xyz.com mailx -s “Hello world” abc@xyz.com <... (2 Replies)
Discussion started by: scriptscript
2 Replies

5. Solaris

identify the mail server for mail command

Hi , I am new to unix , i am using the mail and mailx command to send the mail .How come i will know the my mail command using which server as mail box.. Please help me .. Thanks in advance (1 Reply)
Discussion started by: julirani
1 Replies

6. Shell Programming and Scripting

Help with SCP command

Hi, I have around 100 files which are aroun 10 MB in size and need to SCP all those files to another machine. Could you please suggest which way is efficient to do? 1. Gzip each file and transfer one by one. 2. Tar all the files together and then gzip it and send one HUGE file. Basicaly... (3 Replies)
Discussion started by: robinbannis
3 Replies

7. Solaris

SSH/SCP Question

Thanks to this forum, I was able to get a program running that uses SSH to control programs running on other hosts. Now I'd like to enhance it. The control program on the target hosts occassionally needs to be updated. Updating the menu program on the source host is easy as it is on one host. ... (1 Reply)
Discussion started by: PabloCruise77
1 Replies

8. Shell Programming and Scripting

scp shell scripting question

HI all, I am attempting to use the scp statemet in a shell script that I am writing I need to have the user of the script enter a password at the time of the shell script running.I have the following questions? 1) how do i disable the automatic text echo when the user is entering the... (1 Reply)
Discussion started by: Segwar
1 Replies

9. UNIX for Dummies Questions & Answers

Simple Windows-to-Unix SCP question

Hi, I am fairly new to Unix. My school computers have only UNIX installed on them, and I wish to use them to do some parallel computing. To do so, I need to transfer the files from my Windows computer to my Unix account on a different computer. I am using the SSH login with the Putty client.... (2 Replies)
Discussion started by: Duchesne
2 Replies

10. UNIX for Dummies Questions & Answers

cipher scp question

Hi, At the moment there are two ciphers available on our unix box (aix 5.1)...aes256 and 3des. Can somebody tell how can use a different cipher (aes128 one that use less cpu and is faster). How do i install this. How can i see wich ciphers are available. In the config file of ssh2 the folowwing... (0 Replies)
Discussion started by: lennyxx
0 Replies
Login or Register to Ask a Question