Home > OS >  How do I run a Bash script using crontab on startup? Other solutions haven't worked
How do I run a Bash script using crontab on startup? Other solutions haven't worked

Time:06-07

I'm trying run a bash script when my machine boots up using crontab that will open a terminal and then open btop, a command-line tool, in that terminal. The bash script I've written is in a file named startm and the contents are below:

#!/bin/bash
    gnome-terminal --command="bash -c 'btop; $SHELL'"

It opens a terminal, then runs the btop command in that terminal. The $SHELL bit is just to keep the terminal window open when the script has finished running.

In my crontab as a superuser I input the following:

@reboot /home/username/Scripts/startm

The script is already executable. If anyone has any ideas about what I'm doing wrong, or other ways I can accomplish this, please respond. I am new to Linux & Bash and any guidance will be appreciated.

CodePudding user response:

Basically, the problem is that you can't run gnome-terminal until there is a gnome desktop to run it on, and there won't be a desktop until you have logged in. Doing it from crontab is not going to work.

One way to do this is to put something into your ~/.bash-login script or similar to run the script when you login.

CodePudding user response:

Will adding your path string to 'Starup Applications' work?

  • Related