searching a log file and appending to a .txt file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting searching a log file and appending to a .txt file
# 1  
Old 07-06-2009
searching a log file and appending to a .txt file

I'm new to shell scripting and am writing a script to help me log the free memory and hd space on a server. As of now, the script just runs 'df -h' and appends the output to a file and then runs 'top' and appends the output to a log file.

What I want to do, is have the script also search the log file for the specific values I'm tracking, and append them to another file for me.

As of now this is all I really have...

df -h > log
top >> log

Any help is apprecaited. Thanks!

p.s. I'm using Solaris 10
# 2  
Old 07-06-2009
Do a man for "grep".

It would be something like this:

grep "Value1" log > second.log
grep "Value2" log >> second.log

Put the values into a file named values.txt

cat /dev/null > second.log
for i in `cat values.txt`
grep $i >> second.log

Let me know if it works for you.
# 3  
Old 07-06-2009
yes, this I've been able to figure out. Though, I don't quite understand the need to use cat in your moderate example.

After googling for a while, I figured I could pull out just the string using grep -o pattern filename, but it doesn't work for me. Next I tried to just pull out the substring I need using the below, but that isn't working for me either...

freeMem=`grep ",.*free mem," testlog.txt`
echo ${freeMem:22:2} ## get an error that says bad substitution.
# 4  
Old 07-07-2009
Which "cat"?

The first one clears out second.log
The second one puts the contents of values.txt into array $i to loop through.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to attach a .txt file or .log file to mail and mailx command

Hi, I am trying to attach a .log file or .txt file to mail command to send an email once my ksh script executed. I am unable to use mutt command as it has been not installed and i am not supposed to install it. I have tried many ways by googling which has not helped me to succeed. Here is my... (5 Replies)
Discussion started by: Samah
5 Replies

2. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

3. Shell Programming and Scripting

To log binary file output to a txt file

Hi, I wrote a small script whose function is to execute the postemsg provided if the threshold breaches. I want to log this postemsg messages to a log file. But I am not able to do. Can someone throw some light on how to log the output of this. I am pasting a snippet of that code. ... (2 Replies)
Discussion started by: dbashyam
2 Replies

4. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

5. Shell Programming and Scripting

Searching for a string in a log file with little movement

I have a script which tails a log file and if it finds certain strings in the data tailed it sends an email, basically like this: tail -f logfile > tmp.file & sleep 10 kill $! STRING=$(grep -c "string" tmp.file) && echo $STRING | mailx -s "Warning.." When the string is... (10 Replies)
Discussion started by: Moxy
10 Replies

6. Shell Programming and Scripting

How to convert a .log file into .txt file under unix??

Hi Friends, I have a .log file generated from a tool(Windows PC) which can be opened using a notepad, but when I tried to view the file in unix (cygwin on my laptop) the file type is showing as binary file, So I am unable to process the file. I need to extract some of the selected text... (3 Replies)
Discussion started by: ks_reddy
3 Replies

7. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" it works... (2 Replies)
Discussion started by: ash22
2 Replies

8. Shell Programming and Scripting

Date Not appending in log file

Hi experts . . . Sunsolaris 9 version I have the script as below: Am getting log file as : archive_today_.log Please suggest. ################################################## set 'date' dd=$3 mon=$2 export mon yyyy=$6 export yyyy cd /oracle/P47/saparch (4 Replies)
Discussion started by: vrjalli
4 Replies

9. Linux

Searching for gaps in huge (2.2G) log file?

I've got a 2.2 Gig syslog file from our Cisco firewall appliance. The problem is that we've been seeing gaps in the syslog for anywhere from 10 minutes to 2 hours. Currently I've just been using 'less' and paging through the file to see if I can find any noticeable gaps. Obviously this isn't the... (3 Replies)
Discussion started by: deckard
3 Replies

10. Shell Programming and Scripting

help searching log file with dates

Im tyring to create a script that will show me any lines in a file with todays date and yesterdays, the date format in the file is as follows ----- amqxfdcx.c : 728 -------------------------------------------------------- 07/12/05 09:53:20 AMQ6109: An internal WebSphere MQ error has... (3 Replies)
Discussion started by: csaunders
3 Replies
Login or Register to Ask a Question

Featured Tech Videos