Bash script do not works when redirecting output to dev null


Results 1 to 2 of 2

Thread: Bash script do not works when redirecting output to dev null

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    34

    Bash script do not works when redirecting output to dev null

    Hello dear members, i have an bash script (i added it here) and im running it like every few minutes by cronjob from linux command line:

    crontab -l
    */3 * * * * /path/to/script.sh > /dev/null

    when i dont redirect it to dev null, it outputting some data during its run, which is quite wanted in case i want to run it manually so i want what it doing..

    ISSUE:

    when i run script manually with or without dev null, it succeed, but when it is run with dev null redirection by cronjob, it fails (some file handling functions dont works, because the file this script modifying is not updated...), so i would like to ask You to advice me on how to find what is causing this script to fail when running with dev null redirection by cronjob (when run manually not with cronjob, it succeed with dev null)

  2. #2
    Join Date
    Dec 2014
    Posts
    8
    redirection operators are evaluated left-to-right. what you did wrong was put 2>&1 first, which points "2" to the same place as "1 currently is pointed to" which is the local terminal screen because you have not redirected 1 yet. What you need to do is either of the following:
    2>/dev/null 1>/dev/null google-chrome &

    or
    2>/dev/null 1>&2 google-chrome &

    the placement of the redirect operators in relation to the command does not matter. you can put them before or after the command.
    Last edited by bestellen; 09-22-2015 at 01:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •