cat, grep and tee to a local file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cat, grep and tee to a local file
# 1  
Old 09-04-2008
Data cat, grep and tee to a local file

Hi,
This is what I am trying to do.
1) connect to 3 remote servers from my local machine
serverA serverB serverC
2) read error file from each server
cat /var/lib/mysql/mydb.err
3) grep for lines displaying "yesterday" date
grep "`date +%y%m%d' '-d\"1 day ago\"`"
4) Append those lines to a local file
5) Mail this file everyday using cron

Thanks.
# 2  
Old 09-04-2008
Code:
yesterday=`date -d "1 day ago" +%y%m%d`
for server in serverA serverB serverC; do
  ssh $server grep "$yesterday" /var/lib/mysql/mydb.err
done | mailx -s "mydb.err for $yesterday" me@example.com

cat of single files, and temporary files, should be avoided.

Running this from cron left as a minor exercise.
# 3  
Old 09-04-2008
Thanks. It's almost working.
1) It asks for password. I want to embed password in the script.
2) The error file name is different on all three servers.
# 4  
Old 09-04-2008
Code:
while read server errorfile; do
  ssh $server grep "$yesterday" "$errorfile"
done <<HERE | mailx -s "fnord" me@example.com
serverA /var/lib/mysql/mydb.err
serverB /var/log/mydb.err
serverC /opt/mysql/log/mydb.err
HERE

See elsewhere in these forums and Google for how to set up passwordless SSH public keys.
# 5  
Old 09-15-2008
great! Thanks all.
But...
080915 10:02:20 [ERROR] /usr/sbin/mysqld: Table './db/tbl_tb' is marked as crashed and should be repaired
080915 10:02:45 [ERROR] /usr/sbin/mysqld: Table './db/tbl_tb' is marked as crashed and should be repaired

Since the error is repeated on the next line, I want only alert.
# 6  
Old 09-15-2008
I am getting report ONLY from serverA and data from serverB, serverC is not being sent.
# 7  
Old 09-15-2008
Do the log files actually contain matches for the expression you grep for?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh cat file output into a file on local computer

Hello, I'm on a remote computer by SSH. How can I get the output of "cat file" into a file on the local computer? I cannot use scp, because it's blocked. something like: ssh root@remote_maschine "cat /file" > /locale_machine/file :rolleyes: (2 Replies)
Discussion started by: borsti007
2 Replies

2. UNIX for Dummies Questions & Answers

Grep or cat The Whole Directory PROBLEMS :(

Hi Guys This is my first post so I am not sure how things go here. I'm sorry if I'm breaking the rule or something. Feel free to correct me about that :) So as I was saying... I'd been trying to grep this folder containing 900,000 txt files but seems no luck. I get either "No such file... (6 Replies)
Discussion started by: Nexeu
6 Replies

3. Shell Programming and Scripting

Replace cat and grep with <

Hello someone told me to use OS=`awk '{print int($3)}' < /etc/redhat-release` instead of OS=cat /etc/redhat-release | `awk '{print int($3)}'` any idea for the reason ? (5 Replies)
Discussion started by: nimafire
5 Replies

4. UNIX for Dummies Questions & Answers

Grep and cat combined

Hello, i need to search one word (snp1) from many files and copy the content of the columns of this word in new file. example: file 1: SNP BP CHR P snp1 1 3 0.01 snp2 2 2 0.05 . . file 2: SNP BP CHR P snp1 1 3 0.06 snp2 2 2 0.3 output... (6 Replies)
Discussion started by: biopsy
6 Replies

5. Shell Programming and Scripting

Directing cat or grep command in variable

Hi, I still have the problem with directing information from cat or grep to a variable. For instance: XMSG "$(date +%Y_%m_%d)_error_report.txt" "$(cat "$(date +%Y_%m_%d)_error_report.txt")" &Works! The text received by cat is directed to my function. If it is written like this, my... (2 Replies)
Discussion started by: haukee
2 Replies

6. Shell Programming and Scripting

grep or cat using sed

Is there a way using grep or cat a file to create a new file based on whether the first 9 positions of each record is less than 399999999? This is a fixed file format. (3 Replies)
Discussion started by: ski
3 Replies

7. Shell Programming and Scripting

cat -n and grep

I am not sure if using cat -n is the most efficient way to split a file into multiple files, one file per line in the source file. I thought using cat -n would make it easy to process the file because it produces an output that numbers each line that I could then grep for with the regex "^ *$i".... (3 Replies)
Discussion started by: kapu
3 Replies

8. Shell Programming and Scripting

cat /etc/passwd and grep -v on /etc/shells

Hi All, I'd like to do this cat /etc/passwd and grep -v on the /etc/shells list I'd like to find all shell that doesn't exist on the /etc/passwd. Is there an easy way without doing a egrep -v "/bin/sh|/bin/bash................"? How do I use a file /etc/shells as my list for... (4 Replies)
Discussion started by: itik
4 Replies

9. UNIX for Advanced & Expert Users

cat and grep not working

I am trying to cat a file and then grep that file for a number. I can do it fine on other files but this particular file will not do anything. I tried running it on an older file from the same device but it is just not working. The file is nothing more than a flat file on a unix box. Here is just a... (3 Replies)
Discussion started by: jphess
3 Replies

10. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies
Login or Register to Ask a Question