- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting user list
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
Discussions
Discussions
Forums
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
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
тАО07-28-2009 09:02 AM
тАО07-28-2009 09:02 AM
Thanks
Mike
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:11 AM
тАО07-28-2009 09:11 AM
Re: scripting user list
grep -v '^[a-zA-Z]\{2\}[0-9]\{4\}' user-list
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:13 AM
тАО07-28-2009 09:13 AM
Re: scripting user list
One way to generate your file of ids is this way:
# perl -e 'open($fh,"-|","logins -u") or die;while (<$fh>) {@F=split;print unless $F[0]=~m{\d+}}' > /var/tmp/logins
Then you can do:
#!/usr/bin/sh
while read USERID X
do
echo ${USERID}
done < /var/tmp/logins
You could imbed the Perl snippet in your shell script too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:32 AM
тАО07-28-2009 09:32 AM
Re: scripting user list
How would put all this in the same shell? Also is there a way the whole thing could be done via a shell script alone?
Thanks
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:37 AM
тАО07-28-2009 09:37 AM
Re: scripting user list
You don't want to use my grep or JRF's perl solution?
You can also use a real shell's pattern matching:
if [[ name != [a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9] ]]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:38 AM
тАО07-28-2009 09:38 AM
Re: scripting user list
if [[ "$name" != [a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9] ]]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:48 AM
тАО07-28-2009 09:48 AM
Solution> How would put all this in the same shell? Also is there a way the whole thing could be done via a shell script alone?
#!/usr/bin/sh
#!/usr/bin/sh
set -u
MYFILE=/var/tmp/mylogins
trap 'rm ${MYFILE}' EXIT
perl -e 'open($fh,"-|","logins -u") or die;
while (<$fh>) {@F=split;print unless $F[0]=~m{\d+}}' > ${MYFILE}
while read USERID X
do
echo ${USERID}
done < ${MYFILE}
...in pure Perl, I might do:
#!/usr/bin/perl
use strict;
use warnings;
my @F;
my $file = '/var/tmp/mylogins';
open(my $fh, "-|", "logins -u") or die "Can't open $file:$!\n";
while (<$fh>) {
@F=split;
system( "echo", $F[0] ) unless $F[0]=~m{\d+};
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 09:59 AM
тАО07-28-2009 09:59 AM
Re: scripting user list
Here's a pure shell variation along the lines that Dennis began:
#!/usr/bin/sh
logins -u | while read USERID X
do
echo ${USERID} | grep -q -E '^[a-zA-Z]+$' && echo ${USERID}
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 01:00 PM
тАО07-28-2009 01:00 PM
Re: scripting user list
One more question. in the script above i see 2 echo statements, i plug in the actual command instead of the second echo statement- correct?
Thanks
Mike.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-28-2009 01:34 PM
тАО07-28-2009 01:34 PM
Re: scripting user list
> One more question. in the script above i see 2 echo statements, i plug in the actual command instead of the second echo statement- correct?
Yes.
Given:
# echo ${USERID} | grep -q -E '^[a-zA-Z]+$' && echo ${USERID}
...we are feeding the ${USERID} value to 'grep' with the first 'echo'. If the return value from 'grep' is zero, there was a match and the second statement (another 'echo')is run. Hence, this is the one where you want to substitute the real command.
Regards!
...JRF...