On closing the Terminal the nohupped shell script (with &) is stopped












0















I'm developing a simple screenshot spyware which takes screenshot every 5 seconds from start of the script. I want it to run on closing the terminal. Even after nohupping the script along with '&', my script exits on closing the terminal.



screenshotScriptWOSleep.sh



    #!/bin/bash

echo "Starting Screenshot Capture Script."
echo "Process ID: $$"
directory=$(date "+%Y-%m-%d-%H:%M")
mkdir ${directory}
cd ${directory}
shotName=$(date "+%s")
while true
do
if [ $( date "+%Y-%m-%d-%H:%M" ) != ${directory} ]
then
directory=$(date "

+%Y-%m-%d-%H:%M")
cd ..
mkdir ${directory}
cd ${directory}
fi
if [ $(( ${shotName} + 5 )) -eq $(date "+%s" ) ]
then
shotName=$(date "+%s" )
screencapture -x $(date "+%Y-%m-%d-%H:%M:%S" )
fi
done


I ran the script with,
nohup ./screenshotScriptWOSleep.sh &



On closing the terminal window, it warns with,
"Closing this tab will terminate the running processes: bash, date."



I have read that the nohup applies to the child process too, but i'm stuck here. Thanks.










share|improve this question























  • This might work: nohup ./screenshotScriptWOSleep.sh >/dev/null 2>&1 &

    – Cyrus
    Nov 25 '18 at 10:13











  • FOUND! Hey all, found the issues behind this. nohup doesn't work as expected in mac's terminal. I used iterm2 to nohup and it worked.

    – Naveen Regulus
    Nov 30 '18 at 7:29


















0















I'm developing a simple screenshot spyware which takes screenshot every 5 seconds from start of the script. I want it to run on closing the terminal. Even after nohupping the script along with '&', my script exits on closing the terminal.



screenshotScriptWOSleep.sh



    #!/bin/bash

echo "Starting Screenshot Capture Script."
echo "Process ID: $$"
directory=$(date "+%Y-%m-%d-%H:%M")
mkdir ${directory}
cd ${directory}
shotName=$(date "+%s")
while true
do
if [ $( date "+%Y-%m-%d-%H:%M" ) != ${directory} ]
then
directory=$(date "

+%Y-%m-%d-%H:%M")
cd ..
mkdir ${directory}
cd ${directory}
fi
if [ $(( ${shotName} + 5 )) -eq $(date "+%s" ) ]
then
shotName=$(date "+%s" )
screencapture -x $(date "+%Y-%m-%d-%H:%M:%S" )
fi
done


I ran the script with,
nohup ./screenshotScriptWOSleep.sh &



On closing the terminal window, it warns with,
"Closing this tab will terminate the running processes: bash, date."



I have read that the nohup applies to the child process too, but i'm stuck here. Thanks.










share|improve this question























  • This might work: nohup ./screenshotScriptWOSleep.sh >/dev/null 2>&1 &

    – Cyrus
    Nov 25 '18 at 10:13











  • FOUND! Hey all, found the issues behind this. nohup doesn't work as expected in mac's terminal. I used iterm2 to nohup and it worked.

    – Naveen Regulus
    Nov 30 '18 at 7:29
















0












0








0








I'm developing a simple screenshot spyware which takes screenshot every 5 seconds from start of the script. I want it to run on closing the terminal. Even after nohupping the script along with '&', my script exits on closing the terminal.



screenshotScriptWOSleep.sh



    #!/bin/bash

echo "Starting Screenshot Capture Script."
echo "Process ID: $$"
directory=$(date "+%Y-%m-%d-%H:%M")
mkdir ${directory}
cd ${directory}
shotName=$(date "+%s")
while true
do
if [ $( date "+%Y-%m-%d-%H:%M" ) != ${directory} ]
then
directory=$(date "

+%Y-%m-%d-%H:%M")
cd ..
mkdir ${directory}
cd ${directory}
fi
if [ $(( ${shotName} + 5 )) -eq $(date "+%s" ) ]
then
shotName=$(date "+%s" )
screencapture -x $(date "+%Y-%m-%d-%H:%M:%S" )
fi
done


I ran the script with,
nohup ./screenshotScriptWOSleep.sh &



On closing the terminal window, it warns with,
"Closing this tab will terminate the running processes: bash, date."



I have read that the nohup applies to the child process too, but i'm stuck here. Thanks.










share|improve this question














I'm developing a simple screenshot spyware which takes screenshot every 5 seconds from start of the script. I want it to run on closing the terminal. Even after nohupping the script along with '&', my script exits on closing the terminal.



screenshotScriptWOSleep.sh



    #!/bin/bash

echo "Starting Screenshot Capture Script."
echo "Process ID: $$"
directory=$(date "+%Y-%m-%d-%H:%M")
mkdir ${directory}
cd ${directory}
shotName=$(date "+%s")
while true
do
if [ $( date "+%Y-%m-%d-%H:%M" ) != ${directory} ]
then
directory=$(date "

+%Y-%m-%d-%H:%M")
cd ..
mkdir ${directory}
cd ${directory}
fi
if [ $(( ${shotName} + 5 )) -eq $(date "+%s" ) ]
then
shotName=$(date "+%s" )
screencapture -x $(date "+%Y-%m-%d-%H:%M:%S" )
fi
done


I ran the script with,
nohup ./screenshotScriptWOSleep.sh &



On closing the terminal window, it warns with,
"Closing this tab will terminate the running processes: bash, date."



I have read that the nohup applies to the child process too, but i'm stuck here. Thanks.







bash shell terminal scripting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 9:39









Naveen RegulusNaveen Regulus

13




13













  • This might work: nohup ./screenshotScriptWOSleep.sh >/dev/null 2>&1 &

    – Cyrus
    Nov 25 '18 at 10:13











  • FOUND! Hey all, found the issues behind this. nohup doesn't work as expected in mac's terminal. I used iterm2 to nohup and it worked.

    – Naveen Regulus
    Nov 30 '18 at 7:29





















  • This might work: nohup ./screenshotScriptWOSleep.sh >/dev/null 2>&1 &

    – Cyrus
    Nov 25 '18 at 10:13











  • FOUND! Hey all, found the issues behind this. nohup doesn't work as expected in mac's terminal. I used iterm2 to nohup and it worked.

    – Naveen Regulus
    Nov 30 '18 at 7:29



















This might work: nohup ./screenshotScriptWOSleep.sh >/dev/null 2>&1 &

– Cyrus
Nov 25 '18 at 10:13





This might work: nohup ./screenshotScriptWOSleep.sh >/dev/null 2>&1 &

– Cyrus
Nov 25 '18 at 10:13













FOUND! Hey all, found the issues behind this. nohup doesn't work as expected in mac's terminal. I used iterm2 to nohup and it worked.

– Naveen Regulus
Nov 30 '18 at 7:29







FOUND! Hey all, found the issues behind this. nohup doesn't work as expected in mac's terminal. I used iterm2 to nohup and it worked.

– Naveen Regulus
Nov 30 '18 at 7:29














2 Answers
2






active

oldest

votes


















0














Either you're doing something really weird or that's referring to other processes.



nohup bash -c 'sleep 500' &


Shutdown that terminal; open another one:



ps aux | grep sleep
409370294 26120 1 0 2:43AM ?? 0:00.01 sleep 500
409370294 26330 26191 0 2:45AM ttys005 0:00.00 grep -i sleep


As you can see, sleep is still running.






share|improve this answer
























  • I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

    – Naveen Regulus
    Nov 26 '18 at 17:17





















0














Just ignore that warning, your process is not terminated. verify with



watch wc -l nohup.out






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466255%2fon-closing-the-terminal-the-nohupped-shell-script-with-is-stopped%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Either you're doing something really weird or that's referring to other processes.



    nohup bash -c 'sleep 500' &


    Shutdown that terminal; open another one:



    ps aux | grep sleep
    409370294 26120 1 0 2:43AM ?? 0:00.01 sleep 500
    409370294 26330 26191 0 2:45AM ttys005 0:00.00 grep -i sleep


    As you can see, sleep is still running.






    share|improve this answer
























    • I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

      – Naveen Regulus
      Nov 26 '18 at 17:17


















    0














    Either you're doing something really weird or that's referring to other processes.



    nohup bash -c 'sleep 500' &


    Shutdown that terminal; open another one:



    ps aux | grep sleep
    409370294 26120 1 0 2:43AM ?? 0:00.01 sleep 500
    409370294 26330 26191 0 2:45AM ttys005 0:00.00 grep -i sleep


    As you can see, sleep is still running.






    share|improve this answer
























    • I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

      – Naveen Regulus
      Nov 26 '18 at 17:17
















    0












    0








    0







    Either you're doing something really weird or that's referring to other processes.



    nohup bash -c 'sleep 500' &


    Shutdown that terminal; open another one:



    ps aux | grep sleep
    409370294 26120 1 0 2:43AM ?? 0:00.01 sleep 500
    409370294 26330 26191 0 2:45AM ttys005 0:00.00 grep -i sleep


    As you can see, sleep is still running.






    share|improve this answer













    Either you're doing something really weird or that's referring to other processes.



    nohup bash -c 'sleep 500' &


    Shutdown that terminal; open another one:



    ps aux | grep sleep
    409370294 26120 1 0 2:43AM ?? 0:00.01 sleep 500
    409370294 26330 26191 0 2:45AM ttys005 0:00.00 grep -i sleep


    As you can see, sleep is still running.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 25 '18 at 9:49









    jeremysprofilejeremysprofile

    1,6721617




    1,6721617













    • I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

      – Naveen Regulus
      Nov 26 '18 at 17:17





















    • I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

      – Naveen Regulus
      Nov 26 '18 at 17:17



















    I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

    – Naveen Regulus
    Nov 26 '18 at 17:17







    I did this without the sleep command. I also tried with sleep command. But on closing the terminal window the nohupped script along with the subprocess[date, screencapture, sleep] running terminates. I have read that the child process of nohup also ignores SIGHUP. Clarify me if i'm wrong. Thanks.

    – Naveen Regulus
    Nov 26 '18 at 17:17















    0














    Just ignore that warning, your process is not terminated. verify with



    watch wc -l nohup.out






    share|improve this answer




























      0














      Just ignore that warning, your process is not terminated. verify with



      watch wc -l nohup.out






      share|improve this answer


























        0












        0








        0







        Just ignore that warning, your process is not terminated. verify with



        watch wc -l nohup.out






        share|improve this answer













        Just ignore that warning, your process is not terminated. verify with



        watch wc -l nohup.out







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 9:51









        gopygopy

        1687




        1687






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466255%2fon-closing-the-terminal-the-nohupped-shell-script-with-is-stopped%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks