2

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.

IanC
  • 931
techy
  • 127

4 Answers4

1

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".

waltinator
  • 36,399
0

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.

0

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

cmak.fr
  • 8,696
0

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.

Jerry Chong
  • 181
  • 1
  • 5