LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-21-2013, 03:21 AM   #1
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

Rep: Reputation: Disabled
scripts file output format gone messy


hi
i want to list last login at 7-19 everyday
i created script file like this (havent done because stuck somewhere)

Code:
#!/bin/bash
date=`date +%b" "%_d`
last=`last | grep "$date"`
echo $last
and the output:
Code:
[root@liang tmp]# sh last.sh
wikiadmi pts/1 192.168.238.1 Wed Feb 6 06:27 still logged in wikiadmi tty3 Wed Feb 6 05:40 still logged in wikiadmi tty2 Wed Feb 6 05:40 still logged in wikiadmi pts/0 :0.0 Wed Feb 6 05:25 still logged in wikiadmi tty1 :0 Wed Feb 6 05:25 still logged in reboot system boot 2.6.32-279.el6.x Wed Feb 6 05:24 - 05:50 (00:26) wikiadmi pts/0 192.168.238.1 Wed Feb 6 01:10 - 01:54 (00:44) reboot system boot 2.6.32-279.el6.x Wed Feb 6 01:08 - 05:50 (04:42)
[root@liang tmp]#
i have successfully grep the current date, but the "last command" output became 1 line, which is unreadable.
any help
thx

Last edited by slowerogue; 02-21-2013 at 03:22 AM.
 
Old 02-21-2013, 03:41 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Try using echo "$last" instead of echo $last

BTW: It isn't wise to use variable names that are the same as the command name, make the vars upper case if you want to use that specific name.
 
Old 02-21-2013, 03:46 AM   #3
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

Original Poster
Rep: Reputation: Disabled
hi ,
thanks alot!
next, i need to grep time from 7am-7pm, of everyday
how can i grep the specific time range ?
 
Old 02-21-2013, 04:02 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
What are you actually trying to accomplish?

Your first post shows you are trying to grep a specific date and your last post talks about grepping a specific time range for every day. Are those two to be combined at a later stage?

Also: What do you mean by grep time from 7am-7pm? Should the time be the starting time or the ending time or both? Someone can log in at 18:59 and log out at 23:59, or log in at 06:59 and log out at 14:04. Should those be included? Or are you looking for people that logged in after 07:00 and logged out before 19:00?

Last edited by druuna; 02-21-2013 at 04:03 AM. Reason: fixed spelling
 
Old 02-21-2013, 10:30 PM   #5
slowerogue
Member
 
Registered: Oct 2012
Posts: 96

Original Poster
Rep: Reputation: Disabled
hi, i am trying to acomplish the last login from 7am-7pm of everyday.
lets say i run the script on crontab 7.01pm everyday, so i will get the output from 12.00am-7pm, but i only want to get 7am-7pm

the first script i have already grep the current date's login, so next i would like to filter the output from only 7-7pm

if the person login before 7am, there is no need to grep it.
it doesnt matter when the user logout since the "last" will show the user is still logged on.

thats what i was told, request by client so i just follow their requirement.

thanks!

Last edited by slowerogue; 02-21-2013 at 10:32 PM.
 
Old 02-21-2013, 10:37 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,342

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
In that case just create script that you can cron to run at eg 19:05 every day and run the last cmd and parse out the current date and the times you want.
You could use eg awk probably, although I'd use Perl.
I'm sure you can even do it in pure bash, but it would be messy.
Here's some links:

Bash
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

Awk
http://www.grymoire.com/Unix/Awk.html

Perl
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials
http://www.tizag.com/perlT/index.php


First choose your weapon, then go to it
 
  


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
How to convert Tcpdump output file to a Pcap format? gabriel01 Linux - Networking 6 11-26-2012 04:50 AM
Exporting output of a file to a non-editable file format HogFather Linux - Enterprise 6 03-09-2012 03:56 AM
Putty using csv files in BASH to format file in script as output smks Linux - Newbie 7 12-22-2011 05:50 PM
i need to output a text file in proper format anurupr Linux - Newbie 2 03-04-2010 03:14 AM
Stranger format to my scripts output shmo982 Programming 3 05-01-2009 02:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration