Tried to run batch script on terminal at startup using crontab and /etc/rc.local but they dont work. I dont know what has gone wrong as there is no log to check
Here is the line on crontab @reboot user /home/user/script.sh ; /usr/bin/gnome-terminal -- bash -c "/home/user/script2.sh; exec bash" and on rc.local /home/user/script.sh ; /usr/bin/xterm -hold -e /home/user/script2.sh
- 101
- 1
- 7
-
Rather than crontab, it’s generally recommended that you [define a service](https://askubuntu.com/a/1151089/1222991) to accomplish this goal. It is much more reliable than crontab – matigo Aug 10 '21 at 15:56
-
3A *terminal emulator* usually runs in a user's *desktop session* after they have logged in - none of which happens `@reboot`. See instead [How do I start applications automatically on login?](https://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login) – steeldriver Aug 10 '21 at 16:32
2 Answers
A terminal emulator such as xterm or Gnome Terminal can only run on a graphical server (Xorg or increasingly Wayland). There is no chance you can start that before the graphical environment has been setup.
During log in, however, you can automatically launch a terminal emulator. To keep the terminal open when the command has finished, you could add a "bash" command at the end so the terminal stays open at a bash prompt, or, in Gnome Terminal, edit the profile to specify that the terminal should remain open.
- 82,909
- 6
- 116
- 186
You can try creating a service as described here: https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
Services are like "background jobs": they can be enabled to start on startup. I am not an expert, but I think cronjobs are more oriented to scheduled tasks (e.g. make a backup of the system every night at 2 a.m.).
- 31
- 3