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

Forum rules
Before you post please read how to get help
Post Reply
DangerousChemistry
Level 1
Level 1
Posts: 2
Joined: Thu Feb 15, 2018 5:25 pm

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

Post by DangerousChemistry » 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

User avatar
all41
Level 13
Level 13
Posts: 4637
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

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

Post by all41 » Thu Feb 22, 2018 7:30 pm

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.
Proud to be a supporter and monthly contributor to Mint.

User avatar
Termy
Level 5
Level 5
Posts: 762
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

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

Post by Termy » Fri Feb 23, 2018 8:44 pm

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?
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife

lmuserx4849

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

Post by lmuserx4849 » Sun Feb 25, 2018 5:34 am

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.

Sugarcrisp
Level 1
Level 1
Posts: 37
Joined: Sat Mar 31, 2018 6:58 am

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

Post by Sugarcrisp » Thu Apr 05, 2018 9:35 am

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

bash64
Level 2
Level 2
Posts: 96
Joined: Mon Mar 23, 2015 12:19 am

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

Post by bash64 » Tue Apr 10, 2018 1:40 pm

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.

User avatar
Flemur
Level 16
Level 16
Posts: 6063
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

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

Post by Flemur » Tue Apr 10, 2018 7:06 pm

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
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Mint 18.3 Xfce/fluxbox/pulse-less
Xubuntu 17.10/fluxbox/pulse-less

User avatar
BG405
Level 6
Level 6
Posts: 1385
Joined: Fri Mar 11, 2016 3:09 pm
Location: England

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

Post by BG405 » Tue Apr 10, 2018 7:59 pm

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.
Dell Inspiron 1525 - LM17.3 CE 64-------------------Acer D255E 2GB - Manjaro KDE, LM17.3 KDE 32
Toshiba NB305 - LM17.3 Xfce 32---------------------K7S5A AMD 1.2GHz - LM17.3 Xfce 32 & WinXP-Pro
Acer Aspire E11 ES1-111M - LM18.2 KDE 64 ----Dell PII 350 64MB - Puppy 4.3 & Win98-SE

Post Reply

Return to “Scripts & Bash”