- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- output redirection and wc
Operating System - HP-UX
1752795
Members
6034
Online
108789
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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-08-2010 06:33 PM
тАО10-08-2010 06:33 PM
Hi,
a simple question...
for i in NODE `cat nodeslist`
do
echo `date` >>HPDev.policies
eecho Node Name - $NODE >> HPDev.policies
ovdeploy -cmd "opctemplate -list" -node $NODE >>HPDev.policies 2>>HPDev.Policies.error | wc >>HPDev.policies
done
i am running a command to get list of policies on a node and sending it to a file. also the count of policies i would like to update.
but this "wc" does not work.
this above "wc" updates only 0 0 0
a simple question...
for i in NODE `cat nodeslist`
do
echo `date` >>HPDev.policies
eecho Node Name - $NODE >> HPDev.policies
ovdeploy -cmd "opctemplate -list" -node $NODE >>HPDev.policies 2>>HPDev.Policies.error | wc >>HPDev.policies
done
i am running a command to get list of policies on a node and sending it to a file. also the count of policies i would like to update.
but this "wc" does not work.
this above "wc" updates only 0 0 0
Solved! Go to Solution.
- Tags:
- redirect
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2010 07:11 PM
тАО10-08-2010 07:11 PM
Solution
> [...] but this "wc" does not work. [...]
It counts what it sees, but what does it see?
> [...] >>HPDev.policies
> [...] 2>>HPDev.Policies.error
> [...] | wc [...]
You seem to be sending stdout to one file,
and stderr to another file. Then you pipe
what's left into "wc", but what's left?
Everything has already been redirected to
some file or other.
Consider this simpler (all-shell) example:
dyi # ( echo stdout ; echo stderr 1>&2 )
stdout
stderr
Now, redirect stdout to "so", and stderr to
"se" (and look at those files):
dyi # ( echo stdout ; echo stderr 1>&2 ) > so 2> se
dyi # cat so
stdout
dyi # cat se
stderr
The files got their data, but there's nothing
left to be sent to the terminal (or into a
pipeline). Piping nothing into "wc" will
give you "0 0 0".
You could use "tee" to copy stdout into a
file, while passing it along in stdout. For
example:
dyi # ( echo stdout ; echo stderr 1>&2 ) 2> se | tee so
stdout
dyi # cat so
stdout
dyi # cat se
stderr
The files still get their data, but stdout
(here, "stdout") continues along to the
terminal, too. _This_ can be piped into
another program (like "wc"):
dyi # ( echo stdout ; echo stderr 1>&2 ) 2> se | tee so | wc
1 1 7
man tee
Look for "-a", which you'll probably want to
use (in place of ">>").
It counts what it sees, but what does it see?
> [...] >>HPDev.policies
> [...] 2>>HPDev.Policies.error
> [...] | wc [...]
You seem to be sending stdout to one file,
and stderr to another file. Then you pipe
what's left into "wc", but what's left?
Everything has already been redirected to
some file or other.
Consider this simpler (all-shell) example:
dyi # ( echo stdout ; echo stderr 1>&2 )
stdout
stderr
Now, redirect stdout to "so", and stderr to
"se" (and look at those files):
dyi # ( echo stdout ; echo stderr 1>&2 ) > so 2> se
dyi # cat so
stdout
dyi # cat se
stderr
The files got their data, but there's nothing
left to be sent to the terminal (or into a
pipeline). Piping nothing into "wc" will
give you "0 0 0".
You could use "tee" to copy stdout into a
file, while passing it along in stdout. For
example:
dyi # ( echo stdout ; echo stderr 1>&2 ) 2> se | tee so
stdout
dyi # cat so
stdout
dyi # cat se
stderr
The files still get their data, but stdout
(here, "stdout") continues along to the
terminal, too. _This_ can be piped into
another program (like "wc"):
dyi # ( echo stdout ; echo stderr 1>&2 ) 2> se | tee so | wc
1 1 7
man tee
Look for "-a", which you'll probably want to
use (in place of ">>").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2010 07:18 PM
тАО10-08-2010 07:18 PM
Re: output redirection and wc
thanks Steve, lot of info, good learning...
i found one small temporary (TEMP) idea, let me know this is good or not...here it is:
root@OVO> more agent-redeployment.sh
COUNT=1
for NODE in $( do
echo date is `date` >>HPDev.policies
echo Node Name - $NODE >>HPDev.policies
echo Server Count is ${COUNT} >>HPDev.policies
ovdeploy -cmd "opctemplate -list" -node $NODE >TEMPFILE 2>>HPDev.Policies.error
cat TEMPFILE >>HPDev.policies
wc TEMPFILE >>HPDev.policies
sleep 10
COUNT=${COUNT} + 1
done
1. this TEMPFILE idea is fine or not?
2. this COUNT=${COUNT} + 1 not works. like C++, do we have COUNT++ in shell scripting?
i found one small temporary (TEMP) idea, let me know this is good or not...here it is:
root@OVO> more agent-redeployment.sh
COUNT=1
for NODE in $(
echo date is `date` >>HPDev.policies
echo Node Name - $NODE >>HPDev.policies
echo Server Count is ${COUNT} >>HPDev.policies
ovdeploy -cmd "opctemplate -list" -node $NODE >TEMPFILE 2>>HPDev.Policies.error
cat TEMPFILE >>HPDev.policies
wc TEMPFILE >>HPDev.policies
sleep 10
COUNT=${COUNT} + 1
done
1. this TEMPFILE idea is fine or not?
2. this COUNT=${COUNT} + 1 not works. like C++, do we have COUNT++ in shell scripting?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2010 07:29 PM
тАО10-08-2010 07:29 PM
Re: output redirection and wc
>1. this TEMPFILE idea is fine or not?
Yes it will work. Make sure you clean it up and not have more than one use of the script at a time. Otherwise you need to make it unique by adding .$$
>2. this COUNT=${COUNT} + 1 not works. like C++, do we have COUNT++ in shell scripting?
No, a real shell says ++/-- are not supported. Use:
(( count += 1 ))
Yes it will work. Make sure you clean it up and not have more than one use of the script at a time. Otherwise you need to make it unique by adding .$$
>2. this COUNT=${COUNT} + 1 not works. like C++, do we have COUNT++ in shell scripting?
No, a real shell says ++/-- are not supported. Use:
(( count += 1 ))
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP