- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find out where stdout and stderr have been redirec...
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
05-18-2005 05:59 AM
05-18-2005 05:59 AM
find out where stdout and stderr have been redirected to
05 * * * * /home/Utility/myjob.sh > /myjob.log
In the shell script myjob.sh, how can I determine that stdout has been redirected to /myjob.log? Or is there a way to see the "whole" command line that was used to execute the script? I know $0 gives me the script name, but not the rest of the line. Thanks for any help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 06:03 AM
05-18-2005 06:03 AM
Re: find out where stdout and stderr have been redirected to
Change your entry to:
05 * * * * /home/Utility/myjob.sh > /myjob.log 2>&1
Then all errors will go to your log file...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 07:12 AM
05-18-2005 07:12 AM
Re: find out where stdout and stderr have been redirected to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 07:33 AM
05-18-2005 07:33 AM
Re: find out where stdout and stderr have been redirected to
If is understood the question properly, i can say that first check the return code of the command and then the size of the file myjob.log.
If the size changes after the command has executed that means it has redirected the output to your log file (assuming command really generate some output).
Hope that helps.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 07:39 AM
05-18-2005 07:39 AM
Re: find out where stdout and stderr have been redirected to
Say someone does the following command:
/root/utility_script.sh > /user1/test.log
In side the script utility_script.sh, I do not know whether the output has been redirected. I want to know how to find out what stdout is assigned (directed) to when the script is executed. In this case, the script would find out that stdout has been redirected to /user1/test.log. I need to find the filename that stdout has been redirected to, or the tty if it has not been redirected. Thanks. Hope this is clearer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 08:10 AM
05-18-2005 08:10 AM
Re: find out where stdout and stderr have been redirected to
You wrote ........
In this case,
the script would find out that stdout has been redirected to /user1/test.log.
I need to find the filename that stdout has been redirected
..................................
Now i can't differentiate the two statements above!!!
Well the answer to the second statemnt comes as: myjob.log
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 08:19 AM
05-18-2005 08:19 AM
Re: find out where stdout and stderr have been redirected to
In the first line of the myjob.sh script, add a timestamp:
print "### $0 executed on `/usr/bin/date` ###"
Then check the log...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 08:46 AM
05-18-2005 08:46 AM
Re: find out where stdout and stderr have been redirected to
lsof -p$$ -a -d2 -d1
This will display the STDOUT and STDERR mappings for the current process.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2005 08:57 AM
05-18-2005 08:57 AM
Re: find out where stdout and stderr have been redirected to
exec >/tmp/utility_script.out 2>&1
as the first line in your script, will make sure that output always goes to that file.
You can also test STDOUT to see if it is assigned to the terminal with-
if [[ -t 1 ]] ; then
echo "STDOUT is on a terminal..."
fi
HTH
-- Rod Hills