
japhy
Enthusiast
/ Moderator
Sep 26, 2000, 6:43 AM
Post #2 of 3
(1286 views)
|
The 'last' Unix program returns information about when users logged on, and when they logged off. Here's some sample output: chuck pts/2 adsl-63-194-86-4 Sat May 20 18:47 - 18:53 (00:06) elongftp ftp 216-164-194-69.s Sat May 20 13:47 - 13:47 (00:00) chuck pts/4 adsl-63-194-86-4 Sat May 20 13:30 - 18:47 (05:16) chuck pts/4 adsl-63-194-86-4 Sat May 20 13:26 - 13:30 (00:03) Now, the Perl program gets, as input, the output from the 'last' command. Then, it does the following to each line of input: 1. does the input match /(..:..)...(.*)/ ? 2. if so, is the SHELL variable $1 greater than or equal to the Perl's regex variable $1? 3. if so, is the SHELL variable $1 less than the Perl's regex variable $2? The result of these three conditions is either 1 or 0. If it's 1, then the code simply state: $_ x= 1 (which means $_ = $_ x 1). The 'x' operator is the repetition operator -- 'foo' x 1 is 'foo', and 'foo' x 3 is 'foofoofoo'. If it's 0, then the code is: $_ x= 0 (which is basically like saying $_ = ''). The real trick to it is that this is executed in sh (or some variant thereof). The part of the code that reads "'$1'" is doing the following: the " is a " in the code of Perl to run; the ' is a single quote CLOSING THE SINGLE QUOTE that started the Perl program; $1 is the shell variable $1 (the first argument to the program); ' RESUMES the string being sent to Perl as code; " is a double-quote in the Perl program. I hope you understand this. It's damn wicked (and smart). It finds out who's been logged on DURING a specific time. ------------------ Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher
|