- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting
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
10-10-2002 10:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:03 AM
10-10-2002 11:03 AM
Re: Scripting
This works:
# X=`print -u2 "hello andrew" 2>&1`
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:05 AM
10-10-2002 11:05 AM
Re: Scripting
XX=$(my_command 2>&1)
${XX} will then contain both stdout's and stderr's output but to get them separately is a bit more difficult.
ERRS=""
TFILE=/var/tmp/XX${$}.err
XX=$(my_command 2>${TFILE})
if [[ -s ${TFILE} ]]
then
ERRS=$(cat ${TFILE})
fi
rm -f ${TFILE}
Now ${XX} contains the output of stdout and ${ERRS} contains that of stderr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:08 AM
10-10-2002 11:08 AM
Re: Scripting
Here what I am tring to do...
I am trying to put the elaspe time of a command into a variable
I was using
time {command}
to get the elaspe time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:09 AM
10-10-2002 11:09 AM
SolutionDo you mean that you want to capture stderr to a variable? Yes.
Using command substitution:
errormsg=$(command 2>&1 >/dev/ull)
The order of redirection is important! You first want to reassign stderr to what stdout is using, then redirect stdout to null if you don't it.
Using pipes and the shell's read command:
( command | read ouput ) 2>&1 | read error
This pipeline often confuses people. The grouping with parans is important because you want the stderr of the command to pass to the second read, not through first.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:13 AM
10-10-2002 11:13 AM
Re: Scripting
OK, thy this:
# time date 2> /tmp/mytime
# X=`# echo $X
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:13 AM
10-10-2002 11:13 AM
Re: Scripting
V=$(ls junk 2>&1 >V.out)
In this case, $V contains stderr from "ls junk" and V.out contains stdout.
You could capture stderr and stdout both to the variable:
V=$(ls junk 2>&1)
Lastly, to capture stderr in a variable and send stdout to the screen:
V=$(ls junk 2>&1 >$(tty))
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:25 AM
10-10-2002 11:25 AM
Re: Scripting
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:25 AM
10-10-2002 11:25 AM
Re: Scripting
etime=(time {command} 2>&1 >$(tty))
echo $etime
If you want to send stderr to the bit bucket:
etime=(time {command} 2>&1 >/dev/null)
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:29 AM
10-10-2002 11:29 AM
Re: Scripting
I'll have to point this out to Dan (the forums admin).
By the way, welcome to the forums Andrew. It's the best (even if there's been a few problems today with the site upgrade).
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:36 AM
10-10-2002 11:36 AM
Re: Scripting
t=$(time {Command} 2>&1 >/dev/null|grep real|awk '{print $2}')
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:51 AM
10-10-2002 11:51 AM
Re: Scripting
You can drop this grep this way:
t=$(time command 2>&1 >/dev/null | awk '$1~/^real$/{print $2}')
Or you can capture all times this to any array:
set -A t $(time command 2>&1 >/dev/null | awk '{print $2 $4 $6}')
echo real $t
echo all ${t[@]}
echo real ${t[0]} user ${t[1]} sys ${t[2]}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2002 11:56 AM
10-10-2002 11:56 AM
Re: Scripting
Another way of capturing just the timing statistics was shown in my second post. All three metrics are assigned to the variable as a simple string.
Regards!
...JRF...