I want to run a small script on system start

2 different applications, xgamma and sct

Location of file: /usr/bin/xgamma

run "xgamma -bgamma 1.2" (without the quotes)

and in /usr/bin/sct

run "sct 10000" (without the quotes)

would that be:


#!bin/bash

#apply blue gamma 
/usr/bin/xgamma -bgamma 1.2

#apply Screen Temperature
/usr/bin/sct 10000

Save script as ~/xgamma.sh and then add that to Startup apps, or can I just add both right into start up:

Screenshot at 2023-01-30 15-54-04
Screenshot at 2023-01-30 15-54-15

Any help will be appreciated.

Either method should work, as far as I can tell. If you go with option 1, however, you should:

  1. Make the script file executable. As a reminder, you can use the following terminal command to do this:
    chmod +x ~/xgamma.sh
    
  2. When you add the script as a startup program, specify the full path to the script -- so instead of typing ~/xgamma.sh into the "Command" field, type /home/[username]/xgamma.sh. If your username is mickee, type /home/mickee/xgamma.sh.

Other than that, they should work.

2 Likes

Thanks @gordon ! This was my first (if simple) script! I am amazed I even figured this simple one out!

1 Like

@gordon so I'm still learning, LOL. When trying to run from the directory it's in /home/mickee/scripts when I run from the terminal it gives:

mickee@mickeymouse2:~/scripts$ xgamma.sh
xgamma.sh: command not found

what have I done wrong?

1 Like

~/scripts is not in your $PATH.

  1. You can add it to your path in your .profile file

  2. or, the default file for personal executables is /home/mickee/bin or /home/mickee/.local/bin if you want it hidden for some reason. If either of those directories exists, it is automatically added to your $PATH when .profile runs

  3. or, you can call the script locally with a fully specified pathname: e.g.:
    $ /home/mickee/scripts/xgamma.sh -OR-
    $ ~/scripts/xgamma.sh -OR-
    $ (from the scripts directory only) $ ./xgamma.sh

4 Likes

Gordon told you to use the whole path, not ~/
Your terminal does'nt accept that

1 Like

@tatanka I think you may be misreading what he is doing. It looks like he has it working from startup scripts (solved) but had a followup question about running the script from its own directory. The only place he has ~/ is in his terminal prompt; he only typed "xgamma.sh"

He doesn't realize that unlike other OSs Unix/Linux does not automatically include the current directory in the $PATH.

2 Likes

now you misread me :slight_smile:
I think I used too little words.

"He doesn't realize that unlike other OSs Unix/Linux does not automatically include the current directory in the $PATH."

That's all I wanted to say too.

4 Likes

Cool :slight_smile: Just didn't want to confuse OP.

1 Like

Possibly this may be of interest

Permanently Add A Directory To $PATH
To add a directory to $PATH permanently, we’ll need to edit the .bashrc file of the user you want to change.
Use nano or your favorite text editor to open the file, stored in the home directory.

$ pluma ~/.bashrc

At end of this file, put your new directory that you wish to permanently add to $PATH

export PATH=”/home/mendy/myscripts:$PATH”

Save your changes and exit the file. Afterwards, execute the following command to make the changes take
effect in your current session. Alternative, you can log out or reboot the system.

$ source ~/.bashrc

That’s all there is to it. You can check $PATH once more to verify the change.

$ echo $PATH

Temporarily Add A Directory To $PATH
To add a directory to $PATH for the current session, use the following command syntax. In this example, we’re
adding the /home/mendy/myscripts directory.

$ export PATH=”/home/mendy/myscripts:$PATH”

You can verify afterwards that the directory has been added.

$ echo $PATH
/home/mendy/myscripts [...]

Now, files we have stored in the /home/mendy/myscripts directory can be executed anywhere, without specifying their
full path. This configuration will change when we end the current session (reboot the PC or close the
terminal). To make it permanent, check out the section above.

Image shows result of using permanent method adding path to my folder with my scripts in it.

2 Likes

Just a point to make, though. Adding to .bashrc only adds to path when using the bash shell. Any scripts using other shells will not have that path. Adding to .profile affects all login shells.

That may be exactly what one wants, or it may cause confusion because the $PATH is different depending on how it is invoked.

As @gordon implies, though, startup commands does not invoke a login shell until the script's first line is read, so you have to use the full pathname there regardless. And there are security implications to consider when adding multiple directories to $PATH

3 Likes

Before you add entries to the $PATH variable, please read this:

There is already a 'bin' directory in your home which is already included in your $PATH

it is $HOME/.local/bin

Please use it, it saves you some work.
It also keeps all of your home made scripts tidy together

P.S. if you create the directory '$HOME/bin' then it will also automatically added to your $PATH variable.

2 Likes

This topic has been marked "solved," so I'm only adding this for consideration. If you want to start a process when the computer starts and you can't craft a service script for it, you can use a cron job with the @reboot option. The syntax, depending on your environment, looks something like this:

@reboot root /path/to/executable/program/or/script

You can view the contents of your crontab file (the configuration) using crontab -l

To edit the crontab, use crontab -e

2 Likes