- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script question
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
11-03-2005 12:02 AM
11-03-2005 12:02 AM
shell script question
When I ask the user for a response with the 2nd read statement, this statement is ignored?
Can someone help please?
#!/usr/bin/ksh
clear
cat /ignite_images/clients.txt | while read a b c
do
if [ $b = "hpux003" ]
then
i=50
while (( i < 100 ))
do
tput cup 6 5 ; echo "Load $a DAT tape in drive, enter [Yy] to Continue [Qq] to Quit : " ; tput cup 6 83
read resp
case $resp in
[Yy]) tput cup 7 5 ; echo "Copying lif_image to tape"
mt -t /dev/rmt/8mn rew
dd if=/ignite_images/net_recoveries/$1/lif_image of=/dev/rmt/8mn obs=2k > /tmp/dd.out 2>&1
dd if=/ignite_images/net_recoveries/$1/$d of=/dev/rmt/8mn obs=10k >> /tmp/dd.out 2>&1
mt -t /dev/rmt/8mn rew
i=200
;;
[Qq]) tput cup 7 5 ; echo "Not creating tape archive"
exit
;;
*) tput cup 6 83 ; echo " "
tput cup 7 0 ; echo " "
tput cup 7 5 ; echo "${blon}****** Invalid Option - Valid options are \"YyNn\" - Please try again.${blof}"
sleep 5
tput cup 7 0 ; echo " "
;;
esac
done
exit
else
:
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2005 12:08 AM
11-03-2005 12:08 AM
Re: shell script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2005 12:15 AM
11-03-2005 12:15 AM
Re: shell script question
The statement "read resp" does not wait for a response, it just drops through, I presume it has something to do with the initial read. How can I get the "read resp" to actually read a response.
I tried replacing the outer loop with
for i in `cat /ignite_images/clients.txt`
but each field on each line becomes a line in its own right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2005 12:37 AM
11-03-2005 12:37 AM
Re: shell script question
You are reading from the same descriptor. Duplicate a file descriptor (FD) for reading (.e.g. 3) and read from *that* FD for your second read. Consider:
#!/usr/bin/sh
exec 3<&0
cat /etc/hosts | while read LINE
do
echo "${LINE}"
read -u3 X
echo "You said ${X}"
done
By the way, using 'cat' to feed a 'read' generates a superflous process. It is much more economical to do:
while read LINE
do
...
done < filename
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2005 12:50 AM
11-03-2005 12:50 AM
Re: shell script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2005 01:27 AM
11-03-2005 01:27 AM
Re: shell script question
cat /ignite_images/clients.txt | while read a b c
Now everything inside this loop has its standard input directed from that pipeline.
Your "read resp" is reading from your /ignite_images/clients.txt file, not from the user.
You can force your "read resp" to read from the user by changing that line to:
read resp < /dev/tty
/dev/tty is a pseudo-device that always refers to "the standard input/output the session would have if no redirection were used".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2005 02:43 AM
11-03-2005 02:43 AM
Re: shell script question
You've acknowledged that you've gotten the answer you were needing, why not award points to the people whove spent their time to help you?
Every response to your question is eligible to earn between 1-10 points. No need to worry about running out of points - when a truly awesome reply rolls in that deserves a 10, you will be able to assign it a 10! However, be careful to assign points based on the value that a reply truly provides. Use the following scale as a guideline:
o N/A: The answer was simply a point of clarification to my original question
o 1-3: The answer didn't really help answer my question, but thanks for your assistance!
o 4- 7: The answer helped with a portion of my question, but I still need some additional help!
o 8-10: The answer has solved my problem completely! Now I'm a happy camper!
Although assigning points is not mandatory, it is a key component of a strong, interactive community, and it is STRONGLY ENCOURAGED. Others have taken time to help you, so please take a moment to give them credit for their assistance!