Sponsored Content
Top Forums Shell Programming and Scripting How to read a dynamically changing file Post 302623797 by kashif.live on Saturday 14th of April 2012 04:23:20 PM
Old 04-14-2012
How to read a dynamically changing file

I want to read a constantly changing file and do some operation on text found in that file.
Actually that is log file of linux system and whenever i find a matching string in that file i want to create a text file with timestamp. is it possible to read that file?

here is sample output of log file
Code:
Apr 14 16:03:38 localhost kernel: usb 1-2.1: new high speed USB device using uhci_hcd and address 9
Apr 14 16:03:38 localhost kernel: usb 1-2.1: New USB device found, idVendor=12d1, idProduct=1037
Apr 14 16:03:38 localhost kernel: usb 1-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Apr 14 16:03:38 localhost kernel: usb 1-2.1: Product: Ideos
Apr 14 16:03:38 localhost kernel: usb 1-2.1: Manufacturer: Huawei Incorporated

Apr 14 16:02:21 localhost kernel: usb 1-1: new full speed USB device using uhci_hcd and address 8
Apr 14 16:02:21 localhost kernel: usb 1-1: New USB device found, idVendor=0951, idProduct=1643
Apr 14 16:02:21 localhost kernel: usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Apr 14 16:02:21 localhost kernel: usb 1-1: Product: DataTraveler G3
Apr 14 16:02:21 localhost kernel: usb 1-1: Manufacturer: Kingston

I want to create a file whenever "New USB device found" text is found in this file. create a file with timestamp in \usr\temp folder.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read a dynamically changing file and load into Oracle?

I have a tab delimited file which has 27 character fields. The file needs to be loaded into an Oracle table. But the challenge is that everytime the file comes it may or may not have values in all 27 fields. Column Definition of the 27 fields: TYPE: Char (1) NAME: Char (30) CUSTOM_VAL: Char... (8 Replies)
Discussion started by: madhunk
8 Replies

2. UNIX for Dummies Questions & Answers

How can i read array elements dynamically in bash?

Hi friends how can we read array elements dynamically in bash shell? (1 Reply)
Discussion started by: haisubbu
1 Replies

3. Programming

read() without changing atime ?

Hey, First of all I want to know How do I see the atime of a file ?? Whats the command ?? I think ls -l shows the last modified time right ? Because when I use cat to read a file, the timestamp shown by ls -l does not change. Its not ls -lu ! man ls did not help ! How do I see the last... (8 Replies)
Discussion started by: tantric
8 Replies

4. Shell Programming and Scripting

Problem with changing directory and subdirectories to read only

I have a directory with its subdirectories and files. I want to change them all to read only. Say it is ~/test chmod -R 444 ~/test chmod: `/home/myname/test': permission denied I do not understand. Do I have to have executable mode for a diirectory to access. How can I change ~/test to... (5 Replies)
Discussion started by: lalelle
5 Replies

5. Linux

Changing eth3 to read eth0

Hello everyone I recently clone a system and doing so it gave my nics cards id's of eth3 and eth4 instead of eth0 and eth1. Is there a config file or something out there where I can change these back? All help will be appreciated. (2 Replies)
Discussion started by: aojmoj
2 Replies

6. Shell Programming and Scripting

Replace characters then read the file without changing it

Hi All At the moment the following code works but ideally i do not want to have to change the original $1 tr "\r" "\n" < "$1" > "$1.fix" printf "\n" >> "$1.fix" mv "$1.fix" "$1" FILE=$1 coffee_out="splitmovie" coffee_fill="-splitAt" coffee_end="-self-contained -o output.mov $2"... (1 Reply)
Discussion started by: babajuma
1 Replies

7. UNIX for Dummies Questions & Answers

Read a file dynamically

Hi my requriment is read the file name dynamically my code is #!/bin/sh file="/c/work/loan/" Header_Trailer_move() { sed '1d;$d' $file| cat >sam.txt } Header_Trailer_move in above given path my list of files or there i have to read file dyanamically when i entered particular file name... (2 Replies)
Discussion started by: sgoud
2 Replies

8. Programming

Changing the way arguments are read from program

I have the following piece of code. Currently the command line arguments are passed as shown below using the "= "sign. I capture the name of the argument, for example vmod and it's corresponding user parameter which is jcdint-z30.cmd. ./raytrac vmod=jcdint-z30.cmd srFile=jcdint.sr Now I want... (12 Replies)
Discussion started by: kristinu
12 Replies

9. Shell Programming and Scripting

Dynamically changing environment variable

Linux Redhat, BASH Shell. I want to put this in my .bash_profile I have log files that go to directory paths based in part on other variables such as went DB Name is set in memory. So if the DB Name changes the path to the log file changes. How do I create an environment variable I put into... (6 Replies)
Discussion started by: guessingo
6 Replies
All times are GMT -4. The time now is 11:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy