On closing the Terminal the nohupped shell script (with &) is stopped
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
add a comment |
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
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
add a comment |
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
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
bash shell terminal scripting
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
Just ignore that warning, your process is not terminated. verify with
watch wc -l nohup.out
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Just ignore that warning, your process is not terminated. verify with
watch wc -l nohup.out
add a comment |
Just ignore that warning, your process is not terminated. verify with
watch wc -l nohup.out
add a comment |
Just ignore that warning, your process is not terminated. verify with
watch wc -l nohup.out
Just ignore that warning, your process is not terminated. verify with
watch wc -l nohup.out
answered Nov 25 '18 at 9:51
gopygopy
1687
1687
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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