- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help with script break down ..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:21 AM
03-06-2002 11:21 AM
help with script break down ..
#### I have
last | grep -v ftp |grep -v wtmp |awk ' /still logged/ { print $1 ".*still logged in"; next } { print $1 }' |sort -u | while read name
do
last | grep -v ftp | grep -v wtmp | grep -c "^$name" | read count
echo "$name \t$count"
done
# that gives me this out put ..
5
aford.*still logged in 1
rbiersch.*still logged in 1
rleon 2
rleon.*still logged in 1
# the only part I dont understand is where is the 5 comming from? And where is that outputting from without an echo?
I changed the first line to
last | grep -v ftp |grep -v wtmp | grep [A-z]|
And when I ran it the 5 went away. Why did the 5 go away when I added the grep [A-z]?
Thanks,
Richard -
"Give a man a fish feed him for a day,teach a man to fish feed him for a lifetime"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:23 AM
03-06-2002 11:23 AM
Re: help with script break down ..
last | grep -v ftp |grep -v wtmp |awk ' /still logged/ { print $1 ".*still logged in"; next } { print $1 }' |sort -u | while read name
do
last | grep -v ftp | grep -v wtmp | grep -c "^$name" | read count
echo "$name \t$count"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:27 AM
03-06-2002 11:27 AM
Re: help with script break down ..
Hope this is what you were looking for,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:30 AM
03-06-2002 11:30 AM
Re: help with script break down ..
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:30 AM
03-06-2002 11:30 AM
Re: help with script break down ..
#!/bin/sh -x
then when you call it from the command line do
# ./script.sh > /tmp/output 2>&1
You'll get a lot of good information out of that logfile.
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:49 AM
03-06-2002 11:49 AM
Re: help with script break down ..
for i in `last | grep -v ftp |grep -v wtmp | awk '/still logged/{print $1}' | so
rt -u`
do
last $i | wc -l | read count
echo $i $count
done
A little clean, easier to understand, and about twice as fast. Just me though.
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2002 11:51 AM
03-06-2002 11:51 AM
Re: help with script break down ..
last $i | grep still | wc -l | read count
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2002 02:07 AM
03-07-2002 02:07 AM
Re: help with script break down ..
The reason your script is behaving like this is because you're not grepping out blank lines. Therefore, your first $name is "", which is obviously matched on every line in the second part of your script. Just add an extra grep to fix it:
==================================
last | grep -v ^$ | grep -v ftp |grep -v wtmp | awk ' /still logged/ { print $1 ".*still logged in"; next } { print $1 }' |sort -u | while read name
do
last | grep -v ftp | grep -v wtmp | grep -c "^$name" | read count
echo "$name \t$count"
done
===================================
I would have written the script slightly differently, using uniq to get the count:
last | grep -v -e ^$ -e wtmp -e ftp |
awk ' /still logged/ { print $1 " still logged in"; next } { print $1 }' |
sort | uniq -c
Rgds, Robin.