LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep text from remote log file, enter text and rename on remote server (https://www.linuxquestions.org/questions/linux-newbie-8/grep-text-from-remote-log-file-enter-text-and-rename-on-remote-server-4175419398/)

vanish78 07-30-2012 12:47 PM

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:)

Argief 07-30-2012 05:32 PM

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



All times are GMT -5. The time now is 06:38 PM.