- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Can ksh do filehandles?
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
тАО02-24-2010 10:45 AM
тАО02-24-2010 10:45 AM
Can ksh do filehandles?
I can't figure out any way to open the disk file within an iteration of the for loop, and have the script remember where it was in the disklist when it left off. For example, if my vg file contains the following:
vg00
vg01
And my disk file contains:
/dev/dsk/c0t0d0
/dev/dsk/c0t0d1
I want to process vg00, which will open the disk file and allocate c0t0d0 to it. Then when it processes vg01 on the next pass through the for loop, I want it to know that the next available disk is c0t0d1, not start from the beginning.
I know I can do this in perl relatively easily, but I want to use HP-UX's native ksh for portability (this is to automate some things for DR, and I can't guarantee that the DR systems would have any kind of perl at all).
I considered the possibility of maintaining a separate temporary file of "used" disks and doing a diff on it and the main disk file to get sublist of available disks, but that's kinda kludgey. If I can open a filehandle to the disklist and then read each disk in turn, that would be extremely rad.
Thanks!!!
- Tags:
- ksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 10:57 AM
тАО02-24-2010 10:57 AM
Re: Can ksh do filehandles?
> I want to process vg00, which will open the disk file and allocate c0t0d0 to it. Then when it processes vg01 on the next pass through the for loop, I want it to know that the next available disk is c0t0d1, not start from the beginning.
Consider using a shell array with the disk devices and an index that keeps track of the last device processed. You could even add to the array as you go along if this is necessary.
> I know I can do this in perl relatively easily...
Of course. I'm glad you said that :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 11:51 AM
тАО02-24-2010 11:51 AM
Re: Can ksh do filehandles?
Side note: You can guarantee perl and other resources are available in your DR servers by using Ignite tapes or network images to create said DR servers.
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-24-2010 12:32 PM
тАО02-24-2010 12:32 PM
Re: Can ksh do filehandles?
> SEP: Side note: You can guarantee perl and other resources are available in your DR servers by using Ignite tapes or network images to create said DR servers.
That presumes that the OP uses Ignite to clone to the DR site's bare metal. If that were the case you wouldn't expect the question posed with the disclaimer, "I can't guarantee that the DR systems would have any kind of perl at all)".
Regards!
...JRF...
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2010 09:11 PM
тАО02-24-2010 09:11 PM
Re: Can ksh do filehandles?
Kind of but it may be more trouble than it is worth. See below.
In awk you can read from stdin or the list of files and you can also read from other files:
getline var < "FILE1"
In a real shell, you can use file numbers with exec and then use read with those numbers:
TMP=/var/tmp/ef.$$
cat <
line 1
line 2
line 3
line 4
EOF
cat <
line A
line B
line C
EOF
# open $TMP.2 as file 3
exec 3< $TMP.2
echo "exec status: $?"
while read LINE1; do
echo $LINE1
read -u3 LINE2
if [ $? -eq 0 ]; then
echo "$LINE2"
else
echo "EOF file #3"
fi
done < $TMP.1
# Close file
exec 3<&-
rm -f $TMP.1 $TMP.2
- Tags:
- exec
- two-way pipe