Making wtmp files readable one at a time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making wtmp files readable one at a time
# 1  
Old 02-17-2012
Making wtmp files readable one at a time

New Unix user/scripter here. Been trying to solve a problem for two days now with no luck. Hoping someone here has an answer.

Essentially I have a list of wtmp files which I have decompressed and copied to a temporary directory. Using the following command I can turn them into a file than can normally be read with the cat command:

last -f wtmpfile > wtmpfilecopy

The problem is that I need to do this to all the files while retaining the beginning of the original file name. So it doesn't matter if anything is added to the end of the file name as long at the original file name is the beginning of the copies name. This will be going into a script. I've been experimenting with for loops as I found some information that looked promising but still have not found success.

I hope this is enough information and I hope someone out there knows a solution.

Thanks in advance!
# 2  
Old 02-17-2012
What Operating System and version you you have and what Shell do you use?

What are you trying to achieve? What final output are you looking for?

What are the names of the various wtmp files? Are they all in the same directory (including the active wtmp file itself)?
Have you been able to preserve the timestamp on each wtmp file?

There is rarely ever a need to expand a whole wtmp file into text.


Ps. I regularly run a script to find the last time a named user logged in. This script looks at a long history of wtmp files in reverse chronological order.

Last edited by methyl; 02-17-2012 at 12:16 PM.. Reason: typo
# 3  
Old 02-17-2012
Quote:
Originally Posted by methyl
What Operating System and version you you have and what Shell do you use?

What are you trying to achieve? What final output are you looking for?

What are the names of the various wtmp files? Are they all in the same directory (including the active wtmp file itself)?
Have you been able to preserve the timestamp on each wtmp file?

There is rarely ever a need to expand a whole wtmp file into text.


Ps. I regularly run a script to find the last time a named user logged in. This script looks at a long history of wtmp files in reverse chronological order.
I'm using OpenSuse (school computer) and using BASH. What I'm trying to achieve is that I am eventually going to have to grep each of the files looking for a particular string. The string will only be matched in one of the files. The names of the wtmp files are wtmp-######### where #s are a timestamp and I need to preserve that time stamp once I turn the files into readable ones. Thus far, yes I have been able to preserve the timestamp. It comes down to being able to grep each of the wtmp files individually for a specific string to find the file so I know which file contains the record I'm looking for.
# 4  
Old 02-17-2012
Wrench

I guess you mean something like this:


Code:
cd /directory
ls -1t wtmp-* 2>/dev/null | while read filename
do
        last -f "${filename}" > "${filename}".txt
        grep -l "string" "${filename}".txt | while read found
        do
                 echo "found ${string} in ${filename}"
                 grep "${string}" "${filename}"
        done
done

# 5  
Old 02-17-2012
Quote:
Originally Posted by methyl
I guess you mean something like this:


Code:
cd /directory
ls -1t wtmp-* 2>/dev/null | while read filename
do
        last -f "${filename}" > "${filename}".txt
        grep -l "string" "${filename}".txt | while read found
        do
                 echo "found ${string} in ${filename}"
                 grep "${string}" "${filename}"
        done
done

Thank you kindly for the try but it didn't work. There's no way to simply change the wtmp files into readable files? If I can get them readable I can move on from that point. I just need to have them cat-able basically. If not, I'm thinking I may simply have to try another approach to this problem. Again thank you very much for the feedback.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

When comparing binary files, show human readable result?

Hello. I am comparing two binary file. The first file is the source file. The second file is a modified version of the first one. Modification concern uuid value. Example first file have multiple occurrences of 69a3604b-ac2b-43b7-af84-0a4a67fc6962 second file have the same occurence... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Convert Numeric Time to Readable Timestamp - Perl

I am trying to hit an URL using below command and get the data into an excel sheet. wget --user=<<USERID>> --pass=<<PASSWROD>> http://www.files.thatbelongstome.com/file1 -O test1.xls Next step is to consolidate files from 1 to 10 in a single excel sheet and send to my mail. I am working on... (1 Reply)
Discussion started by: PikK45
1 Replies

3. Shell Programming and Scripting

Script to truncate wtmp files

Hi, Does anyone have a script to truncate the wtmp file. I want to move older entries in the wtmp to a new file and move it out of var/adm and shrink the size. (4 Replies)
Discussion started by: ElizabethPJ
4 Replies

4. Shell Programming and Scripting

Converting a random epoch time into a readable format

I am trying to create a script that will take epoch (input from command line) and convert it into a readable format in bash/shell ---------- Post updated at 08:03 PM ---------- Previous update was at 07:59 PM ---------- #!bin/bash read -p "Please enter a number to represent epoch time:"... (9 Replies)
Discussion started by: sprocket
9 Replies

5. Shell Programming and Scripting

Convert epoch time stamp into human readable format

Can someone help me to write a shell script to convert epoch timestamp into human readable format 1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714" 1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"... (10 Replies)
Discussion started by: Moon1234
10 Replies

6. Shell Programming and Scripting

Making big find command more human readable

This does not work. One line works but my pattern are about 100 characters long and it is messy to read. When I try to use several lines it does not two' find "$inputDirectory" \( -name 'very long pattern1' -o -name 'very long pattern2' -o -name... (1 Reply)
Discussion started by: Michael Stora
1 Replies

7. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

8. Shell Programming and Scripting

Convert epoch to human readable date & time format

Hello I have log file from solaris system which has date field converted by Java application using System.currentTimeMillis() function, example is 1280943608380 which equivalent to GMT: Wed, 04 Aug 2010 17:40:08 GMT. Now I need a function in shell script which will convert 1280943608380... (3 Replies)
Discussion started by: Yaminib
3 Replies

9. SuSE

Regarding Readable check for all the files in the folder

Currently we are doing the migration to unix to linux. I am facing the new problem kganeshb@its04489:~/scripts $ ls -l | more total 340 -rw-r----- 1 kganeshb users 9038 Oct 22 13:23 109_db.txt -rw-rw---- 1 dlc users 1413 Oct 10 17:40 1.txt -rw-rw---- 1 kganeshb users 45 Jan 28 13:46 a... (2 Replies)
Discussion started by: kingganesh04
2 Replies
Login or Register to Ask a Question