I have this shell script to play around with the network and vagrant:
#!/bin/bash
cat <<EOF > Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "generic/alpine318"
config.vmwork "public_network", ip: "192.168.100.21"
config.vmwork "private_network", ip: "192.168.56.10"
config.vm.provider "virtualbox" do |vb|
end
end
EOF
vagrant up
cat <<EOF > script.sh
#!/bin/bash
ifconfig eth2 192.168.56.11 netmask 255.255.255.0
ip a > ip.txt
route add default gw 192.168.56.11 eth2
route > gw.txt
EOF
chmod +x script.sh
sshpass -p "vagrant" scp -o StrictHostKeyChecking=no ./script.sh [email protected]:~/script.sh
sshpass -p "vagrant" ssh -tt -o StrictHostKeyChecking=no [email protected] << EOF
sudo ~/script.sh
exit
EOF
When I try to cat the ip.txt and gw.txt inside the ssh session it prints out fine. But then I exit and try to vagrant ssh “cat ip.txt”
it says that the ip.txt file doens’t exist.
I have already tried setting the ip.txt to /home/vagrant/ip.txt and same for gw. Still doenst work. Tried to find the files after exiting the ssh sesion, but still nothing, as if ghey dont exist. And I need the “vagrant ssh “cat ip.txt”” to work, because it is in my github pipeline test file and i cant change the contents of it.