LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2012, 12:47 PM   #1
vanish78
LQ Newbie
 
Registered: May 2011
Posts: 13

Rep: Reputation: 9
grep text from remote log file, enter text and rename on remote server


RHEL

Hi,

I hope I can explain my self so that you can understand, here goes :

I want to grep any errors from a remote log file. Pipe it to a tmp file edit it saying that it was checked and rename it, and echo out the errors or GOOD if there was none. My scipt works on a local machine, but not when I use ssh.

Code:
cd /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert_SOA1.log >alert.tmp
cat alert.tmp >>alert_soa1.log.1
echo "Cleared by AUTO DBA on `date`" >alert_soa1.log
grep "ORA-" alert.tmp | sed s/" "/"_"/ | awk '{ print $0 "__" }' | grep ORA
if [ $? = 1 ]; then
  echo GOOD
fi
I have read a few posts but getting errors :

This is my attempt :

Code:
 cat a.sh
ssh server01 cat /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert_SOA1.log >/u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert.tmp
cat /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert.tmp >>/u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert_SOA1.log.1
echo "Cleared by Ultimatum Monitor Agent on `date`" >alert_SOA1.log
grep "ORA-" /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert.tmp | sed s/" "/"_"/ | awk '{ print $0 "__" }' | grep ORA
if [ $? = 1 ]; then
  echo GOOD
fi
done

Code:
. a.sh
-bash: /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert.tmp: No such file or directory
-bash: /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert_SOA1.log.1: No such file or directory
grep: /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert.tmp: No such file or directory
GOOD
-bash: a.sh: line 8: syntax error near unexpected token `done'
-bash: a.sh: line 8: `done'



Please help, still learning
 
Old 07-30-2012, 05:32 PM   #2
Argief
LQ Newbie
 
Registered: Mar 2010
Location: South Africa
Distribution: Undecided
Posts: 28

Rep: Reputation: 0
Ok, few things first. Is a.sh a script? Scripts normally start with an interpreter line, like: #!/bin/sh

You need to set the execution bit with chmod +x filename, then you can execute it as ./filename

'DONE' is only used after 'DO', and implies you are executing some kind of loop structure, but I am unable to see how you could use it?

When you use '>' or '>>' or '|', the next command is executed locally. In your first example you performed all the actions on the remote server. Unless you put the total command in ``, or escape the '>' but that's a different story.

Also your script performs a single command on the remote server and then exits. I'm not sure if you are aware of this, because you refer to directories on the remote server, when the SSH connection has closed already. Obviously you can add ssh server01 before every line to make them all execute on the remote server.

You need to split it up and decide where you want to perform the actions. I think it will probably be easier if you perform the actions locally. Just keep that in mind, so the directory you execute your script should be writable by your user.

Code:
#!/bin/sh
ssh server01 cat /u01/app/oracle/diag/rdbms/soa/SOA1/trace/alert_SOA1.log > /tmp/alert.tmp
cat /tmp/alert.tmp >>/tmp/alert_SOA1.log.1
echo "Cleared by Ultimatum Monitor Agent on `date`" > /tmp/alert_SOA1.log
grep "ORA-" /tmp/alert.tmp | sed s/" "/"_"/ | awk '{ print $0 "__" }' | grep ORA
if [ $? = 1 ]; then
  echo GOOD
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep a text in files and print the file name who don't contain such text whossa Linux - Newbie 5 04-13-2012 07:49 AM
grep contents of file on remote server bluethundr Linux - Newbie 5 09-25-2010 11:09 AM
read the data from the text file which is located in remote machin to oracle databse marthesh Linux - Newbie 1 07-07-2008 07:05 PM
replacing text of a file on remote system bajaj111 Linux - Software 4 11-07-2006 01:43 AM
How do I use Linux POST command to send text to remote server Bill K Linux - General 1 05-19-2006 09:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration