0

Everytime I run my ubuntu VM I have to run source ~/.bash_profile I was wondering if there's any way which would run this command automatically as soon as I boot my VM up without me having to do this every single time.

2
  • 1
    when you say you run ubuntu VM, does this mean you are starting that instant from start or you are using saved state option of virtualbox/vmware? Also, do you mind sharing what command you are trying to run from bash_profile?
    – kleash
    Dec 3, 2019 at 16:16
  • 1
    Possible duplicate of How to run scripts on start up?
    – karel
    Dec 4, 2019 at 12:56

2 Answers 2

0

What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

Why two different files?

Say, you’d like to print some lengthy diagnostic information about your machine each time you login (load average, memory usage, current users, etc). You only want to see it on login, so you only want to place this in your .bash_profile. If you put it in your .bashrc, you’d see it every time you open a new terminal window.

That was an excerpt from a blog post that might help you. .bash_profile vs .bashrc

2
  • Just read the differences, you mean I should add content of bash_profile into bashrc?
    – asd
    Dec 3, 2019 at 16:03
  • Ye try that. The .bashrc file should already be there.
    – d4n3sh
    Dec 3, 2019 at 16:16
0

save a cmd.sh with command you want to run.

sudo chmod +x cmd.sh

sudo crontab -e

enter the below line at end of file

@reboot path_to_your_file/cmd.sh

save and exit.

warning @reboot is a non standard syntex old crontab will fail.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .