Using session command from a cron job (linux)

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to be able to start a named "session" from within a cron job and run a job within that named session. The job I need to run MAY cause my appliance to not run properly if problem exist and I need to be able to reattach to the named session created if needed/to close it later. Does anyone have any idea how I might do this?
linux cron command session
add a comment |Â
up vote
0
down vote
favorite
I need to be able to start a named "session" from within a cron job and run a job within that named session. The job I need to run MAY cause my appliance to not run properly if problem exist and I need to be able to reattach to the named session created if needed/to close it later. Does anyone have any idea how I might do this?
linux cron command session
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to be able to start a named "session" from within a cron job and run a job within that named session. The job I need to run MAY cause my appliance to not run properly if problem exist and I need to be able to reattach to the named session created if needed/to close it later. Does anyone have any idea how I might do this?
linux cron command session
I need to be able to start a named "session" from within a cron job and run a job within that named session. The job I need to run MAY cause my appliance to not run properly if problem exist and I need to be able to reattach to the named session created if needed/to close it later. Does anyone have any idea how I might do this?
linux cron command session
edited Nov 6 '17 at 19:26
asked Nov 6 '17 at 19:14
Marshal Tucker
31
31
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
GNU Screen or TMUX are probably your best options. The general concept of both is pretty similar to a tabbed window manager, but they're both for terminal usage, and you can detach from a session and re-attach later. I'm not quite certain about the syntax needed for TMUX, but for screen the command you want is:
screen -D -n -s <name> <command>
Replace <name> with the name of the session, and <command> with the command to run. YOu can then re-attach to the session with:
screen -D -r <name>
The only caveat is that yuu have to be running as the same user when you try to reattach that the session was started as (you can technically reattach to other users sessions, but it's a bit more complicated).
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
1
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually usescreen -xrather thanscreen -ras I often use multiclient sessions and-xis a superset of-rin that it will not fail if there is still ascreenclient attached.)
â DopeGhoti
Nov 6 '17 at 20:11
You don't even have to log in technically, you can also use a tool likesudoto switch to the appropriate UID (though I'm pretty suresuwon't work for this because it doesn't reset the environment properly). If you absolutely can't runscreen -rorscreen -xas that user, you can also prefix the session name with that user's name followed by a/, but I've had issues in the past with that not working reliably.
â Austin Hemmelgarn
Nov 6 '17 at 20:19
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
GNU Screen or TMUX are probably your best options. The general concept of both is pretty similar to a tabbed window manager, but they're both for terminal usage, and you can detach from a session and re-attach later. I'm not quite certain about the syntax needed for TMUX, but for screen the command you want is:
screen -D -n -s <name> <command>
Replace <name> with the name of the session, and <command> with the command to run. YOu can then re-attach to the session with:
screen -D -r <name>
The only caveat is that yuu have to be running as the same user when you try to reattach that the session was started as (you can technically reattach to other users sessions, but it's a bit more complicated).
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
1
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually usescreen -xrather thanscreen -ras I often use multiclient sessions and-xis a superset of-rin that it will not fail if there is still ascreenclient attached.)
â DopeGhoti
Nov 6 '17 at 20:11
You don't even have to log in technically, you can also use a tool likesudoto switch to the appropriate UID (though I'm pretty suresuwon't work for this because it doesn't reset the environment properly). If you absolutely can't runscreen -rorscreen -xas that user, you can also prefix the session name with that user's name followed by a/, but I've had issues in the past with that not working reliably.
â Austin Hemmelgarn
Nov 6 '17 at 20:19
add a comment |Â
up vote
1
down vote
accepted
GNU Screen or TMUX are probably your best options. The general concept of both is pretty similar to a tabbed window manager, but they're both for terminal usage, and you can detach from a session and re-attach later. I'm not quite certain about the syntax needed for TMUX, but for screen the command you want is:
screen -D -n -s <name> <command>
Replace <name> with the name of the session, and <command> with the command to run. YOu can then re-attach to the session with:
screen -D -r <name>
The only caveat is that yuu have to be running as the same user when you try to reattach that the session was started as (you can technically reattach to other users sessions, but it's a bit more complicated).
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
1
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually usescreen -xrather thanscreen -ras I often use multiclient sessions and-xis a superset of-rin that it will not fail if there is still ascreenclient attached.)
â DopeGhoti
Nov 6 '17 at 20:11
You don't even have to log in technically, you can also use a tool likesudoto switch to the appropriate UID (though I'm pretty suresuwon't work for this because it doesn't reset the environment properly). If you absolutely can't runscreen -rorscreen -xas that user, you can also prefix the session name with that user's name followed by a/, but I've had issues in the past with that not working reliably.
â Austin Hemmelgarn
Nov 6 '17 at 20:19
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
GNU Screen or TMUX are probably your best options. The general concept of both is pretty similar to a tabbed window manager, but they're both for terminal usage, and you can detach from a session and re-attach later. I'm not quite certain about the syntax needed for TMUX, but for screen the command you want is:
screen -D -n -s <name> <command>
Replace <name> with the name of the session, and <command> with the command to run. YOu can then re-attach to the session with:
screen -D -r <name>
The only caveat is that yuu have to be running as the same user when you try to reattach that the session was started as (you can technically reattach to other users sessions, but it's a bit more complicated).
GNU Screen or TMUX are probably your best options. The general concept of both is pretty similar to a tabbed window manager, but they're both for terminal usage, and you can detach from a session and re-attach later. I'm not quite certain about the syntax needed for TMUX, but for screen the command you want is:
screen -D -n -s <name> <command>
Replace <name> with the name of the session, and <command> with the command to run. YOu can then re-attach to the session with:
screen -D -r <name>
The only caveat is that yuu have to be running as the same user when you try to reattach that the session was started as (you can technically reattach to other users sessions, but it's a bit more complicated).
answered Nov 6 '17 at 19:54
Austin Hemmelgarn
5,1741915
5,1741915
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
1
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually usescreen -xrather thanscreen -ras I often use multiclient sessions and-xis a superset of-rin that it will not fail if there is still ascreenclient attached.)
â DopeGhoti
Nov 6 '17 at 20:11
You don't even have to log in technically, you can also use a tool likesudoto switch to the appropriate UID (though I'm pretty suresuwon't work for this because it doesn't reset the environment properly). If you absolutely can't runscreen -rorscreen -xas that user, you can also prefix the session name with that user's name followed by a/, but I've had issues in the past with that not working reliably.
â Austin Hemmelgarn
Nov 6 '17 at 20:19
add a comment |Â
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
1
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually usescreen -xrather thanscreen -ras I often use multiclient sessions and-xis a superset of-rin that it will not fail if there is still ascreenclient attached.)
â DopeGhoti
Nov 6 '17 at 20:11
You don't even have to log in technically, you can also use a tool likesudoto switch to the appropriate UID (though I'm pretty suresuwon't work for this because it doesn't reset the environment properly). If you absolutely can't runscreen -rorscreen -xas that user, you can also prefix the session name with that user's name followed by a/, but I've had issues in the past with that not working reliably.
â Austin Hemmelgarn
Nov 6 '17 at 20:19
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
hmmmm, so if it runs in a cron job it will not run as "me" so when I reattach I'd have to do the "more complicated" method. Thanks for the help, I'll test. You don't want to leave some more complicated help with the reattach do you?
â Marshal Tucker
Nov 6 '17 at 19:59
1
1
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually use
screen -x rather than screen -r as I often use multiclient sessions and -x is a superset of -r in that it will not fail if there is still a screen client attached.)â DopeGhoti
Nov 6 '17 at 20:11
Simply log in as the user who owns the cron job and run the same command to reattach. (n. b. I usually use
screen -x rather than screen -r as I often use multiclient sessions and -x is a superset of -r in that it will not fail if there is still a screen client attached.)â DopeGhoti
Nov 6 '17 at 20:11
You don't even have to log in technically, you can also use a tool like
sudo to switch to the appropriate UID (though I'm pretty sure su won't work for this because it doesn't reset the environment properly). If you absolutely can't run screen -r or screen -x as that user, you can also prefix the session name with that user's name followed by a /, but I've had issues in the past with that not working reliably.â Austin Hemmelgarn
Nov 6 '17 at 20:19
You don't even have to log in technically, you can also use a tool like
sudo to switch to the appropriate UID (though I'm pretty sure su won't work for this because it doesn't reset the environment properly). If you absolutely can't run screen -r or screen -x as that user, you can also prefix the session name with that user's name followed by a /, but I've had issues in the past with that not working reliably.â Austin Hemmelgarn
Nov 6 '17 at 20:19
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402900%2fusing-session-command-from-a-cron-job-linux%23new-answer', 'question_page');
);
Post as a guest
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
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
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