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 Code:
[root@liang tmp]# sh last.sh any help thx |
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. |
hi ,
thanks alot! next, i need to grep time from 7am-7pm, of everyday how can i grep the specific time range ? |
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? |
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! |
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 :) |
All times are GMT -5. The time now is 02:31 PM. |