- 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
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
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 06:03 AM
07-29-2009 06:03 AM
Re: scripting user list
GM,
The script worked like a charm for all ID's except one id..the id name was dba10gaf, not sure why the script( shell version above) did not work for this ID.
Thanks
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 06:09 AM
07-29-2009 06:09 AM
Re: scripting user list
> The script worked like a charm for all ID's except one id..the id name was dba10gaf, not sure why the script( shell version above) did not work for this ID.
If you dropped the caret (beginning-of-line) anchor, you would see this behavior:
# USERID=dba10gaf
# echo ${USERID}|grep -q -E '^[a-zA-Z]+$' && echo ${USERID}
#
# echo ${USERID}|grep -q -E '[a-zA-Z]+$' && echo ${USERID}
dba10gaf
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 06:11 AM
07-29-2009 06:11 AM
Re: scripting user list
The grep statement is not picking up numbers in the id.
echo ${USERID} | grep -q -E '^[a-zA-Z]+$' && echo ${USERID}
Changes to...
echo ${USERID} | grep -q -E '^[a-zA-Z0-9]+$' && echo ${USERID}
Untested.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 06:17 AM
07-29-2009 06:17 AM
Re: scripting user list
> SEP: The grep statement is not picking up numbers in the id.
SEP, _READ_ the initial OP request again. Mike wants to EXCLUDE accounts like 'jk4567'.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 07:06 AM
07-29-2009 07:06 AM
Re: scripting user list
do you recommenend to use..
echo ${USERID}|grep -q -E '[a-zA-Z]+$' && echo ${USERID}
?
Thanks
MIke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 07:15 AM
07-29-2009 07:15 AM
Re: scripting user list
> do you recommenend to use..
> echo ${USERID}|grep -q -E '[a-zA-Z]+$' && echo ${USERID}
No, while this will eliminate accounts like 'jk4567' it will not eliminate accounts like 'jk45lm'.
# echo ${USERID} | grep -q -E '^[a-zA-Z]+$' && echo ${USERID}
...skips both the aforementioned accounts. Isn't that what you want?
If so, notice the caret (^) to anchor the match to the beginning of the string, together with the dollar-sign ($) to anchor to the end of the string.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 07:30 AM
07-29-2009 07:30 AM
Re: scripting user list
You are correct about excluding jk4567. only these needs to be excluded.(2numbers4letters exact(like 2 numbers first, followed by four letters- total 6) but i still need id's like jk45lm or longer id's (than 6)dba10gaf etc. Thanks JRF, once again
Thanks
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 07:40 AM
07-29-2009 07:40 AM
Re: scripting user list
> You are correct about excluding jk4567. only these needs to be excluded.(2numbers4letters exact(like 2 numbers first, followed by four letters- total 6) but i still need id's like jk45lm or longer id's (than 6)dba10gaf etc.
See if this meets your needs:
# echo ${USERID} | grep -q -E '^[a-zA-Z]+[0-9]+[a-zA-Z]+$' && echo ${USERID}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 10:46 AM
07-29-2009 10:46 AM
Re: scripting user list
THANKS, it works
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2009 01:06 PM
07-29-2009 01:06 PM
Re: scripting user list
If you wanted exactly this, you could have used my regexp.