Visit Our UNIX and Linux User Community


Log and Mail problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Log and Mail problem
# 1  
Old 03-03-2008
Log and Mail problem

Hey Guys,

I am trying to do a recursive search in one directory. If the directory contains that specific folder then create a directory in my other remote machine and use SCP to transfer all the contents of the file.

Till this stage everything works fine. So now i need to add 2 more functionality.

1) If scp fails then mail it to appropriate person and store it in a log file.
2) If scp pass then store a message in the log file stating that SCP has been successful.

For some reason everytime i run my script it gives me an error.

Code:
./file_transfer1.sh[38]: 0403-057 Syntax error at line 45 : `<' is not matched.

And here is my code:

Code:
 LOCAL_LOG_FILE="priceops_`date +%m%d%Y`.log"

     cd /home/abc/nissan
     for dir in *; do
     if [ -d ${dir}/priceops ]; then
     /usr/local/bin/ssh -l ferrari xyz "mkdir -p  /az/web/test/$dir"
     scp -r ${dir}/priceops ferrari:/az/web/test/${dir}/
      echo "File Transferred failed from SUPRA to FERRARI `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE 2>&1
     fi
    done

    if [ $? != 0 ]; then

    echo "Error occured"
    mailx -s "File Transfer Failed" "abc@xyz.com" <<-EOT
    scp failed from SUPRA to FERRARI
   `date`
    EOT
    echo "File Transferred failed from SUPRA to FERRARI `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE 2>&1

The script is not even creating a log file also.
Thank you.,

Last edited by chris1234; 03-03-2008 at 11:15 AM..
# 2  
Old 03-05-2008
You need to post all your code. Error should be on line 45 (possibly) but there is only 19 lines of code posted.

A quick glance - I believe this is an error
mailx -s "File Transfer Failed" "abc@xyz.com" <<-EOT
Should be << EOT
# 3  
Old 03-06-2008
thanks for the reply. yes that is where the error presist. But unfortunately your solution did not work either.

I have worked with mail before also but for some reason it is not working for me now.

mailx -s "File Transfer Failed" "abc@xyz.com" <<-EOT

this is where the errors is it says < is not matched. I tried << EOT or <<EOT did not work. I appreciate if anyone can tell me whats going on.

Thanks
# 4  
Old 03-06-2008
Chris,

try this..
mailx -s \ "subject" \ abc@xyz.com

Thanks
# 5  
Old 03-06-2008
Thanks praveenvi. I do not get the error now. I have to test it to see if that mail functionality works or not. But its very wiered that this same mail function i used for my other program and never had a problem but when i used in this script it give me error.

One more question so right now my if statement looks like this :-

Code:
 if [ $? != 0 ]; then
    echo "Error occured"
     mailx -s \ "File Transfer Failed" \ "abc@xyz.com"
    scp failed from SUPRA to FERRARI
   `date`
    echo "File Transferred failed from SUPRA to FERRARI `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE 2>&1

My question is that is :-

scp failed from SUPRA to FERRARI
`date`

will be added in the description of the mail or not?

Thanks
# 6  
Old 03-06-2008
Sorry but this command does not work properly.

Code:
mailx -s \ "File Transfer Failed" \ "abc@xyz.com"

Now everytime i run this code:-

Code:
LOCAL_LOG_FILE="priceops_`date +%m%d%Y`.log"

     cd /home/abc/nissan
     for dir in *; do
     if [ -d ${dir}/priceops ]; then
     /usr/local/bin/ssh -l ferrari xyz "mkdir -p  /az/web/test/$dir"
     scp -r ${dir}/priceops ferrari:/az/web/test/${dir}/
      echo "File Transferred failed from SUPRA to FERRARI `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE 2>&1
     fi
    done

    if [ $? != 0 ]; then

    echo "Error occured"
     echo "File Transferred failed from SUPRA to FERRARI `date +%n%m/%d/%Y%n%H:%M:%S`" >>$LOCAL_LOG_FILE 2>&1

    mailx -s \ "File Transfer Failed" \ "abc@xyz.com"
fi

exit 0

I dont get any error messages but when i run my script and the scp fails then my script just hangs at this statement.

echo "Error occured"

After that nothing happens. I had to press Ctrl + Z in order to quit. Anyone can tell me what is going on.

Thanks
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #102
Difficulty: Easy
Unix, Linux and other Unix-like operating systems are a family of computer operating systems that are derived from DOS.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Log search and mail it if the log is updated before 24 hours from the current time

Hi , We have around 22 logs , each has different entries. I have to automate this using shell script. The ideas which am sharing is given below 1) We use only TAIL -100 <location and name of the log> Command to check the logs. 2) We want to check whether the log was updated before 24... (13 Replies)
Discussion started by: Kalaihari
13 Replies

2. UNIX for Dummies Questions & Answers

Mail Problem

Hi All, I am having a problem that is very similar to the one being discussed here. I am using OS X and am trying to send mail from the OS X Terminal to my GMail account. The mail seems to go through, but gets stuck at Google's servers. I have a log file from the /var/mail directory that... (0 Replies)
Discussion started by: danielsutton
0 Replies

3. UNIX for Advanced & Expert Users

HP UX mail problem

I am uxing HP UX mailx, I want to send mail with: 1) to list 2) cc list 3) sender address 4) mail body 5) subject 6) attachment I am using : (cat cc_list; cat mail_body; ux2dos file_1 | uuencode attachment.txt)|mailx -m -s "subject" -r sender@abc.com recepient@abc.com cc_list... (2 Replies)
Discussion started by: gautamadak
2 Replies

4. Red Hat

Mail Problem. Maybe, it is a DNS Problem!

Hi, i've a redhat linux 9 upadated by redhat from 7 version to 9 version. A couple of days ago i was a problem with my mail, in other words i'm not able to get any email nor to send any email. I've a proxy configuration and i tried to set iptables in order to verify the port. The 110,255 and 995... (1 Reply)
Discussion started by: pintalgi
1 Replies

5. UNIX for Dummies Questions & Answers

Problem with mail.

Hello! I have two servers with Solaris 2.7 I send mail from first to second. The first is also dns. It's known as "ns.oldb.pkb", second is "dev.pkb". Ping works successful from 1 to 2 and vice verse. But when I am trying on first server : sendmail -v user@dev.pkb < /etc/motd it is... (3 Replies)
Discussion started by: Colf
3 Replies

6. UNIX for Dummies Questions & Answers

Problem with mail

Hello! I have to servers with Solaris 2.7. I mail from first to second ( mailx user@dev < letter ). But mail not arrive to second. It return by daemon with explanation: .... --- Transcript of session follows --- 550 5.1.2 user@dev... Host unknown (Name server: mailhost.serv.dom: host not... (2 Replies)
Discussion started by: Colf
2 Replies

7. UNIX for Dummies Questions & Answers

mail problem (NOT Mail or Mail.app)

When I try to use the CLI mail, I get the following error. What's wrong? Welcome to Darwin! % mail root Subject: test test . EOT % /etc/mail/sendmail.cf: line 81: fileclass: cannot open /etc/mail/local-host-names: Group writable directory Do I just need to change the... (1 Reply)
Discussion started by: chenly
1 Replies

8. UNIX for Advanced & Expert Users

mail problem !!

Hi, Below a try to send an email to a local user can be seen. I can NOT send e-mail anywhere, but I receive email perfectly. <pre> isgsi01(root)10: mail aris < /home/aris/mail2send dbm map "Alias0": unsafe map file /etc/mail/aliases: No such file or directory </pre> ..... but the... (3 Replies)
Discussion started by: guest100
3 Replies

9. UNIX for Dummies Questions & Answers

E-mail problem

Is it true that you need port 110(POP3) to be open for sending email out ?? I can send email out fine but when I check my port 110 is not open. The problem I have is that I can not receive email at all or can not send email locally (between my users). Here is what I get using the netstat... (6 Replies)
Discussion started by: guest100
6 Replies

10. UNIX for Dummies Questions & Answers

Problem with mail

what I have to write in a shell that every time that it arrives a new e-mail has to perform a program taking some data from the e-mail. (2 Replies)
Discussion started by: mmistero
2 Replies

Featured Tech Videos