2

I'm trying to set up my system to automatically boot my two main Vagrant boxes when my computer turns on but it's throwing an error saying no such file or directory when I added this to the bottom of ~/.profile

bash cd ~/Develop/Websites/scotch && vagrant up
bash cd ~/Develop/Websites/homestead && vagrant up

I can paste that line (minus the bash) into a terminal though and it works fine.

I'm told I shouldn't use ~/.profile for this and should possibly use a cron @reboot.

How would I format that since it's not a script that runs necessarily? It's not a file you run, it's a command that has to be in a specific folder.

Octoxan
  • 121
  • 3
  • 1
    The commands should be bash -c 'cd ~/Develop/Websites/scotch && vagrant up' and bash -c 'cd ~/Develop/Websites/homestead && vagrant up' – Terrance Jun 02 '17 at 15:45
  • 1
    First, always use the full path in scripts as ~ is abmibigous. If you use the full script you should not need to cd . Second, that is NOT how you run things on boot or login. – Panther Jun 02 '17 at 15:45
  • @Terrance - does not matter, ~/,profile is NOT run at boot. – Panther Jun 02 '17 at 15:46
  • @bodhi.zazen Good point. =) – Terrance Jun 02 '17 at 15:46
  • @bodhi.zazen How come I have a ton of stuff in my .profile that runs on boot? >.> Not being mean, I seriously don't know. New to this. lol – Octoxan Jun 02 '17 at 15:46
  • @Terrance edited the title to specify I'm on the Budgie flavor, there is no Session and Startup in options lol – Octoxan Jun 02 '17 at 15:56
  • @Terrance - There is a difference between running at boot and running when you log in. If you were to boot and not log in things in ~/.profile will not run. See the link I gave you. Also ~/.profile is not the best option as it would run every time you log in. Google search deamonize vagrant – Panther Jun 02 '17 at 15:57
  • Maybe this might work: https://unix.stackexchange.com/a/47715/111521 However, for the commands I would still recommend doing the bash -c ' ' on the Exec= lines. Oh, and I would use the full path to the files /home/username/Develop/..... – Terrance Jun 02 '17 at 16:08

1 Answers1

1

It looks like you want to run these commands in a sub-shell to not affect the working directory of the shell running the .profile script.

You can use the -c option to run a shell with commands given on the command line:

bash -c 'cd ~/Develop/Websites/scotch && exec vagrant up'

However, it would be simpler to use the sub-shell feature of the current shell instead:

( cd ~/Develop/Websites/scotch && exec vagrant up )
David Foerster
  • 36,264
  • 56
  • 94
  • 147