[HELP] what does "2>&1" do in crontab?

Thread Tools Search this Thread
Operating Systems Solaris [HELP] what does "2>&1" do in crontab?
# 1  
Old 11-14-2012
[HELP] what does "2>&1" do in crontab?

Hi Experts,

I would like to know, what does "2>&1" do in crontab?

* * * * * /export/user/home/test.sh >> /export/user/home/logtest.log 2>&1

My colleague told me the commabd 2>&1 mean to prevent crontab sending an email (sendmail on /var/mail/root) when the script failed. So, if error occur when the crontab script failed, the email will dump to logtest.log not on /var/mail/root.
Is it true?

Why system always sending email if crontab script failed? and with adding command 2>&1 can solve the problem?
# 2  
Old 11-14-2012
Your colleague is correct. The 2>&1 just redirects Channel 2 (Standard Error) and Channel 1 (Standard Output) to the same place which in this context is Channel 1 (Standard Output), and thence your log file.
If all output from a cron is redirected to a file, it will not generate an email of the output to Stdout or Stderr.
Hope this helps.
# 3  
Old 11-14-2012
Hi methyl,

Thanks for your reply.

I have tested, if the output error rc=1, it will not generate an email of the output, but redirected to a file.

If the output warning (rc=4) can be redirected to a file?
Could you give me the simple scenario for output warning, please?

By adding "2>&1" is it the best choice for redirect output cron to a file?

# 4  
Old 11-14-2012
If you want to do the redirection on the crontab line this the best solution based on the information supplied.

It would really help if you posted what Operating System and version you are running (okay we know that is is a Solaris) and what Shell you are using when in crontab. Under Solaris the Shell under cron can be an ancient Bourne Shell.
# 5  
Old 11-14-2012
By adding "2>&1" is it the best choice for redirect output cron to a file?
Personally I would redirect the two output chanels to different files.
2>error_log.txt 1>normal_log.txt

Really depends on the application.
This User Gave Thanks to methyl For This Post:
# 6  
Old 11-14-2012
Yes, i used Solaris 10. The scripts just moving text file to another directory with specific pattern.

If i modify the script became :
2>error_log.txt 1>normal_log.txtWhen the warning info occur, will be redirected to error_log.txt or normal_log.txt ?

Just basic question, how to include time stamp? But when i have tested, time stamp cannot include.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Web Development

How would I mod_rewrite "/~a1Pha" and "/=a1Pha" to "/paste/a1Pha.htm"? (internally & externally)

Basically I want to shorten URLs on my html pasting site (pasteht.ml), by using "/~a1Pha" instead of "/paste/a1Pha". The ID is 5 numbers and letters, both cases. For example: /~idnum serves /paste/idnum.htm /=idnum serves /paste/idnum.htm /paste/idnum redirects to /~idnum (to update any old... (0 Replies)
Discussion started by: phillips1012
0 Replies

4. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

5. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

8. HP-UX

To give the "unzip" permissions & "create" file permissions

Hi, I am a Unix Admin. I have to give the permissions to a user for creating new file in a directory in HP-Ux 11.11 system since he cannot able to create a new file in the directory. Thanks in advance. Mike (3 Replies)
Discussion started by: Mike1234
3 Replies

9. UNIX for Dummies Questions & Answers

Run away "bootpgw" & "inetd"

Hello All. I'm get the following messages posted to the /var/adm/syslog file ever second and not sure on how to stop the process. May 14 15:50:52 a3360 bootpgw: version 2.3.5 May 14 15:50:52 a3360 inetd: /etc/bootpgw exit 0x1 As said about this gets logged every second only thing that... (4 Replies)
Discussion started by: cfaiman
4 Replies

10. UNIX for Dummies Questions & Answers

"nohup" and "&" commands

Why would anyone ever type in a command like this: nohup command & nohup lets you logout of your telnet session so why add "&" to run it in the background? (1 Reply)
Discussion started by: xadamz23
1 Replies
Login or Register to Ask a Question

Featured Tech Videos