LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-20-2010, 09:56 PM   #1
sociopathichaze
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Rep: Reputation: 0
Bash output with timestamp removing duplicates


I'm writing a bash script to auto run on boot in Tinycore. This is a watered down version.
Code:
#!/bin/bash
touch database
ifconfig | grep 'HWaddr' | sed 's/://g' | awk '{print$5}' > file
hwclock | awk '{print$2" "$3" "$5" "$4}' > stamp
cat database stamp file > temp
awk '!x[$0]++' temp > database
rm temp stamp file
I need it to either not add the time stamp if the awk finds a duplicate or write over the time with the new time if awk finds a duplicate.

BTW this is all pretty much cut-and-paste scripting so please feel free to comment if you know a more elegant way.
 
Old 11-20-2010, 11:37 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,537

Rep: Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907
What is in database? Or is it created via touch each time it is run?

Also, why is the time stamp (better use date function by the way) on its own line above the mac address?
Normally you would see it in the same line.

Also, as the data would appear to only contain this information, why are the colons ( being removed?

My general suggestion would be to change all of your output files to variables.
 
Old 11-21-2010, 01:15 AM   #3
sociopathichaze
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
What is in database? Or is it created via touch each time it is run?

Also, why is the time stamp (better use date function by the way) on its own line above the mac address?
Normally you would see it in the same line.

Also, as the data would appear to only contain this information, why are the colons ( being removed?

My general suggestion would be to change all of your output files to variables.
The database file is just a file stored on the usb drive that can later be imported into another program. This is going to be run on a couple hundred machines, each time adding to the file.

The timestamp is on its own line because if it was on the same line as the info, the awk command wouldn't see it as a duplicate because the time is different.

The colons are removed because the program that the database will be read by only reads macs without colons.

My output files are files and not variables because when they are created and deleted, they are written to the usb which make the light flicker, which is useful because the computers aren't going to have monitors hooked up to them. Kind of a ghetto progress bar.
 
Old 11-21-2010, 05:10 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,537

Rep: Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907
How about something that just checks as you go, like:
Code:
ifconfig | awk '/HWaddr/{stamp=strftime("%d %b %T %Y");mac=gensub(/:/,"","g",$NF)}END{while((getline line < "database") > 0){if(++c % 2){t=line;continue}else{if(mac == line){t=stamp;m=mac}else m=line}print t"\n"m}}' > temp
mv temp database
rm temp
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Removing duplicates with offset (datetime) hattori.hanzo Programming 5 10-20-2010 07:28 PM
Merging files and removing near-duplicates TheBigH Linux - Newbie 3 12-02-2009 04:24 PM
[SOLVED] [bash] sort string and discard duplicates hashbang#! Programming 10 08-21-2009 06:17 AM
BASH out duplicates from multiple text files smudge|lala Linux - General 3 09-24-2008 07:51 PM
LXer: Sorting Perl Lists And Removing Duplicates On Linux Or Unix LXer Syndicated Linux News 0 09-04-2008 05:20 AM


All times are GMT -5. The time now is 09:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration