- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script formatting problem
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
02-07-2006 03:16 PM
02-07-2006 03:16 PM
I am running the folloing script
echo "enter user name"
read a
echo "Login name User Name"
echo "`cat /etc/passwd |grep $a |cut -d ":" -f1,5 | cut -d "," -f1 |cut -d ":" -f1` `cat /etc/passwd |grep $a |cut -d ":" -f1,5 | cut -d "," -f1 |cut -d ":" -f2`"
It works very good if there is only one user in the password file. the output comes like
Login name User Name
mayub Mohammad Ayub
But when there is more then one person the output comes like
Login name User Name
ssingh
psingh
gsingh
psingh1 Shobhana Singh
Parwin Singh
Gurvinder Singh
Priya Singh
i want then like
Login name User Name
mayub Mohammad Ayub
How can i do that
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 03:33 PM
02-07-2006 03:33 PM
Re: script formatting problem
echo "enter user name"
read a
echo "enter login"
read b
grep $b /etc/passwd | grep $a | awk -F: '{print $1}'
# not sure on the verification part what you want but this will surely get ONLY one line out of /etc/passwd
# note using passwd file this way is not recommended.
# If I've nnot got it exactly right, just add another read statement.
The cut command is inferior to awk in this case because awk can parse this database (that is what passwd is) by its field boundries, the colon.
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
02-07-2006 03:46 PM
02-07-2006 03:46 PM
Re: script formatting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 03:52 PM
02-07-2006 03:52 PM
Re: script formatting problem
echo "enter user name"
read a
echo "Login name User Name"
ypcat passwd | grep $a | awk -F":" '{print $1,$5}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 03:55 PM
02-07-2006 03:55 PM
Re: script formatting problem
grep $a /etc/passwd | awk -F : '{print $1,$5}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 03:56 PM
02-07-2006 03:56 PM
Re: script formatting problem
Login name User Name
ssingh Shobhana Singh,,,
psingh Parwin Singh,,,
gsingh Gurvinder Singh,,,
psingh1 Priya Singh,,,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 04:02 PM
02-07-2006 04:02 PM
Re: script formatting problem
You can use "awk". It provides better ease use just like, awk -F : '{print $1,$5}'
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 04:25 PM
02-07-2006 04:25 PM
Re: script formatting problem
If you want to check for a null (empty) field, then the script gets more complex, but I can help with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 04:37 PM
02-07-2006 04:37 PM
Re: script formatting problem
There might be a error in cutting of the fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 05:16 PM
02-07-2006 05:16 PM
Re: script formatting problem
This script line of,
echo "`cat /etc/passwd |grep $a |cut -d ":" -f1,5 | cut -d "," -f1 |cut -d ":" -f1` `cat /etc/passwd |grep $a |cut -d ":" -f1,5 | cut -d "," -f1 |cut -d ":" -f2`"
is very odd. You have written a simple thing in a big manner. Kwel.
We will help you out. For formatting better use printf rather than echo.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 05:38 PM
02-07-2006 05:38 PM
Re: script formatting problem
user1 user2?
echo "enter user name"
read a
echo "Login name User Name"
echo "`cat /etc/passwd |grep $a |cut -d ":" -f1,5 | cut -d "," -f1 |cut -d ":" -f1` `cat /etc/passwd |grep $a |cut -d ":" -f1,5 | cut -d "," -f1 |cut -d ":" -f2`"
It will generate for only one user else error. Can you post exact script contents and /etc/passwd entry for two users?
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 07:16 PM
02-07-2006 07:16 PM
Re: script formatting problem
your grep statement probably matches more than a single name/line. If you run 11.11, try changing:
grep $a
to
grep -w "$a"
which will force grep to match only whole words. This will of course not guarantee match of only a single name/line, but may be an improvement.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2006 11:56 PM
02-07-2006 11:56 PM
Re: script formatting problem
read a
awk -F':' -v user=$a '{ if(match($1, user)!=0) printf("%s %s\n", $1, $4); }' < /etc/passwd
You can even enhance printf format string as you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2006 01:11 AM
02-08-2006 01:11 AM
Re: script formatting problem
If you don't mind using perl, the following script will offer what you want.
The script considers the username to be the string of characters in the 'gecos' field up until the first comma if there is one. If the 'gecos' field is empty "[no info]" is reported. If a login name isn't valid, that is reported instead.
# cat ./whatuser
#!/usr/bin/perl
use strict;
use warnings;
my ($name, $gecos);
print "Enter user name (^C to quit)\n";
while (1) {
chomp ($name = <>);
($name,undef,undef,undef,undef,undef,$gecos) = getpwnam $name;
if (defined $name) {
$gecos =~ m/(.+?),/;
printf "%-8s %-16s\n", $name, $1 ? $1 : "[no info]";
} else {
warn "isn't a valid login\n";
}
}
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2006 01:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2006 01:53 AM
02-08-2006 01:53 AM
Re: script formatting problem
using finger add $9 if you have users with middle name too.
for i in $(cat /etc/passwd |awk -F ":" '{print $1}')
do
echo $i
finger $i |grep "In real life" |awk '{print $3 ":" $7 $8}'>> /tmp/t1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2006 02:22 AM
02-08-2006 02:22 AM
Re: script formatting problem
to my reply, you have to cat /vi/view the output at /tmp/t1.
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2006 09:16 AM
02-08-2006 09:16 AM
Re: script formatting problem
I user your script and it solved my problem.
Hi JFR,
I donot use parl script.
Thanks