Crontab: Ubuntu running script (noob)Where is the user crontab stored?How do I create a script file for...
What is the difference between rolling more dice versus fewer dice?
Is this ordinary workplace experiences for a job in Software Engineering?
Should I reinstall Linux when changing the laptop's CPU?
Constexpr if with a non-bool condition
Why did Luke use his left hand to shoot?
How can a large fleets maintain formation in interstellar space?
Why do cars have plastic shrouds over the engine?
Avoid page break between paragraphs
A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?
What to look for when criticizing poetry?
A curious equality of integrals involving the prime counting function?
Is there any risk in sharing info about technologies and products we use with a supplier?
Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?
"on its way" vs. "in its way"
In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?
Salsa20 Implementation: Sum of 2 Words with Carries Suppressed
Citing paywalled articles accessed via illegal web sharing
Play Zip, Zap, Zop
Do "fields" always combine by addition?
Identify KNO3 and KH2PO4 at home
Move fast ...... Or you will lose
Am I a Rude Number?
Is using an 'empty' metaphor considered bad style?
How do you voice extended chords?
Crontab: Ubuntu running script (noob)
Where is the user crontab stored?How do I create a script file for terminal commands?What is the correct way to edit a crontab file?Cannot run bash script from crontab when it works from command line bashBash script not working properly from crontabHelp, ubuntu server 14.04 crontab cannot run my database backup script, but other simple script is okCrontab says command not foundCrontab working but root crontab doesn'tDifficulties running script at startuproot's crontab job not workingRunning pgrep in a crontabPATH issue with Cron - Not running bash/python scriptScript works manually, but not when called by Cron
I'm new to crontab and would like to run the following script from /etc/crontab
:
0 15 * * * root bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
I have tried with and without bash-c
option, yet the script doesn't run.
My objective is:
- Get this script running from Crontab
- Get this script running on startup
Help is appreciated.
bash scripts cron
New contributor
add a comment |
I'm new to crontab and would like to run the following script from /etc/crontab
:
0 15 * * * root bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
I have tried with and without bash-c
option, yet the script doesn't run.
My objective is:
- Get this script running from Crontab
- Get this script running on startup
Help is appreciated.
bash scripts cron
New contributor
1
Consider putting this in your user crontab (i.e.crontab -e
as userdell
) instead of in the system crontab as root.
– marcelm
47 mins ago
add a comment |
I'm new to crontab and would like to run the following script from /etc/crontab
:
0 15 * * * root bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
I have tried with and without bash-c
option, yet the script doesn't run.
My objective is:
- Get this script running from Crontab
- Get this script running on startup
Help is appreciated.
bash scripts cron
New contributor
I'm new to crontab and would like to run the following script from /etc/crontab
:
0 15 * * * root bash-c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
I have tried with and without bash-c
option, yet the script doesn't run.
My objective is:
- Get this script running from Crontab
- Get this script running on startup
Help is appreciated.
bash scripts cron
bash scripts cron
New contributor
New contributor
edited 7 hours ago
dessert
24.1k670104
24.1k670104
New contributor
asked 7 hours ago
orrporrp
212
212
New contributor
New contributor
1
Consider putting this in your user crontab (i.e.crontab -e
as userdell
) instead of in the system crontab as root.
– marcelm
47 mins ago
add a comment |
1
Consider putting this in your user crontab (i.e.crontab -e
as userdell
) instead of in the system crontab as root.
– marcelm
47 mins ago
1
1
Consider putting this in your user crontab (i.e.
crontab -e
as user dell
) instead of in the system crontab as root.– marcelm
47 mins ago
Consider putting this in your user crontab (i.e.
crontab -e
as user dell
) instead of in the system crontab as root.– marcelm
47 mins ago
add a comment |
1 Answer
1
active
oldest
votes
You're missing a space after the command bash
and the argument -c
.
This should work:
0 15 * * * root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
Some additional hints:
- Don't run a
crontab
as userroot
if you don't need to. - You wrote that you put it in
/etc/crontab
file. Don't edit crontab files directly, rather usecrontab -e
command orsudo crontab -e
for commands which needroot
rights. Note, that you don't put theuser
field in the "other"crontab
files. If you have more than one command you can use
bash -c
as you do, but I'd rather put the commands in a script and execute this from crontab.To run a script on startup, you can use
@reboot
instead of0 15 * * *
.
5
“I'm not sure what the word root is about here.” See the header of/etc/crontab
: Unlike any other crontab you don't have to run thecrontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, soroot
should be not used in this case.
– Melebius
6 hours ago
1
thanks, as I never edited/etc/crontab
directly I didn't even know this... :-D
– RoVo
6 hours ago
2
See also Two Other Types of Crontab
– steeldriver
6 hours ago
1
I suspect there may be a more fundamental issue with running abash -c
command from cron, since IIRC each command is implicitly executed by/bin/sh -c
(or, more exactly,$SHELL -c
). It may be necessary to setSHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without thebash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.
– steeldriver
5 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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
});
}
});
orrp is a new contributor. Be nice, and check out our Code of Conduct.
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%2faskubuntu.com%2fquestions%2f1121615%2fcrontab-ubuntu-running-script-noob%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
You're missing a space after the command bash
and the argument -c
.
This should work:
0 15 * * * root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
Some additional hints:
- Don't run a
crontab
as userroot
if you don't need to. - You wrote that you put it in
/etc/crontab
file. Don't edit crontab files directly, rather usecrontab -e
command orsudo crontab -e
for commands which needroot
rights. Note, that you don't put theuser
field in the "other"crontab
files. If you have more than one command you can use
bash -c
as you do, but I'd rather put the commands in a script and execute this from crontab.To run a script on startup, you can use
@reboot
instead of0 15 * * *
.
5
“I'm not sure what the word root is about here.” See the header of/etc/crontab
: Unlike any other crontab you don't have to run thecrontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, soroot
should be not used in this case.
– Melebius
6 hours ago
1
thanks, as I never edited/etc/crontab
directly I didn't even know this... :-D
– RoVo
6 hours ago
2
See also Two Other Types of Crontab
– steeldriver
6 hours ago
1
I suspect there may be a more fundamental issue with running abash -c
command from cron, since IIRC each command is implicitly executed by/bin/sh -c
(or, more exactly,$SHELL -c
). It may be necessary to setSHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without thebash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.
– steeldriver
5 hours ago
add a comment |
You're missing a space after the command bash
and the argument -c
.
This should work:
0 15 * * * root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
Some additional hints:
- Don't run a
crontab
as userroot
if you don't need to. - You wrote that you put it in
/etc/crontab
file. Don't edit crontab files directly, rather usecrontab -e
command orsudo crontab -e
for commands which needroot
rights. Note, that you don't put theuser
field in the "other"crontab
files. If you have more than one command you can use
bash -c
as you do, but I'd rather put the commands in a script and execute this from crontab.To run a script on startup, you can use
@reboot
instead of0 15 * * *
.
5
“I'm not sure what the word root is about here.” See the header of/etc/crontab
: Unlike any other crontab you don't have to run thecrontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, soroot
should be not used in this case.
– Melebius
6 hours ago
1
thanks, as I never edited/etc/crontab
directly I didn't even know this... :-D
– RoVo
6 hours ago
2
See also Two Other Types of Crontab
– steeldriver
6 hours ago
1
I suspect there may be a more fundamental issue with running abash -c
command from cron, since IIRC each command is implicitly executed by/bin/sh -c
(or, more exactly,$SHELL -c
). It may be necessary to setSHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without thebash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.
– steeldriver
5 hours ago
add a comment |
You're missing a space after the command bash
and the argument -c
.
This should work:
0 15 * * * root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
Some additional hints:
- Don't run a
crontab
as userroot
if you don't need to. - You wrote that you put it in
/etc/crontab
file. Don't edit crontab files directly, rather usecrontab -e
command orsudo crontab -e
for commands which needroot
rights. Note, that you don't put theuser
field in the "other"crontab
files. If you have more than one command you can use
bash -c
as you do, but I'd rather put the commands in a script and execute this from crontab.To run a script on startup, you can use
@reboot
instead of0 15 * * *
.
You're missing a space after the command bash
and the argument -c
.
This should work:
0 15 * * * root bash -c 'for i in /home/dell/Downloads/*.{pdf,docx,png,jpg,PDF,DOCX}; do shred -zvu "$i" -n20; done'
Some additional hints:
- Don't run a
crontab
as userroot
if you don't need to. - You wrote that you put it in
/etc/crontab
file. Don't edit crontab files directly, rather usecrontab -e
command orsudo crontab -e
for commands which needroot
rights. Note, that you don't put theuser
field in the "other"crontab
files. If you have more than one command you can use
bash -c
as you do, but I'd rather put the commands in a script and execute this from crontab.To run a script on startup, you can use
@reboot
instead of0 15 * * *
.
edited 6 hours ago
answered 6 hours ago
RoVoRoVo
7,6541843
7,6541843
5
“I'm not sure what the word root is about here.” See the header of/etc/crontab
: Unlike any other crontab you don't have to run thecrontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, soroot
should be not used in this case.
– Melebius
6 hours ago
1
thanks, as I never edited/etc/crontab
directly I didn't even know this... :-D
– RoVo
6 hours ago
2
See also Two Other Types of Crontab
– steeldriver
6 hours ago
1
I suspect there may be a more fundamental issue with running abash -c
command from cron, since IIRC each command is implicitly executed by/bin/sh -c
(or, more exactly,$SHELL -c
). It may be necessary to setSHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without thebash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.
– steeldriver
5 hours ago
add a comment |
5
“I'm not sure what the word root is about here.” See the header of/etc/crontab
: Unlike any other crontab you don't have to run thecrontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, soroot
should be not used in this case.
– Melebius
6 hours ago
1
thanks, as I never edited/etc/crontab
directly I didn't even know this... :-D
– RoVo
6 hours ago
2
See also Two Other Types of Crontab
– steeldriver
6 hours ago
1
I suspect there may be a more fundamental issue with running abash -c
command from cron, since IIRC each command is implicitly executed by/bin/sh -c
(or, more exactly,$SHELL -c
). It may be necessary to setSHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without thebash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.
– steeldriver
5 hours ago
5
5
“I'm not sure what the word root is about here.” See the header of
/etc/crontab
: Unlike any other crontab you don't have to run the crontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root
should be not used in this case.– Melebius
6 hours ago
“I'm not sure what the word root is about here.” See the header of
/etc/crontab
: Unlike any other crontab you don't have to run the crontab
command to install the new version when you edit this file and files in /etc/cron.d. These files also have username fields, that none of the other crontabs do. However, in this case, only the user’s home folder is involved, so root
should be not used in this case.– Melebius
6 hours ago
1
1
thanks, as I never edited
/etc/crontab
directly I didn't even know this... :-D– RoVo
6 hours ago
thanks, as I never edited
/etc/crontab
directly I didn't even know this... :-D– RoVo
6 hours ago
2
2
See also Two Other Types of Crontab
– steeldriver
6 hours ago
See also Two Other Types of Crontab
– steeldriver
6 hours ago
1
1
I suspect there may be a more fundamental issue with running a
bash -c
command from cron, since IIRC each command is implicitly executed by /bin/sh -c
(or, more exactly, $SHELL -c
). It may be necessary to set SHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without the bash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.– steeldriver
5 hours ago
I suspect there may be a more fundamental issue with running a
bash -c
command from cron, since IIRC each command is implicitly executed by /bin/sh -c
(or, more exactly, $SHELL -c
). It may be necessary to set SHELL=/bin/bash
(to suport brace expansion etc.) and then run the command without the bash -c
wrapper. But really the best approach (as you note) is to put the bash code in an external script file.– steeldriver
5 hours ago
add a comment |
orrp is a new contributor. Be nice, and check out our Code of Conduct.
orrp is a new contributor. Be nice, and check out our Code of Conduct.
orrp is a new contributor. Be nice, and check out our Code of Conduct.
orrp is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1121615%2fcrontab-ubuntu-running-script-noob%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
1
Consider putting this in your user crontab (i.e.
crontab -e
as userdell
) instead of in the system crontab as root.– marcelm
47 mins ago