Page 1 of 1

Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Thu Feb 22, 2018 6:53 pm
by DangerousChemistry
I'm using Linux Mint 18.3 Cinnamon.

When I double click the .bash file it asks if I want to run or display the file. I click on "Run In Terminal" and the script starts. So it works fine when I manually open it.

I want the script to run automatically. I tried using the Startup Applications in System Settings. I added a custom command but that isn't working. When I click "Run Now" in Startup Applications nothing happens. Nothing happens when I restart either.

Does someone know how to run a .bash file in the Terminal immediately after booting up?

Thank you

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Thu Feb 22, 2018 7:30 pm
by all41
Open an instance of Nemo--then in the toolbar Edit/Preferences/Behavior and make sure Nemo will run executable text
files without asking each time.
Welcome aboard the forums.

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Fri Feb 23, 2018 8:44 pm
by Termy
You may need to specify bash FILE, where FILE is the filename of your script. Failing that, amend it to ~/.profile. Does it need root privileges? If so, consider amending it to /etc/rc.local but ensure it is written correctly, regarding exit statuses. Back up any files you edit beforehand, just in-case.

What is the script you're running? What is the command you've used to execute the script?

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Sun Feb 25, 2018 5:34 am
by lmuserx4849
DangerousChemistry wrote:
Thu Feb 22, 2018 6:53 pm
I'm using Linux Mint 18.3 Cinnamon.

When I double click the .bash file it asks if I want to run or display the file. I click on "Run In Terminal" and the script starts. So it works fine when I manually open it.

I want the script to run automatically. I tried using the Startup Applications in System Settings. I added a custom command but that isn't working. When I click "Run Now" in Startup Applications nothing happens. Nothing happens when I restart either.

Does someone know how to run a .bash file in the Terminal immediately after booting up?

Thank you
I don't have cinnamon, but these things are often done the same way. I think you did everything right and the script is probably running (as long as you made it executable/chmod u+x), but you aren't seeing the terminal. One way to confirm this is to direct some output to a file, like echo Test $(date) > $HOME/test.log.

When you used the System Settings, it created a file in $HOME/.config/autostart. The file name will be the name you entered followed by ".desktop". If you cat / view that file, it will have a line that looks like Exec=your_command. If you want to see the terminal, change that line to gnome-terminal --command "path/your_command". Now you probably can also type that same line on the command line in System Settings :-)

In your script, to pause and exit, you can put something like read -p "Hit enter"; exit.

For others:
kde terminal: konsole
mate terminal: mate-terminal

Just a little extra:
You can read more about:
- .bashrc and .profile: bash startup files
- autostart files and directories. You'll hear a lot about .desktop files and freedesktop.org.

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Thu Apr 05, 2018 9:35 am
by Sugarcrisp
I just finished creating my own startup that seems to be working perfectly. Best of all it was very easy. I created my bash script and saved it to my scripts folder.

Code: Select all

#!/bin/sh
expressvpn connect smart
Next, I CD to my scripts directory and ran

Code: Select all

chmod 744 expressvpn connect smart
This gives the file executable rights.
Then I ran the following to add my script to the cron startup utility.

Code: Select all

crontab -e
I use the nano editor (it was one of the options that came up) to create/modify my scripts. I scrolled to the bottom of the file and added
@reboot ( sleep 10 ; sh /home/brett/my-scripts/expressvpnstart.sh )
To save in nano
ctr+o, then enter
To exit in nano
ctr+x
This runs the bash script at reboot/login. The sleep 10 just delays the command for 10 seconds on startup

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Tue Apr 10, 2018 1:40 pm
by bash64
If you mean after logging into your desktop then Startup Applications is correct.
You need to create an entry that runs an executable bash script.
Lets say its called myscript.sh and it sits in your home folder.

Make it executable:
>sudo chmod u+x myscript.sh

Now, in startup apps ADD a custom command and BROWSE for myscript.sh and fill in the other items.

It will run everytime you login.

If you mean during the boot process then you probably want to add the command to run it to /etc/rc.local:

>sudo bash
>nano /etc/rc.local

/home/{loginname}/myscript.sh

save and exit nano

Replace loginname with your account name.

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Tue Apr 10, 2018 7:06 pm
by Flemur
DangerousChemistry wrote:
Thu Feb 22, 2018 6:53 pm
I added a custom command but that isn't working. When I click "Run Now" in Startup Applications nothing happens.
You can run a script without a window showing up...so your script might be running but you just don't see anything.

Add something like this to the script, and see if the file "aaa.txt" shows up:

Code: Select all

echo "Script is running " > /home/<username>/aaa.txt

Re: Can you show me how to run a bash file in Terminal immediately after startup?

Posted: Tue Apr 10, 2018 7:59 pm
by BG405
Flemur wrote:
Tue Apr 10, 2018 7:06 pm
Add something like this to the script, and see if the file "aaa.txt" shows up:

Code: Select all

echo "Script is running " > /home/<username>/aaa.txt
You could also use notify-send "Script running" (or whatever messaage you want) as an alternative.