How to lock my Ubuntu for a specific amount of time
#!/bin/bash
for i in {1..10}; do
timeout 1 gnome-screensaver-command -l
done
Running this as a one-line command in the terminal (without #!/bin/bash
) will keep locking my pc for 10 seconds, and unlocking it is impossible. This is desired.
However, when I run this via script, it only locks it once, but after that I can immediately unlock and use the pc. Please help me.. I want to automate it and use it as a cron job. How to make it work?
This is all I have in my cron file:
1 * * * * for i in {1..5}; do timeout --foreground 1 gnome-screensaver-command -l; done > test
It won't even run the job. No test file appears. When I run service cron status
, no job is run recently, even though I commanded it to run the script every minute..
ubuntu bash
add a comment |
#!/bin/bash
for i in {1..10}; do
timeout 1 gnome-screensaver-command -l
done
Running this as a one-line command in the terminal (without #!/bin/bash
) will keep locking my pc for 10 seconds, and unlocking it is impossible. This is desired.
However, when I run this via script, it only locks it once, but after that I can immediately unlock and use the pc. Please help me.. I want to automate it and use it as a cron job. How to make it work?
This is all I have in my cron file:
1 * * * * for i in {1..5}; do timeout --foreground 1 gnome-screensaver-command -l; done > test
It won't even run the job. No test file appears. When I run service cron status
, no job is run recently, even though I commanded it to run the script every minute..
ubuntu bash
add a comment |
#!/bin/bash
for i in {1..10}; do
timeout 1 gnome-screensaver-command -l
done
Running this as a one-line command in the terminal (without #!/bin/bash
) will keep locking my pc for 10 seconds, and unlocking it is impossible. This is desired.
However, when I run this via script, it only locks it once, but after that I can immediately unlock and use the pc. Please help me.. I want to automate it and use it as a cron job. How to make it work?
This is all I have in my cron file:
1 * * * * for i in {1..5}; do timeout --foreground 1 gnome-screensaver-command -l; done > test
It won't even run the job. No test file appears. When I run service cron status
, no job is run recently, even though I commanded it to run the script every minute..
ubuntu bash
#!/bin/bash
for i in {1..10}; do
timeout 1 gnome-screensaver-command -l
done
Running this as a one-line command in the terminal (without #!/bin/bash
) will keep locking my pc for 10 seconds, and unlocking it is impossible. This is desired.
However, when I run this via script, it only locks it once, but after that I can immediately unlock and use the pc. Please help me.. I want to automate it and use it as a cron job. How to make it work?
This is all I have in my cron file:
1 * * * * for i in {1..5}; do timeout --foreground 1 gnome-screensaver-command -l; done > test
It won't even run the job. No test file appears. When I run service cron status
, no job is run recently, even though I commanded it to run the script every minute..
ubuntu bash
ubuntu bash
edited Jan 11 at 12:35
MyWays
asked Jan 10 at 2:12
MyWaysMyWays
225
225
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
A bigger question is why are you running the command 10 times for 1 second, instead of 1 time for 10 seconds? You wouldn't even need the loop then. If it's to stop someone else from entering the password and unlocking the computer, maybe you should just change the password and keep it to yourself.
There's software to help manage time, you might want to try one, like Pomodoro:
This GNOME app helps to manage time according to Pomodoro Technique. It intends to improve productivity and quality of work by reminding you to take short breaks.
Pomodoro Technique is based on two principles:
- focusing on work for limited time, about half an hour,
- clearing your mind during breaks.
This workflow can improve focus, physical health and mental agility depending on how you spend your breaks and how strictly you follow the routine.
See this question on askubuntu Is there a Pomodoro app available?, it also recommends tomate among others.
If you wanted to "stop" a particular program for a while, you could use kill -STOP pid
, or pkill -STOP pattern
, as in
kill -STOP pid
sleep $seconds
kill -CONT pid
Stopping whatever program you want to take a break from would let the rest of the system keep working. I wouldn't really want to try stopping something more major, like the window manager or X/xorg.
Cron doesn't behave exactly like your regular user's terminal does, it might not even know where some commands are. You could try:
Running the command as your user, via
sudo -u [YourUser] command
(see man sudo for more info on-u
).Add the full path to the command (found via
which [command]
or searching the package's installed files withdpkg
or apt/synaptic, etc.
Sounds like timeout
behaves differently when it's run in an interactive terminal, vs in a script. Reading it's info page reveals an option I think you could use:
‘--foreground’
Don’t create a separate background program group, so that the
managed COMMAND can use the foreground TTY normally. This is
needed to support timing out commands not started directly from an
interactive shell, in two situations.
- COMMAND is interactive and needs to read from the terminal for
example
the user wants to support sending signals directly to COMMAND
from the terminal (like Ctrl-C for example)
Note in this mode of operation, any children of COMMAND will not be
timed out. Also SIGCONT will not be sent to COMMAND, as it’s
generally not needed with foreground processes, and can cause
intermittent signal delivery issues with programs that are monitors
themselves (like GDB for example).
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1392543%2fhow-to-lock-my-ubuntu-for-a-specific-amount-of-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A bigger question is why are you running the command 10 times for 1 second, instead of 1 time for 10 seconds? You wouldn't even need the loop then. If it's to stop someone else from entering the password and unlocking the computer, maybe you should just change the password and keep it to yourself.
There's software to help manage time, you might want to try one, like Pomodoro:
This GNOME app helps to manage time according to Pomodoro Technique. It intends to improve productivity and quality of work by reminding you to take short breaks.
Pomodoro Technique is based on two principles:
- focusing on work for limited time, about half an hour,
- clearing your mind during breaks.
This workflow can improve focus, physical health and mental agility depending on how you spend your breaks and how strictly you follow the routine.
See this question on askubuntu Is there a Pomodoro app available?, it also recommends tomate among others.
If you wanted to "stop" a particular program for a while, you could use kill -STOP pid
, or pkill -STOP pattern
, as in
kill -STOP pid
sleep $seconds
kill -CONT pid
Stopping whatever program you want to take a break from would let the rest of the system keep working. I wouldn't really want to try stopping something more major, like the window manager or X/xorg.
Cron doesn't behave exactly like your regular user's terminal does, it might not even know where some commands are. You could try:
Running the command as your user, via
sudo -u [YourUser] command
(see man sudo for more info on-u
).Add the full path to the command (found via
which [command]
or searching the package's installed files withdpkg
or apt/synaptic, etc.
Sounds like timeout
behaves differently when it's run in an interactive terminal, vs in a script. Reading it's info page reveals an option I think you could use:
‘--foreground’
Don’t create a separate background program group, so that the
managed COMMAND can use the foreground TTY normally. This is
needed to support timing out commands not started directly from an
interactive shell, in two situations.
- COMMAND is interactive and needs to read from the terminal for
example
the user wants to support sending signals directly to COMMAND
from the terminal (like Ctrl-C for example)
Note in this mode of operation, any children of COMMAND will not be
timed out. Also SIGCONT will not be sent to COMMAND, as it’s
generally not needed with foreground processes, and can cause
intermittent signal delivery issues with programs that are monitors
themselves (like GDB for example).
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
add a comment |
A bigger question is why are you running the command 10 times for 1 second, instead of 1 time for 10 seconds? You wouldn't even need the loop then. If it's to stop someone else from entering the password and unlocking the computer, maybe you should just change the password and keep it to yourself.
There's software to help manage time, you might want to try one, like Pomodoro:
This GNOME app helps to manage time according to Pomodoro Technique. It intends to improve productivity and quality of work by reminding you to take short breaks.
Pomodoro Technique is based on two principles:
- focusing on work for limited time, about half an hour,
- clearing your mind during breaks.
This workflow can improve focus, physical health and mental agility depending on how you spend your breaks and how strictly you follow the routine.
See this question on askubuntu Is there a Pomodoro app available?, it also recommends tomate among others.
If you wanted to "stop" a particular program for a while, you could use kill -STOP pid
, or pkill -STOP pattern
, as in
kill -STOP pid
sleep $seconds
kill -CONT pid
Stopping whatever program you want to take a break from would let the rest of the system keep working. I wouldn't really want to try stopping something more major, like the window manager or X/xorg.
Cron doesn't behave exactly like your regular user's terminal does, it might not even know where some commands are. You could try:
Running the command as your user, via
sudo -u [YourUser] command
(see man sudo for more info on-u
).Add the full path to the command (found via
which [command]
or searching the package's installed files withdpkg
or apt/synaptic, etc.
Sounds like timeout
behaves differently when it's run in an interactive terminal, vs in a script. Reading it's info page reveals an option I think you could use:
‘--foreground’
Don’t create a separate background program group, so that the
managed COMMAND can use the foreground TTY normally. This is
needed to support timing out commands not started directly from an
interactive shell, in two situations.
- COMMAND is interactive and needs to read from the terminal for
example
the user wants to support sending signals directly to COMMAND
from the terminal (like Ctrl-C for example)
Note in this mode of operation, any children of COMMAND will not be
timed out. Also SIGCONT will not be sent to COMMAND, as it’s
generally not needed with foreground processes, and can cause
intermittent signal delivery issues with programs that are monitors
themselves (like GDB for example).
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
add a comment |
A bigger question is why are you running the command 10 times for 1 second, instead of 1 time for 10 seconds? You wouldn't even need the loop then. If it's to stop someone else from entering the password and unlocking the computer, maybe you should just change the password and keep it to yourself.
There's software to help manage time, you might want to try one, like Pomodoro:
This GNOME app helps to manage time according to Pomodoro Technique. It intends to improve productivity and quality of work by reminding you to take short breaks.
Pomodoro Technique is based on two principles:
- focusing on work for limited time, about half an hour,
- clearing your mind during breaks.
This workflow can improve focus, physical health and mental agility depending on how you spend your breaks and how strictly you follow the routine.
See this question on askubuntu Is there a Pomodoro app available?, it also recommends tomate among others.
If you wanted to "stop" a particular program for a while, you could use kill -STOP pid
, or pkill -STOP pattern
, as in
kill -STOP pid
sleep $seconds
kill -CONT pid
Stopping whatever program you want to take a break from would let the rest of the system keep working. I wouldn't really want to try stopping something more major, like the window manager or X/xorg.
Cron doesn't behave exactly like your regular user's terminal does, it might not even know where some commands are. You could try:
Running the command as your user, via
sudo -u [YourUser] command
(see man sudo for more info on-u
).Add the full path to the command (found via
which [command]
or searching the package's installed files withdpkg
or apt/synaptic, etc.
Sounds like timeout
behaves differently when it's run in an interactive terminal, vs in a script. Reading it's info page reveals an option I think you could use:
‘--foreground’
Don’t create a separate background program group, so that the
managed COMMAND can use the foreground TTY normally. This is
needed to support timing out commands not started directly from an
interactive shell, in two situations.
- COMMAND is interactive and needs to read from the terminal for
example
the user wants to support sending signals directly to COMMAND
from the terminal (like Ctrl-C for example)
Note in this mode of operation, any children of COMMAND will not be
timed out. Also SIGCONT will not be sent to COMMAND, as it’s
generally not needed with foreground processes, and can cause
intermittent signal delivery issues with programs that are monitors
themselves (like GDB for example).
A bigger question is why are you running the command 10 times for 1 second, instead of 1 time for 10 seconds? You wouldn't even need the loop then. If it's to stop someone else from entering the password and unlocking the computer, maybe you should just change the password and keep it to yourself.
There's software to help manage time, you might want to try one, like Pomodoro:
This GNOME app helps to manage time according to Pomodoro Technique. It intends to improve productivity and quality of work by reminding you to take short breaks.
Pomodoro Technique is based on two principles:
- focusing on work for limited time, about half an hour,
- clearing your mind during breaks.
This workflow can improve focus, physical health and mental agility depending on how you spend your breaks and how strictly you follow the routine.
See this question on askubuntu Is there a Pomodoro app available?, it also recommends tomate among others.
If you wanted to "stop" a particular program for a while, you could use kill -STOP pid
, or pkill -STOP pattern
, as in
kill -STOP pid
sleep $seconds
kill -CONT pid
Stopping whatever program you want to take a break from would let the rest of the system keep working. I wouldn't really want to try stopping something more major, like the window manager or X/xorg.
Cron doesn't behave exactly like your regular user's terminal does, it might not even know where some commands are. You could try:
Running the command as your user, via
sudo -u [YourUser] command
(see man sudo for more info on-u
).Add the full path to the command (found via
which [command]
or searching the package's installed files withdpkg
or apt/synaptic, etc.
Sounds like timeout
behaves differently when it's run in an interactive terminal, vs in a script. Reading it's info page reveals an option I think you could use:
‘--foreground’
Don’t create a separate background program group, so that the
managed COMMAND can use the foreground TTY normally. This is
needed to support timing out commands not started directly from an
interactive shell, in two situations.
- COMMAND is interactive and needs to read from the terminal for
example
the user wants to support sending signals directly to COMMAND
from the terminal (like Ctrl-C for example)
Note in this mode of operation, any children of COMMAND will not be
timed out. Also SIGCONT will not be sent to COMMAND, as it’s
generally not needed with foreground processes, and can cause
intermittent signal delivery issues with programs that are monitors
themselves (like GDB for example).
edited Jan 14 at 23:13
answered Jan 10 at 11:16
Xen2050Xen2050
10.9k31536
10.9k31536
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
add a comment |
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
It doesnt work. Ive updated my question with my cron file. Also, the script is for productivity. Blocking access to the pc so I can take a break. I can change 10secs to 5min if I want to.
– MyWays
Jan 11 at 12:23
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
I've added some other ideas... but just voluntarily standing up and taking a break might be the easiest, or are you trying to force someone to take an unwilling break?
– Xen2050
Jan 14 at 23:00
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
"The script is for productivity. Blocking access to the pc so I can take a break" Consider a quiet, gentle, physical timer. I'd say "egg timer" but those are pretty harsh.
– Christopher Hostage
Jan 14 at 23:19
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
@ChristopherHostage That's exactly what Wikipedia suggests on the linked Pomodoro technique page, "The physical act of winding the timer confirms the user's determination to start the task; ticking externalises desire to complete the task; ringing announces a break. Flow and focus become associated with these physical stimuli." I wouldn't want a loud fire-alarm heard-from-outside bell either, but a nice quiet musical one might be nice. This is SuperUser after all, and any sound clip could be used...
– Xen2050
Jan 14 at 23:29
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1392543%2fhow-to-lock-my-ubuntu-for-a-specific-amount-of-time%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