bash script output not written to file in folder

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












My goal is to run a script in crontab and save its output (via echo commands) to a log file. Thus, I am using the following:



$HOME/folder/sh/script.sh 1>$HOME/folder/logs/script.log 2>$HOME/folder/logs/script.err


However, from the command line (not cron yet), I cannot see the log file at all. The permissions are valid.



If I remove the redirections or keep the redirection to a file in the current directory, I can see the (correct) log contents.



Why doesn't bash script output appear in the log file under a nested folder structure?










share|improve this question



















  • 2




    Are all the components of the pathnames correctly spelled? Does the directory exist? Do you have write permission in the directory? Are you looking in the correct location when you look for the log files?
    – Kusalananda
    Aug 23 at 9:13










  • Yes, yes, yes, yes. :D
    – cogitoergosum
    Aug 23 at 9:15






  • 2




    If the shell failed to create the files, it ought to give you an error. You haven't mentioned any diagnostic output from the shell or script, so we must assume that the output was actually successfully written somewhere. A directory listing of the $HOME/folder/logs directory would be nice to see.
    – Kusalananda
    Aug 23 at 9:22






  • 1




    Even an empty command, redirected to a file (e.g. : >file, a no-op command, redirected to file), will create the file (the shell creates the file before executing the command). You say that the files do not appear. This makes me believe that the redirection fails even before the script is executed. Either that, or your script is explicitly removing those files during the course of its execution.
    – Kusalananda
    Aug 23 at 9:28







  • 1




    For the script to start at all, the files redirected into must be created (see previous comment). Are you sure nothing deletes the log files during the course of running the script?
    – Kusalananda
    Aug 23 at 10:43














up vote
0
down vote

favorite












My goal is to run a script in crontab and save its output (via echo commands) to a log file. Thus, I am using the following:



$HOME/folder/sh/script.sh 1>$HOME/folder/logs/script.log 2>$HOME/folder/logs/script.err


However, from the command line (not cron yet), I cannot see the log file at all. The permissions are valid.



If I remove the redirections or keep the redirection to a file in the current directory, I can see the (correct) log contents.



Why doesn't bash script output appear in the log file under a nested folder structure?










share|improve this question



















  • 2




    Are all the components of the pathnames correctly spelled? Does the directory exist? Do you have write permission in the directory? Are you looking in the correct location when you look for the log files?
    – Kusalananda
    Aug 23 at 9:13










  • Yes, yes, yes, yes. :D
    – cogitoergosum
    Aug 23 at 9:15






  • 2




    If the shell failed to create the files, it ought to give you an error. You haven't mentioned any diagnostic output from the shell or script, so we must assume that the output was actually successfully written somewhere. A directory listing of the $HOME/folder/logs directory would be nice to see.
    – Kusalananda
    Aug 23 at 9:22






  • 1




    Even an empty command, redirected to a file (e.g. : >file, a no-op command, redirected to file), will create the file (the shell creates the file before executing the command). You say that the files do not appear. This makes me believe that the redirection fails even before the script is executed. Either that, or your script is explicitly removing those files during the course of its execution.
    – Kusalananda
    Aug 23 at 9:28







  • 1




    For the script to start at all, the files redirected into must be created (see previous comment). Are you sure nothing deletes the log files during the course of running the script?
    – Kusalananda
    Aug 23 at 10:43












up vote
0
down vote

favorite









up vote
0
down vote

favorite











My goal is to run a script in crontab and save its output (via echo commands) to a log file. Thus, I am using the following:



$HOME/folder/sh/script.sh 1>$HOME/folder/logs/script.log 2>$HOME/folder/logs/script.err


However, from the command line (not cron yet), I cannot see the log file at all. The permissions are valid.



If I remove the redirections or keep the redirection to a file in the current directory, I can see the (correct) log contents.



Why doesn't bash script output appear in the log file under a nested folder structure?










share|improve this question















My goal is to run a script in crontab and save its output (via echo commands) to a log file. Thus, I am using the following:



$HOME/folder/sh/script.sh 1>$HOME/folder/logs/script.log 2>$HOME/folder/logs/script.err


However, from the command line (not cron yet), I cannot see the log file at all. The permissions are valid.



If I remove the redirections or keep the redirection to a file in the current directory, I can see the (correct) log contents.



Why doesn't bash script output appear in the log file under a nested folder structure?







bash cron logs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 23 at 9:15

























asked Aug 23 at 9:07









cogitoergosum

1012




1012







  • 2




    Are all the components of the pathnames correctly spelled? Does the directory exist? Do you have write permission in the directory? Are you looking in the correct location when you look for the log files?
    – Kusalananda
    Aug 23 at 9:13










  • Yes, yes, yes, yes. :D
    – cogitoergosum
    Aug 23 at 9:15






  • 2




    If the shell failed to create the files, it ought to give you an error. You haven't mentioned any diagnostic output from the shell or script, so we must assume that the output was actually successfully written somewhere. A directory listing of the $HOME/folder/logs directory would be nice to see.
    – Kusalananda
    Aug 23 at 9:22






  • 1




    Even an empty command, redirected to a file (e.g. : >file, a no-op command, redirected to file), will create the file (the shell creates the file before executing the command). You say that the files do not appear. This makes me believe that the redirection fails even before the script is executed. Either that, or your script is explicitly removing those files during the course of its execution.
    – Kusalananda
    Aug 23 at 9:28







  • 1




    For the script to start at all, the files redirected into must be created (see previous comment). Are you sure nothing deletes the log files during the course of running the script?
    – Kusalananda
    Aug 23 at 10:43












  • 2




    Are all the components of the pathnames correctly spelled? Does the directory exist? Do you have write permission in the directory? Are you looking in the correct location when you look for the log files?
    – Kusalananda
    Aug 23 at 9:13










  • Yes, yes, yes, yes. :D
    – cogitoergosum
    Aug 23 at 9:15






  • 2




    If the shell failed to create the files, it ought to give you an error. You haven't mentioned any diagnostic output from the shell or script, so we must assume that the output was actually successfully written somewhere. A directory listing of the $HOME/folder/logs directory would be nice to see.
    – Kusalananda
    Aug 23 at 9:22






  • 1




    Even an empty command, redirected to a file (e.g. : >file, a no-op command, redirected to file), will create the file (the shell creates the file before executing the command). You say that the files do not appear. This makes me believe that the redirection fails even before the script is executed. Either that, or your script is explicitly removing those files during the course of its execution.
    – Kusalananda
    Aug 23 at 9:28







  • 1




    For the script to start at all, the files redirected into must be created (see previous comment). Are you sure nothing deletes the log files during the course of running the script?
    – Kusalananda
    Aug 23 at 10:43







2




2




Are all the components of the pathnames correctly spelled? Does the directory exist? Do you have write permission in the directory? Are you looking in the correct location when you look for the log files?
– Kusalananda
Aug 23 at 9:13




Are all the components of the pathnames correctly spelled? Does the directory exist? Do you have write permission in the directory? Are you looking in the correct location when you look for the log files?
– Kusalananda
Aug 23 at 9:13












Yes, yes, yes, yes. :D
– cogitoergosum
Aug 23 at 9:15




Yes, yes, yes, yes. :D
– cogitoergosum
Aug 23 at 9:15




2




2




If the shell failed to create the files, it ought to give you an error. You haven't mentioned any diagnostic output from the shell or script, so we must assume that the output was actually successfully written somewhere. A directory listing of the $HOME/folder/logs directory would be nice to see.
– Kusalananda
Aug 23 at 9:22




If the shell failed to create the files, it ought to give you an error. You haven't mentioned any diagnostic output from the shell or script, so we must assume that the output was actually successfully written somewhere. A directory listing of the $HOME/folder/logs directory would be nice to see.
– Kusalananda
Aug 23 at 9:22




1




1




Even an empty command, redirected to a file (e.g. : >file, a no-op command, redirected to file), will create the file (the shell creates the file before executing the command). You say that the files do not appear. This makes me believe that the redirection fails even before the script is executed. Either that, or your script is explicitly removing those files during the course of its execution.
– Kusalananda
Aug 23 at 9:28





Even an empty command, redirected to a file (e.g. : >file, a no-op command, redirected to file), will create the file (the shell creates the file before executing the command). You say that the files do not appear. This makes me believe that the redirection fails even before the script is executed. Either that, or your script is explicitly removing those files during the course of its execution.
– Kusalananda
Aug 23 at 9:28





1




1




For the script to start at all, the files redirected into must be created (see previous comment). Are you sure nothing deletes the log files during the course of running the script?
– Kusalananda
Aug 23 at 10:43




For the script to start at all, the files redirected into must be created (see previous comment). Are you sure nothing deletes the log files during the course of running the script?
– Kusalananda
Aug 23 at 10:43










1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you are sure about PATH, and permissions, and the same redirection works for other commands, it looks like your script is manipulating the log files or folders that you are trying to write (Ambiguous redirect).



It is that the case?



If so remove any lines of the script manipulating anything related to the logs, and try again.



If that works please select this as the correct answer.



If not please remove 2> run the script again, and watch what happen, maybe you will see a message showing why the script can't write to the files.



Good Lucky!






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464341%2fbash-script-output-not-written-to-file-in-folder%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If you are sure about PATH, and permissions, and the same redirection works for other commands, it looks like your script is manipulating the log files or folders that you are trying to write (Ambiguous redirect).



    It is that the case?



    If so remove any lines of the script manipulating anything related to the logs, and try again.



    If that works please select this as the correct answer.



    If not please remove 2> run the script again, and watch what happen, maybe you will see a message showing why the script can't write to the files.



    Good Lucky!






    share|improve this answer
























      up vote
      0
      down vote













      If you are sure about PATH, and permissions, and the same redirection works for other commands, it looks like your script is manipulating the log files or folders that you are trying to write (Ambiguous redirect).



      It is that the case?



      If so remove any lines of the script manipulating anything related to the logs, and try again.



      If that works please select this as the correct answer.



      If not please remove 2> run the script again, and watch what happen, maybe you will see a message showing why the script can't write to the files.



      Good Lucky!






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        If you are sure about PATH, and permissions, and the same redirection works for other commands, it looks like your script is manipulating the log files or folders that you are trying to write (Ambiguous redirect).



        It is that the case?



        If so remove any lines of the script manipulating anything related to the logs, and try again.



        If that works please select this as the correct answer.



        If not please remove 2> run the script again, and watch what happen, maybe you will see a message showing why the script can't write to the files.



        Good Lucky!






        share|improve this answer












        If you are sure about PATH, and permissions, and the same redirection works for other commands, it looks like your script is manipulating the log files or folders that you are trying to write (Ambiguous redirect).



        It is that the case?



        If so remove any lines of the script manipulating anything related to the logs, and try again.



        If that works please select this as the correct answer.



        If not please remove 2> run the script again, and watch what happen, maybe you will see a message showing why the script can't write to the files.



        Good Lucky!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 23 at 19:55









        Luciano Andress Martini

        3,153829




        3,153829



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464341%2fbash-script-output-not-written-to-file-in-folder%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)