I have 3 shell script files placed inside vagrant directory like so: files placement screenshot
This is the install.sh file:
#!/bin/bash echo "Launching instances with the following parameters:" echo "" echo "Machine Image ID: $ 1" echo "Number of Instances: $ 2" echo "Instance Type: $ 3" echo "Key Pair Name: $ 4" echo "Security Group ID: $ 5" aws ec2 run-instances --image-id $ 1 --count $ 2 --instance-type $ 3 --key-name $ 4 --user-data file://install-env.sh --security-group-ids $ 5
This is the install-env.sh file:
#!/bin/bash sudo apt-get -y update sudo apt-get -y install apache2 php php-gd mysql-server sudo systemctl enable apache2 sudo systemctl start apache2
I have another destroy.sh file but it’s not related to this error as of now. This is the command I am trying to execute after I ssh into ubuntu VM (I replaced the ami & sg numbers with * for posting it here):
vagrant@ubuntu-bionic:/vagrant$ ./install.sh ami-*************** 1 t2.micro key-name sg-**************
This is the error that I am getting:
-bash: ./install.sh: /bin/bash^M: bad interpreter: No such file or directory
The same command works fine if I have those shell script inside home directory, (which I am not able to see on the UI) and I run the command without navigating to vagrant directory like so:
vagrant@ubuntu-bionic:$ ./install.sh ami-********** 1 t2.micro key-name sg-**************
Why does it not work if I place the files inside vagrant directory? I want to place it here so that I can make changes in one place and push/pull to/from github, instead of having to copy-paste my changes and then push to github everytime.
Please guide me through the placement of shell script files and the directory navigation on cmd prompt.