Cronjob - Script not running on reboot
I need to execute a script, myscript.sh
, at every reboot.
After crontab -e
I wrote:
@reboot /home/techy/Documents/myscript.sh
The file is executable after chmod 777 myscript.sh
, but I'm not able to get output from shell script.
My shell script is supposed to change the desktop background, and is working if executed from terminal.
cron
add a comment |
I need to execute a script, myscript.sh
, at every reboot.
After crontab -e
I wrote:
@reboot /home/techy/Documents/myscript.sh
The file is executable after chmod 777 myscript.sh
, but I'm not able to get output from shell script.
My shell script is supposed to change the desktop background, and is working if executed from terminal.
cron
add a comment |
I need to execute a script, myscript.sh
, at every reboot.
After crontab -e
I wrote:
@reboot /home/techy/Documents/myscript.sh
The file is executable after chmod 777 myscript.sh
, but I'm not able to get output from shell script.
My shell script is supposed to change the desktop background, and is working if executed from terminal.
cron
I need to execute a script, myscript.sh
, at every reboot.
After crontab -e
I wrote:
@reboot /home/techy/Documents/myscript.sh
The file is executable after chmod 777 myscript.sh
, but I'm not able to get output from shell script.
My shell script is supposed to change the desktop background, and is working if executed from terminal.
cron
cron
edited Dec 21 '16 at 22:43
IanC
671615
671615
asked Dec 21 '16 at 22:07
techytechy
3218
3218
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
You cannot do this with @reboot
, (or even cron
). When your @reboot
script runs, you haven't logged in (myscript.sh
is run as root
), the X Server hasn't been started, and the background you want to change doesn't even exist.
I suggest using ~/.config/autostart/
. The files there are .desktop
files, see man desktop-file-validate
, man desktop-file-edit
, man desktop-file-install
, ... . Since the files in my ~/.config/autostart/
put icons on the top of my screen, I think it's the right context/time to "change the desktop background".
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
add a comment |
You want to execute your script at logon, not at boot.
as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder~/.config/autostart/
More information about Gnome Autostart:
Desktop Application Autostart Specification
-1- Create the launcher:
Copy/paste those lines in a terminal
tee -a ~/.config/autostart/myscript.desktop << END1
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec='/home/techy/Documents/myscript.sh'
Name=myscript
END1
chmod +x ~/.config/autostart/myscript.desktop
-2- Start the launcher for the first time, it will ask you to validate
Browse with file manager to ~/.config/autostart/
Double-click on the new created myscript.desktop
file
Validate the security message popup
-3- Done, test it
Log-off then log in back in to see it working
add a comment |
Not sure about the details of your script in myscript.sh
.
If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.
To solve this, you need to put some delay (Example: sleep 5m
) inside your script until internet connection is established successfully.
This method solves my problem, but not sure if this works for you too.
New contributor
add a comment |
I would try this instead.
@reboot sleep 45 && sh /home/techy/Documents/myscript.sh
That gives some time to your boot up, and the sh actually calls the shell script.
You might need to run chmod -x /home/techy/Documents/myscript.sh
this takes restrictions off of the script and path.
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.
So I had to make this crontab magic and realized that the two commands below are very different indeed:
crontab -e
sudo crontab -e
As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write
@reboot /folder/loadhd.sh
Check this:
https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
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
});
}
});
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%2f863240%2fcronjob-script-not-running-on-reboot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You cannot do this with @reboot
, (or even cron
). When your @reboot
script runs, you haven't logged in (myscript.sh
is run as root
), the X Server hasn't been started, and the background you want to change doesn't even exist.
I suggest using ~/.config/autostart/
. The files there are .desktop
files, see man desktop-file-validate
, man desktop-file-edit
, man desktop-file-install
, ... . Since the files in my ~/.config/autostart/
put icons on the top of my screen, I think it's the right context/time to "change the desktop background".
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
add a comment |
You cannot do this with @reboot
, (or even cron
). When your @reboot
script runs, you haven't logged in (myscript.sh
is run as root
), the X Server hasn't been started, and the background you want to change doesn't even exist.
I suggest using ~/.config/autostart/
. The files there are .desktop
files, see man desktop-file-validate
, man desktop-file-edit
, man desktop-file-install
, ... . Since the files in my ~/.config/autostart/
put icons on the top of my screen, I think it's the right context/time to "change the desktop background".
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
add a comment |
You cannot do this with @reboot
, (or even cron
). When your @reboot
script runs, you haven't logged in (myscript.sh
is run as root
), the X Server hasn't been started, and the background you want to change doesn't even exist.
I suggest using ~/.config/autostart/
. The files there are .desktop
files, see man desktop-file-validate
, man desktop-file-edit
, man desktop-file-install
, ... . Since the files in my ~/.config/autostart/
put icons on the top of my screen, I think it's the right context/time to "change the desktop background".
You cannot do this with @reboot
, (or even cron
). When your @reboot
script runs, you haven't logged in (myscript.sh
is run as root
), the X Server hasn't been started, and the background you want to change doesn't even exist.
I suggest using ~/.config/autostart/
. The files there are .desktop
files, see man desktop-file-validate
, man desktop-file-edit
, man desktop-file-install
, ... . Since the files in my ~/.config/autostart/
put icons on the top of my screen, I think it's the right context/time to "change the desktop background".
answered Dec 21 '16 at 23:33
waltinatorwaltinator
22.6k74169
22.6k74169
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
add a comment |
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
can you please elaborate ? where should I put my script to execute at every reboot ?
– techy
Dec 22 '16 at 15:22
add a comment |
You want to execute your script at logon, not at boot.
as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder~/.config/autostart/
More information about Gnome Autostart:
Desktop Application Autostart Specification
-1- Create the launcher:
Copy/paste those lines in a terminal
tee -a ~/.config/autostart/myscript.desktop << END1
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec='/home/techy/Documents/myscript.sh'
Name=myscript
END1
chmod +x ~/.config/autostart/myscript.desktop
-2- Start the launcher for the first time, it will ask you to validate
Browse with file manager to ~/.config/autostart/
Double-click on the new created myscript.desktop
file
Validate the security message popup
-3- Done, test it
Log-off then log in back in to see it working
add a comment |
You want to execute your script at logon, not at boot.
as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder~/.config/autostart/
More information about Gnome Autostart:
Desktop Application Autostart Specification
-1- Create the launcher:
Copy/paste those lines in a terminal
tee -a ~/.config/autostart/myscript.desktop << END1
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec='/home/techy/Documents/myscript.sh'
Name=myscript
END1
chmod +x ~/.config/autostart/myscript.desktop
-2- Start the launcher for the first time, it will ask you to validate
Browse with file manager to ~/.config/autostart/
Double-click on the new created myscript.desktop
file
Validate the security message popup
-3- Done, test it
Log-off then log in back in to see it working
add a comment |
You want to execute your script at logon, not at boot.
as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder~/.config/autostart/
More information about Gnome Autostart:
Desktop Application Autostart Specification
-1- Create the launcher:
Copy/paste those lines in a terminal
tee -a ~/.config/autostart/myscript.desktop << END1
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec='/home/techy/Documents/myscript.sh'
Name=myscript
END1
chmod +x ~/.config/autostart/myscript.desktop
-2- Start the launcher for the first time, it will ask you to validate
Browse with file manager to ~/.config/autostart/
Double-click on the new created myscript.desktop
file
Validate the security message popup
-3- Done, test it
Log-off then log in back in to see it working
You want to execute your script at logon, not at boot.
as mentioned, a good way is to put a launcher (.desktop file) in the autostart folder~/.config/autostart/
More information about Gnome Autostart:
Desktop Application Autostart Specification
-1- Create the launcher:
Copy/paste those lines in a terminal
tee -a ~/.config/autostart/myscript.desktop << END1
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec='/home/techy/Documents/myscript.sh'
Name=myscript
END1
chmod +x ~/.config/autostart/myscript.desktop
-2- Start the launcher for the first time, it will ask you to validate
Browse with file manager to ~/.config/autostart/
Double-click on the new created myscript.desktop
file
Validate the security message popup
-3- Done, test it
Log-off then log in back in to see it working
edited Jun 14 '18 at 6:09
answered Jun 14 '18 at 6:02
cmak.frcmak.fr
2,1341021
2,1341021
add a comment |
add a comment |
Not sure about the details of your script in myscript.sh
.
If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.
To solve this, you need to put some delay (Example: sleep 5m
) inside your script until internet connection is established successfully.
This method solves my problem, but not sure if this works for you too.
New contributor
add a comment |
Not sure about the details of your script in myscript.sh
.
If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.
To solve this, you need to put some delay (Example: sleep 5m
) inside your script until internet connection is established successfully.
This method solves my problem, but not sure if this works for you too.
New contributor
add a comment |
Not sure about the details of your script in myscript.sh
.
If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.
To solve this, you need to put some delay (Example: sleep 5m
) inside your script until internet connection is established successfully.
This method solves my problem, but not sure if this works for you too.
New contributor
Not sure about the details of your script in myscript.sh
.
If your script requires to connect remote host, then you need internet connection in the first place before execution of this script.
To solve this, you need to put some delay (Example: sleep 5m
) inside your script until internet connection is established successfully.
This method solves my problem, but not sure if this works for you too.
New contributor
New contributor
answered 51 mins ago
Jerry ChongJerry Chong
11
11
New contributor
New contributor
add a comment |
add a comment |
I would try this instead.
@reboot sleep 45 && sh /home/techy/Documents/myscript.sh
That gives some time to your boot up, and the sh actually calls the shell script.
You might need to run chmod -x /home/techy/Documents/myscript.sh
this takes restrictions off of the script and path.
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
I would try this instead.
@reboot sleep 45 && sh /home/techy/Documents/myscript.sh
That gives some time to your boot up, and the sh actually calls the shell script.
You might need to run chmod -x /home/techy/Documents/myscript.sh
this takes restrictions off of the script and path.
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
I would try this instead.
@reboot sleep 45 && sh /home/techy/Documents/myscript.sh
That gives some time to your boot up, and the sh actually calls the shell script.
You might need to run chmod -x /home/techy/Documents/myscript.sh
this takes restrictions off of the script and path.
I would try this instead.
@reboot sleep 45 && sh /home/techy/Documents/myscript.sh
That gives some time to your boot up, and the sh actually calls the shell script.
You might need to run chmod -x /home/techy/Documents/myscript.sh
this takes restrictions off of the script and path.
answered Apr 6 '18 at 22:04
Sabastion ManneySabastion Manney
1
1
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.
So I had to make this crontab magic and realized that the two commands below are very different indeed:
crontab -e
sudo crontab -e
As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write
@reboot /folder/loadhd.sh
Check this:
https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.
So I had to make this crontab magic and realized that the two commands below are very different indeed:
crontab -e
sudo crontab -e
As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write
@reboot /folder/loadhd.sh
Check this:
https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.
So I had to make this crontab magic and realized that the two commands below are very different indeed:
crontab -e
sudo crontab -e
As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write
@reboot /folder/loadhd.sh
Check this:
https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e
I've been running into this problem on every boot. Ubuntu wasn't fully loading two hard drivers on my pc. I had to click on them at Nautilus in order to really load the drivers. I noticed that when running Transmission on startup using those drivers as a target for torrent files and it wasn't working.
So I had to make this crontab magic and realized that the two commands below are very different indeed:
crontab -e
sudo crontab -e
As I had to use root user's credentials to load the drivers only the second option worked for me and inside crontab file I could write
@reboot /folder/loadhd.sh
Check this:
https://stackoverflow.com/questions/43237488/linux-difference-between-sudo-crontab-e-and-just-crontab-e
edited Aug 2 '18 at 16:53
answered Jun 13 '18 at 21:44
Valmor NascimentoValmor Nascimento
114
114
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
this does not answer the question
– cmak.fr
Jun 16 '18 at 23:28
add a comment |
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%2f863240%2fcronjob-script-not-running-on-reboot%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