How to execute shell script via crontab?
I have a notify.sh
script that looks like:
notify-send "hi welcome"
My crontab notification for 2 PM:
0 14 * * * home/hacks/notify.sh
However, this doesn't work. What is the problem?
linux crontab
add a comment |
I have a notify.sh
script that looks like:
notify-send "hi welcome"
My crontab notification for 2 PM:
0 14 * * * home/hacks/notify.sh
However, this doesn't work. What is the problem?
linux crontab
add a comment |
I have a notify.sh
script that looks like:
notify-send "hi welcome"
My crontab notification for 2 PM:
0 14 * * * home/hacks/notify.sh
However, this doesn't work. What is the problem?
linux crontab
I have a notify.sh
script that looks like:
notify-send "hi welcome"
My crontab notification for 2 PM:
0 14 * * * home/hacks/notify.sh
However, this doesn't work. What is the problem?
linux crontab
linux crontab
edited Jan 24 '13 at 20:24
slhck
160k47445467
160k47445467
asked Dec 10 '09 at 8:38
AravindAravind
291138
291138
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
Your script is missing a #! line at the start, which is the magic interpreted by the kernel to say which command interpreter is to be used for the script.
Make it look like this:
#!/bin/sh
notify-send "hi welcome"
and make sure the script is executable:
ls -l home/hacks/notify.sh
chmod +x home/hacks/notify.sh
ls -l home/hacks/notify.sh
Also, since you're asking for this to happen just once a day, is the timezone of the crontab the same as your own timezone? You might find this happening at 2pm GMT.
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
add a comment |
Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.
*/1 * * * * cd /home/hacks && sh notify.sh
To make the script executable, we have to do:
chmod +x home/hacks/notify.sh
Here i run this script for every one minute ...
By doing below script, you can write it in a log file to find whether its working
write log
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log
send mail
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" user@domain.com
2
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
add a comment |
4 hypothesis:
the cron daemon is not running (do a
ps axfww | grep cron
and check)the notify-send is trying to send output to a terminal, or an X session -- but it is ran from within the
cron
environment and it does not know "who to talk to", so to speak.your script is not executable
the
home/
path in the crontab script is relative to the user the scripts gets executed as. Try using the full path
add a comment |
Add export DISPLAY=:0
above the notify-send line in your script. This addresses lornezog's second point.
add a comment |
You have to open crontab by the following command:
crontab -u username -e (to edit) -l(to list) -r(to remove) 10(minutes) 8-15(hours) *(Day of month) *(month) 1,3,5(days of week) /path/to/script/script_name.sh
This will run your script once an hour from 8AM-3PM at 10 minutes past the hour every Monday, Wednesday and Friday.
add a comment |
First of All, we need to edit the crontab with Command crontab -e
and than Inside this Crontab
add the Path of Executable script and in your Case like this
* 14 * * * home/hacks/notify.sh >/dev/null 2>&1
.
Start /Stop / restart cron service
/etc/init.d/crond start /stop / restart
service crond start /stop /restart
systemctl stop crond.service
systemctl stop crond.service
add a comment |
quite simple, add following line at bottom of the crontab file via:
sudo nano /etc/crontab
@reboot root cd /home/pi/node-sonos-http-api && npm start &
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
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%2f81262%2fhow-to-execute-shell-script-via-crontab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your script is missing a #! line at the start, which is the magic interpreted by the kernel to say which command interpreter is to be used for the script.
Make it look like this:
#!/bin/sh
notify-send "hi welcome"
and make sure the script is executable:
ls -l home/hacks/notify.sh
chmod +x home/hacks/notify.sh
ls -l home/hacks/notify.sh
Also, since you're asking for this to happen just once a day, is the timezone of the crontab the same as your own timezone? You might find this happening at 2pm GMT.
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
add a comment |
Your script is missing a #! line at the start, which is the magic interpreted by the kernel to say which command interpreter is to be used for the script.
Make it look like this:
#!/bin/sh
notify-send "hi welcome"
and make sure the script is executable:
ls -l home/hacks/notify.sh
chmod +x home/hacks/notify.sh
ls -l home/hacks/notify.sh
Also, since you're asking for this to happen just once a day, is the timezone of the crontab the same as your own timezone? You might find this happening at 2pm GMT.
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
add a comment |
Your script is missing a #! line at the start, which is the magic interpreted by the kernel to say which command interpreter is to be used for the script.
Make it look like this:
#!/bin/sh
notify-send "hi welcome"
and make sure the script is executable:
ls -l home/hacks/notify.sh
chmod +x home/hacks/notify.sh
ls -l home/hacks/notify.sh
Also, since you're asking for this to happen just once a day, is the timezone of the crontab the same as your own timezone? You might find this happening at 2pm GMT.
Your script is missing a #! line at the start, which is the magic interpreted by the kernel to say which command interpreter is to be used for the script.
Make it look like this:
#!/bin/sh
notify-send "hi welcome"
and make sure the script is executable:
ls -l home/hacks/notify.sh
chmod +x home/hacks/notify.sh
ls -l home/hacks/notify.sh
Also, since you're asking for this to happen just once a day, is the timezone of the crontab the same as your own timezone? You might find this happening at 2pm GMT.
answered Dec 10 '09 at 9:04
Phil PPhil P
1,75397
1,75397
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
add a comment |
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
+1 This answer is awesome - particularly noting the point about the script needs to being executable! Thanks!
– FXQuantTrader
Jan 9 '15 at 6:10
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
Very subtle explanation. My upvote
– Fokwa Best
Oct 24 '16 at 12:58
add a comment |
Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.
*/1 * * * * cd /home/hacks && sh notify.sh
To make the script executable, we have to do:
chmod +x home/hacks/notify.sh
Here i run this script for every one minute ...
By doing below script, you can write it in a log file to find whether its working
write log
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log
send mail
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" user@domain.com
2
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
add a comment |
Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.
*/1 * * * * cd /home/hacks && sh notify.sh
To make the script executable, we have to do:
chmod +x home/hacks/notify.sh
Here i run this script for every one minute ...
By doing below script, you can write it in a log file to find whether its working
write log
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log
send mail
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" user@domain.com
2
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
add a comment |
Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.
*/1 * * * * cd /home/hacks && sh notify.sh
To make the script executable, we have to do:
chmod +x home/hacks/notify.sh
Here i run this script for every one minute ...
By doing below script, you can write it in a log file to find whether its working
write log
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log
send mail
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" user@domain.com
Making crontab running is easy only . Here I am going to say how to run crontab jobs. It is useful for anyone who is stuck on crontab.
*/1 * * * * cd /home/hacks && sh notify.sh
To make the script executable, we have to do:
chmod +x home/hacks/notify.sh
Here i run this script for every one minute ...
By doing below script, you can write it in a log file to find whether its working
write log
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log
send mail
*/1 * * * * cd /home/hacks && sh notify.sh>>test.log | mail -s "Hi this is example" user@domain.com
edited Dec 28 '12 at 16:35
Community♦
1
1
answered Mar 25 '10 at 6:05
AravindAravind
291138
291138
2
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
add a comment |
2
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
2
2
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
isnt that "*/1 * * * * sh /home/hacks/notify.sh" will also work ?
– user1179459
Sep 25 '15 at 1:14
add a comment |
4 hypothesis:
the cron daemon is not running (do a
ps axfww | grep cron
and check)the notify-send is trying to send output to a terminal, or an X session -- but it is ran from within the
cron
environment and it does not know "who to talk to", so to speak.your script is not executable
the
home/
path in the crontab script is relative to the user the scripts gets executed as. Try using the full path
add a comment |
4 hypothesis:
the cron daemon is not running (do a
ps axfww | grep cron
and check)the notify-send is trying to send output to a terminal, or an X session -- but it is ran from within the
cron
environment and it does not know "who to talk to", so to speak.your script is not executable
the
home/
path in the crontab script is relative to the user the scripts gets executed as. Try using the full path
add a comment |
4 hypothesis:
the cron daemon is not running (do a
ps axfww | grep cron
and check)the notify-send is trying to send output to a terminal, or an X session -- but it is ran from within the
cron
environment and it does not know "who to talk to", so to speak.your script is not executable
the
home/
path in the crontab script is relative to the user the scripts gets executed as. Try using the full path
4 hypothesis:
the cron daemon is not running (do a
ps axfww | grep cron
and check)the notify-send is trying to send output to a terminal, or an X session -- but it is ran from within the
cron
environment and it does not know "who to talk to", so to speak.your script is not executable
the
home/
path in the crontab script is relative to the user the scripts gets executed as. Try using the full path
edited Dec 10 '09 at 10:16
answered Dec 10 '09 at 8:42
lorenzoglorenzog
1,62711223
1,62711223
add a comment |
add a comment |
Add export DISPLAY=:0
above the notify-send line in your script. This addresses lornezog's second point.
add a comment |
Add export DISPLAY=:0
above the notify-send line in your script. This addresses lornezog's second point.
add a comment |
Add export DISPLAY=:0
above the notify-send line in your script. This addresses lornezog's second point.
Add export DISPLAY=:0
above the notify-send line in your script. This addresses lornezog's second point.
answered Mar 11 '12 at 0:33
W_WhalleyW_Whalley
3,06711115
3,06711115
add a comment |
add a comment |
You have to open crontab by the following command:
crontab -u username -e (to edit) -l(to list) -r(to remove) 10(minutes) 8-15(hours) *(Day of month) *(month) 1,3,5(days of week) /path/to/script/script_name.sh
This will run your script once an hour from 8AM-3PM at 10 minutes past the hour every Monday, Wednesday and Friday.
add a comment |
You have to open crontab by the following command:
crontab -u username -e (to edit) -l(to list) -r(to remove) 10(minutes) 8-15(hours) *(Day of month) *(month) 1,3,5(days of week) /path/to/script/script_name.sh
This will run your script once an hour from 8AM-3PM at 10 minutes past the hour every Monday, Wednesday and Friday.
add a comment |
You have to open crontab by the following command:
crontab -u username -e (to edit) -l(to list) -r(to remove) 10(minutes) 8-15(hours) *(Day of month) *(month) 1,3,5(days of week) /path/to/script/script_name.sh
This will run your script once an hour from 8AM-3PM at 10 minutes past the hour every Monday, Wednesday and Friday.
You have to open crontab by the following command:
crontab -u username -e (to edit) -l(to list) -r(to remove) 10(minutes) 8-15(hours) *(Day of month) *(month) 1,3,5(days of week) /path/to/script/script_name.sh
This will run your script once an hour from 8AM-3PM at 10 minutes past the hour every Monday, Wednesday and Friday.
edited Jul 9 '11 at 1:47
3498DB
15.7k114762
15.7k114762
answered Dec 10 '09 at 10:00
ravindrakhokharia
add a comment |
add a comment |
First of All, we need to edit the crontab with Command crontab -e
and than Inside this Crontab
add the Path of Executable script and in your Case like this
* 14 * * * home/hacks/notify.sh >/dev/null 2>&1
.
Start /Stop / restart cron service
/etc/init.d/crond start /stop / restart
service crond start /stop /restart
systemctl stop crond.service
systemctl stop crond.service
add a comment |
First of All, we need to edit the crontab with Command crontab -e
and than Inside this Crontab
add the Path of Executable script and in your Case like this
* 14 * * * home/hacks/notify.sh >/dev/null 2>&1
.
Start /Stop / restart cron service
/etc/init.d/crond start /stop / restart
service crond start /stop /restart
systemctl stop crond.service
systemctl stop crond.service
add a comment |
First of All, we need to edit the crontab with Command crontab -e
and than Inside this Crontab
add the Path of Executable script and in your Case like this
* 14 * * * home/hacks/notify.sh >/dev/null 2>&1
.
Start /Stop / restart cron service
/etc/init.d/crond start /stop / restart
service crond start /stop /restart
systemctl stop crond.service
systemctl stop crond.service
First of All, we need to edit the crontab with Command crontab -e
and than Inside this Crontab
add the Path of Executable script and in your Case like this
* 14 * * * home/hacks/notify.sh >/dev/null 2>&1
.
Start /Stop / restart cron service
/etc/init.d/crond start /stop / restart
service crond start /stop /restart
systemctl stop crond.service
systemctl stop crond.service
answered Oct 24 '15 at 12:00
kunalkunal
13
13
add a comment |
add a comment |
quite simple, add following line at bottom of the crontab file via:
sudo nano /etc/crontab
@reboot root cd /home/pi/node-sonos-http-api && npm start &
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
add a comment |
quite simple, add following line at bottom of the crontab file via:
sudo nano /etc/crontab
@reboot root cd /home/pi/node-sonos-http-api && npm start &
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
add a comment |
quite simple, add following line at bottom of the crontab file via:
sudo nano /etc/crontab
@reboot root cd /home/pi/node-sonos-http-api && npm start &
quite simple, add following line at bottom of the crontab file via:
sudo nano /etc/crontab
@reboot root cd /home/pi/node-sonos-http-api && npm start &
edited Dec 28 '18 at 16:32
Mureinik
2,54561625
2,54561625
answered Dec 28 '18 at 16:01
Martini7Martini7
1
1
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
add a comment |
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
This does not seem to be an answer to the question.
– Ljm Dullaart
Dec 28 '18 at 19:00
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%2f81262%2fhow-to-execute-shell-script-via-crontab%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