- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using echo to create a script
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
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
тАО06-23-2009 09:22 AM
тАО06-23-2009 09:22 AM
I want to be able to create a script on the fly from another script by echoing lines into a file, but am running into difficulty, as it isn't working right. What am I doing wrong?
[CODE]
echo "for i in `grep $FRAME /root_home/powermt.sort.fil |awk '{print $7}'`" > pvtimout_set.sh
echo "do" >> pvtimout_set.sh
echo "echo ${i} ----------" >> pvtimout_set.sh
echo "echo pvchange -t 90 /dev/dsk/${i}" >> pvtimout_set.sh
echo "pvchange -t 90 /dev/dsk/${i}" >> pvtimout_set.sh
echo >> pvtimout_set.sh
echo "echo pvdisplay /dev/dsk/${i} |grep Timeout" >> pvtimout_set.sh
echo "pvdisplay /dev/dsk/${i} |grep Timeout" >> pvtimout_set.sh
echo >> pvtimout_set.sh
echo "done 2> /root_home/scripts/pvtimout.out 1>&2" >> pvtimout_set.sh
[/CODE]
Thanks for any help in advance!
Solved! Go to Solution.
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2009 09:32 AM
тАО06-23-2009 09:32 AM
Re: Using echo to create a script
those characters, including but not limited to, $,>,<,{,},'," any other I might not have caught, will need to be escaped, by preceeding them with a backslash character.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2009 09:33 AM
тАО06-23-2009 09:33 AM
Re: Using echo to create a script
IF you add a 'set -x' to this code you will see that evaluation of statements like "`grep $FRAME...`" is occuring and hence your script is hanging.
A much easier, clearer way to do this is with a HERE-DOC like this:
# cat .mymaker
#!/usr/bin/sh
cat <<-EOF! > pvtimeout.sh
for i in \`grep $FRAME /root_home/powermt.sort.fil |awk '{print $7}'\`
do
echo ${i} ----------
pvchange -t 90 /dev/dsk/${i}
pvchange -t 90 /dev/dsk/${i}
echo pvdisplay /dev/dsk/${i} |grep Timeout
pvdisplay /dev/dsk/${i} |grep Timeout
done
EOF!
Regards!
...JRF...
- Tags:
- here doc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2009 09:41 AM
тАО06-23-2009 09:41 AM
SolutionOoops, I neglected to escape (backslash) things like "$" :
# cat ./mymaker
#!/usr/bin/sh
cat <<-EOF! > pvtimeout.sh
for i in \`grep \$FRAME /root_home/powermt.sort.fil |awk '{print \$7}'\`
do
echo \${i} ----------
pvchange -t 90 /dev/dsk/\${i}
pvchange -t 90 /dev/dsk/\${i}
echo pvdisplay /dev/dsk/\${i} |grep Timeout
pvdisplay /dev/dsk/\${i} |grep Timeout
done
EOF!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2009 03:32 PM
тАО06-23-2009 03:32 PM
Re: Using echo to create a script
If you are using "\" before EVERY "$", you can stop that by quoting the word:
cat <<-\EOF!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2009 04:36 PM
тАО06-23-2009 04:36 PM
Re: Using echo to create a script
> Dennis: If you are using "\" before EVERY "$", you can stop that by quoting the word:
cat <<-\EOF!
This is a bit different from Perl and I didn't really _read_ the manpage sentence that says, "If any character of word is quoted...". You make that clear --- thanks for the pointer!
/* NO Points please for this note */
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2009 11:31 PM
тАО06-23-2009 11:31 PM
Re: Using echo to create a script
you can use
echo
{
# begin script
your code
# end script
}>your script
all code within {} will be redirect to your script.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2009 04:42 AM
тАО06-24-2009 04:42 AM
Re: Using echo to create a script
cat <<-EOF! > pvtimeout_set.sh
for i in \`grep ${FRAME} /tmp/powermt.sort.out |awk '{print \$7}'\`
do
echo \${i} ----------
echo pvchange -t ${TIMEOUT} /dev/dsk/\${i}
pvchange -t ${TIMEOUT} /dev/dsk/\${i}
echo pvdisplay /dev/dsk/\${i} |grep Timeout
pvdisplay /dev/dsk/\${i} |grep Timeout
echo
done
EOF!
Arturo,
That will pick up the echo statements I put into the script as well?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2009 06:14 AM
тАО06-24-2009 06:14 AM
Re: Using echo to create a script
I wonder how many times I've overlooked that sentence?
no points pls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2009 07:50 PM
тАО06-24-2009 07:50 PM
Re: Using echo to create a script
You forgot a "\" for ${FRAME}. Note your echo piped to grep.
I would suggest you redo it as:
cat <<-\EOF!
for i in $(grep ${FRAME} /tmp/powermt.sort.out | awk '{print $7}'); do
echo "${i} ----------"
echo "pvchange -t ${TIMEOUT} /dev/dsk/${i}"
pvchange -t ${TIMEOUT} /dev/dsk/${i}
echo "pvdisplay /dev/dsk/${i} | grep Timeout"
pvdisplay /dev/dsk/${i} | grep Timeout
echo
done
EOF!
>That will pick up the echo statements I put into the script as well?
See my improvements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2009 09:36 PM
тАО06-24-2009 09:36 PM
Re: Using echo to create a script
I did this on purpose, as I wanted the ${FRAME} variable passed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-24-2009 11:11 PM
тАО06-24-2009 11:11 PM
Re: Using echo to create a script
Ah, that's why it was empty for me.