- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: for-do-done for 2 Fields
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
тАО10-26-2005 01:34 AM
тАО10-26-2005 01:34 AM
I need to create about 130 user accounts on a new server. The App Team have provided me with a file containing, what will be their 5 digit uid, and a comment field containing thier full name, and location (comma delimited).
Looks a bit like this:
12345 First Surname,UK/Town Name
I'm a bit stumped as to how I'm going to achieve the following:
useradd -u
Solved! Go to Solution.
- Tags:
- useradd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2005 01:51 AM
тАО10-26-2005 01:51 AM
Re: for-do-done for 2 Fields
cat file |
while read uid rest
do
print "uid = $uid and rest = $rest"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2005 01:51 AM
тАО10-26-2005 01:51 AM
Solutioncat myfile | while read line
do
field1=`echo $line|cut -d, -f1`
field2=`echo $line|cut -d, -f2`
UID=`echo field1|awk {'print $1'}`
NameSurname=`echo field1|awk {'print $2" "$3'}`
LOCATION=$field2
useradd -u $UID -g $GID -d /apps/gns -s /apps/gns/bin/pfash -c "${NameSurname},${LOCATION}" $username
# on this statetement, you need to set the username and GID variables
# before executing the last command.
done
Hope this helps
UNIX because I majored in cryptology...
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2005 01:56 AM
тАО10-26-2005 01:56 AM
Re: for-do-done for 2 Fields
with the read command the first field is assigned to the first name, the second field to the second name, etc., with the leftover fields assigned to the last name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2005 02:04 AM
тАО10-26-2005 02:04 AM
Re: for-do-done for 2 Fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2005 02:05 AM
тАО10-26-2005 02:05 AM
Re: for-do-done for 2 Fields
Curt's suggestion is a good one for its simplicity. I'll add another useful tip:
The shell's IFS (Inter-Field-Separater) is designed to be leveraged for problems like this. You can set the value of 'IFS' to any character you choose. For example, if the colon (":") character delmited your fields:
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read A B C
do
echo "${A} ${B} ${C}"
done < myfile
IFS=${IFS}
Regards!
...JRF...
- Tags:
- IFS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2005 02:06 AM
тАО10-26-2005 02:06 AM
Re: for-do-done for 2 Fields
For example,
/tmp/userlist:
user1 111 333 /home/home /shell "comment with spaces"
user2 222 433 /home/home /shell "comment with spaces"
Try this:
cat /tmp/userlist | while read USERNAME UID GID HOME SHELL COMMENT
do
useradd -u $UID -g $GID -d $HOME -s $SHELL -c $COMMENT $USERNAME
done