Showing posts with label year. Show all posts
Showing posts with label year. Show all posts

Monday, May 4, 2009

Getting The Year From Wtmpx/Wtmp - Part 2 - The Easy Way

Hey there,

Today's subject matter hearkens back to a post we did in 2007 about looking around inside Solaris' wtmpx. In that post, the ultimate objective was to get the "year" information, since commands like "last" don't include that information in their output and the lack of that year information can make for confusing output if you don't roll your wtmpx file every year.

Once I stumbled over this command (which is one thing that always amazes me, since I've been using Solaris since 2.4 - there's always something new to learn, even if it's old ;) I was extremely pleased. Of course, knowing how to crack open wtmpx and get at anything and everything inside it is probably a more powerful skill to possess, but, if you're a simplest-is-best kind of guy like me, using a command that will allow you to get the last output with the year attached is perfect if you're looking to get your last output with the year attached. Seems almost self-evident ;)

The command you can use is called "fwtmp" and exists in the "/usr/lib/acct" directory on Solaris and in many and varying places depending on your Linux distro (assuming your db is updated, commands like locate or slocate should make it easy to find). The command has actually been around since Solaris 7, but (yes, I did some research on it when I realized I'd never realized it existed before ;) had some issues that made it unacceptable. Those same issues persisted through most of Solaris 8, but were eventually ironed out by the time Solaris 9 came out (which is also like saying "By the time you had your Solaris 8 system patched to the gills," since a fully patched 64-bit installation of Solaris 8 was, basically, Solaris 9). The command still stands in good stead on Solaris 10 and is working well on every Linux distro I've been able to test.

Even better still, the command's application is extremely simple; allowing you to use its output for whatever diabolical purposes you have in mind (I believe it supports altruism as well ;) Many of the wtmp/btmp implementations on Linux already have a way around this by allowing you to specify time frames (with the -t flag) when you invoke last. Most distro's also include this command (and its fellow commands) by default, as well. This old post on getting the year from last on Linux also demonstrates how Linux makes this whole process less convoluted by allowing you to get the same information from the lastlog file.

For a quick example of how easy this command is to use, check out the following command line session. First we create a temporary file using fwtmp and then we read a line from it to verify that it worked correctly (it doesn't get much simpler than that... unless they just start including the year in last's output ;) :

host # /usr/lib/acct/fwtmp < /var/adm/wtmpx > tmp_wtmpx_file
host # head -1 tmp_wtmpx_file
user123 sshd 1258 7 0000 0000 1226072918 230489 0 29 host123.desktop.ourhost.com Fri Nov 7 09:48:38 2008


Simplicity at its finest. There's actually a whole separate binary to fix wtmpx, which basically takes care of cleaning operations you could do yourself.

As a for instance, assuming you had the privileges to do so, and wanted to remove that login listed above from the wtmpx file, you could run that initial command to create the tmp_wtmpx_file, delete that line in it (using vi, emacs, what-have-you) and then convert the text file you got from fwtmp back into a binary wtmpx file, using the same command (The -ic options instruct fwtmp that its input is in ASCII format and needs to be converted to binary):

host # /usr/lib/acct/fwtmp -ic tmp_wtmpx_file > /var/adm/wtmpx


Of course, this is a simplistic look at how to do something like that (and certainly not a recommendation to mess with your security logs). You should probably back up files before overwriting them, etc. Still, it's kind of cool to know you can get all this information from wtmpx without having to learn the Perl pack signature (or know anything about C :)

The programming possibilities are only limited to what you need to do and the information fwtmp can provide!

Cheers!

, Mike




Discover the Free Ebook that shows you how to make 100% commissions on ClickBank!



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Thursday, January 1, 2009

Happy New Year! Unix and Linux Resolutions.

Good morning/afternoon/evening... is it January 2nd already?!?!?!?!

Today's bit of humour might help you shake off the hair-of-the-dog that you (if you're like me) are completely covered in by now. It's oddly amusing that New Year's Day (we're not counting however long you made it past midnight yesterday ;) is generally composed of a confusing and awkward hangover coupled with a nagging half-memory of something really stupid you promised to do this year (probably something beneficial and good-for-you... when will you ever learn ;)

The beauty of the New Year's resolution is that no one ever really expects you to keep it. I can't tell you how many people promised to quit smoking in 2009, at the party I attended last night, proceeded to light up within 5 minutes of midnight and got away with it scot-free. It's not that the information is classified, I just don't remember all that well. One of them may have been me ;) In any event, the life of a New Year's resolution (from my experience) usually plays out like this:

1. An inebriated promise/vow/declaration is made at some time before midnight (local time zone) regarding quitting a really bad habit or, conversely, working to form a really good one.

2. Within the half hour previous to midnight on New Year's Eve, this promise is made again, at least once. Often, the pronouncement is backed up by some form of peacocking and/or strangely primal mammalian behaviour ;)

3. About 5 minutes after midnight, on New Year's Day, the resolution is broken. All is not lost, however, due to an unwritten rule of universal law (Jim Beam's 67th Time-Space Assertion) which actually redefines the strict rules of linear time by allowing for the previous year to continue until the person who invokes the rule either falls asleep or passes out. Many people don't know this (and they'll never teach it in our public schools), but this is the real reason there are 365.25 days in a year, give or take. The concept of the leap year (along with all of its Byzantine provisions), and every calendar ever widely used, was invented as a way to keep from traumatizing our youth and instilling a sense of order in a universe powered by chaos but inhabited by "intelligent" life. I understand that most human beings need order and/or a sense of purpose in order to justify the "sanctity of life" they, out of necessity, hold so dear (except for the life of "pesky critters" and animals that taste good ;), but you must always consider that your God is probably still rolling on the floor laughing about how a simple brain-tweak that allowed you to realize you exist is "still" messing with your thought process, giving you a false sense of security in your species' superiority and causing you to exponentially waste more and more of your life philosophizing. I'm kidding, of course... Your God doesn't have a sense of humor anymore. He's been around a long long long time and he's well beyond bitter at this point ;)

4. The next day, the resolution is broken again, although, this time, after several minutes of nagging self doubt and an occasional burst of enthusiasm or really positive thought that's inevitably trampled under foot.

5. Lather, rinse, repeat ;)

Seriously, I hope you have a great New Year and keep at least one resolution (one of the good ones :) - Worst case, you can exercise your right to be a better person, quit a bad habit, start a good habit, etc, any day of the year. Once the year's freshness seal has been cracked, the year may be old, but any day is just as good a day as any :)

Happy New Year, everyone!

BTW: See this post if you're curious to know how I feel about computer-illiterate people referring to us all as geeks and play a fun little bloody Ninja penguin game to go with that Bloody Mary. Kill your headache and some virtual corporate goons at the same time :)



From GeekOfTheDay.com







Geek New Year's Resolutions






The upcoming new holds much hope and promise, and like everyone else, geeks have their own goals to meet . When it comes down to it, aren't that much different than regular, ordinary people. Right?


Geek New Year's Resolution List


Image1. Promise to install Linux on: Portable DVD player; Timex Ironman watch; Talking Santa; House arrest ankle bracelet


2. Learn to identify all O'Reilly books just by animal on cover


3. Remember Pi to at least 12 more decimal points


4. Finish writing thesis on Silly String theory


5. Establish skin re-pigmentation process using mild solar radiation exposures (ie. get out more)


6. Market own brand of open source Cola with triple-caffeine


7. Start another rally outside Paramount about reviving Star Trek franchises--this time without the massacre of ten thousand baby tribbles


8. Master control of three "World of Warcraft" characters simultaneously


9. Buy every copy of The Butterfly Effect 2 from Blockbuster Video and place in time capsule for me to find when I'm older


10. Appeal restraining orders from Geri Ryan, Jolene Blalock, and, um, Nichelle Nichols






, Mike




Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.