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
08-14-2005 01:52 PM
08-14-2005 01:52 PM
Please see the below command:
/usr/lbin/qs >> /var/adm/qs/qs.log 2>&1
In this what is the meaning of 2>&1 ?
I have seen this in most of the cron jobs and some shell scripts.
What would be repercussion of this if we forget to mentioned 2>&1 ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 02:12 PM
08-14-2005 02:12 PM
Re: 2>&1
This type of syntax is used to collect the standard output and standard error in the file preceeding it.
Like in your case when the script /usr/lbin/qs runs the standard output and standard error of the files will be appended to the file /var/adm/qs/qs.log and if you miss the syntax 2>&1 then only the output of the command will be in the file.
Have a look at the man pages of sh-bourne for more details
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 02:43 PM
08-14-2005 02:43 PM
SolutionTechnically those are file descriptors.
File descriptor 0 = standard input
File descriptor 1 = standard output
File descriptor 2 = standard error
Now normally when you do things via a terminal session file descriptors 1 and 2 both come back to the screen.
But if you do a command like:
# ll > afile
That will just redirect file descriptor 1 to the file afile. If there are any errors, then you would see them echo'd to the screen.
If you did:
# ll > afile 2>&1
Then you are telling the shell to redirect file descriptor 2 (standard error) to the same location as file descriptor 1 (standard out) which is redirected to the file afile.
Now you could get more complicated and redirect standard out and standard error to different locations if you want to.
Something like:
# ll 1>file.log 2>file.error
The above will send file descriptor 1 (standard output) to file.log and file descriptor 2 (standard error) to file.error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 06:06 PM
08-14-2005 06:06 PM
Re: 2>&1
The only difference in using 2>&1 and >afile 2>err.log is that in the first the output and error is sent synchronously to single file whereas in the other case the output is to different files asynchronously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 07:36 PM
08-14-2005 07:36 PM
Re: 2>&1
explanations...
very clear
Good Luck,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2005 07:59 PM
08-14-2005 07:59 PM
Re: 2>&1
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=891230
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=841251
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=126984
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=113110
Good luck,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 01:06 AM
08-16-2005 01:06 AM
Re: 2>&1
You asked about repercussions if you don't use it?
Cron jobs should not have any output going to standard output. Using the 2>&1 on the command line lets you log any errors and keep them from going to standard output.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 01:16 AM
08-16-2005 01:16 AM
Re: 2>&1
Otherwise it might mess up your normal work.
Since cron runs in background, you should output its error to a log file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2005 02:09 AM
08-16-2005 02:09 AM
Re: 2>&1
http://wks.uts.ohio-state.edu/unix_course/intro-69.html