I have a virtual machine running and its root directory mounted to in ./vm
I have this script running on the virtual machine:
#!/usr/bin/env bash
flag=/dir/flag
echo "Listening..."
while true; do
while [[ ! -f "$flag" ]]; do
sleep 2
done;
cat "$flag"
rm -f "$flag"
done
In the host, I have this:
#!/usr/bin/env bash
arrayA=( a b c d )
arrayB=( w x y z )
while true; do
for i in $(seq 0 $((${#arrayA[@]} - 1 ))); do
rm -rf ./vm/dir/*
sync
echo "${arrayB[i]}" > ./vm/dir/flag
read -p "press [Enter]"
done
done
The problem I get, is that sometimes the script in the host yells at me:
./host.sh: line ..: vm/dir/flag: No such file or directory
I don't know how to fix this. I've inserted syncs
here and there, but sometimes (not always) after pressing [Enter], I get the error message, the flag is not written, and the virtual machine does nothing.
[[ true ]]
checks if the stringtrue
is non-empty, and returns true if so. If you want to loop forever, usewhile true
, or more idiomaticallywhile :