- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Getting script input from another file.
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
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
09-26-2000 09:55 AM
09-26-2000 09:55 AM
exec 5< /opt/security/os/eis2_fplus.data
IFS=":"
while read -u5 userid first_name last_name / user_role
The input data file looks like this...
qf71701:Joe:Blow:users:admin
Thanks.
I'm wanting to run a daily script to add new users and I want to put all of the user specific information into a delimited file that will gwt sent over each night. Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2000 10:53 AM
09-26-2000 10:53 AM
SolutionThis line opens an input stream (5) from the file /opt/security/os/eis2_fplus.data
2) IFS=":"
This line replaces the IFS variable (internal field separator: normally set to {space, tab, newline}) with the ":". In other words, all input will be delimited by colon rather than whitespace.
3) while read -u5 userid first_name last_name / user_role
This line sets a while loop which reads the fields "userid" "first_name" etc. from the input stream denoted by identifier "5".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2000 10:55 AM
09-26-2000 10:55 AM
Re: Getting script input from another file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2000 10:58 AM
09-26-2000 10:58 AM
Re: Getting script input from another file.
Explained line by line:
exec 5< /opt/security/os/eis2_fplus.data
-------
The exec shell built-in in this form (without arguments) rearranges I/O redirection, In your case, it means that the file is attached to file descriptor 5.
IFS=":"
-------
Set the IFS (Internal Field Separator) to the character ':'. The default IFS is whitespace, and is used to determine the boundaries between commands an options and arguments, to determine fields for some shell built-ins as read (as in your case).
while read -u5 userid first_name last_name / user_role
------
Read the next line from file descriptor 5 (that is connected to your file, remember), assigning the first field to the variable userid, the second field to the variable first_name and so forth.
For more information on this and other shell magic, see the shell manpage (sh-posix(1)) or one of the O'Reilly books on shell scripting.
Hope this helps,
Rik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2000 04:41 PM
09-26-2000 04:41 PM
Re: Getting script input from another file.
In reference to your question "So the occurrance of "5" is just a reference and doesn't hold any other significance?":
'5' happened to be the file descriptor number chosen by the programmer for association with the file /opt/security/os/eis2_fplus.data.
A file descriptor is a small unique, per-process, nonnegative integer identifier that is used to refer to a file opened for reading and/or writing. Each file descriptor refers to exactly one open file description.
Remember '0' is standard-in (stdin), '1' is the file descriptor for standard-out (stdout), and '2' is the descriptor for standard-error (stderr). The shell allows you to use values 3-9 to associate with any file of your choice. A larger number of descriptors are available to C-programs.
...JRF...