-1

I'm creating a new instance in AWS and adding some user data, but part of the job is to create an sh file and then executed.

I'm trying:

#!/bin/bash -x
cd /tmp
INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
sudo wget -O ethminer.tar.gz https://github.com/ethereum-mining/ethminer/releases/download/v0.18.0/ethminer-0.18.0-cuda-9-linux-x86_64.tar.gz
sudo tar xvfz ethminer.tar.gz
cd bin
cat > runner.sh << __EOF__
#!/bin/bash -x
SERVERS=(us1 us2 eu1 asia1)
while (true); do
  PREFERRED_SERVER=\${!SERVERS[\${!RANDOM} % \${!#SERVERS[@]}]}
  ./ethminer \
    -P stratums://xxx.${!INSTANCE_ID}@\${!PREFERRED_SERVER}.ethermine.org:5555 \
    -P stratums://xxx.${!INSTANCE_ID}@us1.ethermine.org:5555 \
    -P stratums://xxx.${!INSTANCE_ID}@us2.ethermine.org:5555 \
    -P stratums://xxx.${!INSTANCE_ID}@eu1.ethermine.org:5555 \
    -P stratums://xxx.${!INSTANCE_ID}@asia1.ethermine.org:5555 \
  >> /tmp/ethminer.log 2>&1
done
__EOF__
sudo chmod +x runner.sh
sudo nohup ./runner.sh &

Everything works except the sh, my command creates the runner.sh script but it is empty.

alexmorgan.cr
  • 270
  • 6
  • 18

1 Answers1

0

The UserData does not work because its is designed from CloudFormation, thus it has incorrect syntax for use in a standalone instance. The script with correct syntax is below and it will generate your runner.sh. I haven't tested runner's functionality, only the creation of the runner.sh.

#!/bin/bash -x
cd /tmp
INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
sudo wget -O ethminer.tar.gz https://github.com/ethereum-mining/ethminer/releases/download/v0.18.0/ethminer-0.18.0-cuda-9-linux-x86_64.tar.gz
sudo tar xvfz ethminer.tar.gz
cd bin
cat > runner.sh << __EOF__
#!/bin/bash -x
SERVERS=(us1 us2 eu1 asia1)
while (true); do
  PREFERRED_SERVER=\${SERVERS[\${RANDOM} % \${#SERVERS[@]}]}
  ./ethminer \
    -P stratums://xXX.${insTANCE_ID}@\${PREFERRED_SERVER}.ethermine.org:5555 \
    -P stratums://xxx.${INSTANCE_ID}@us1.ethermine.org:5555 \
    -P stratums://xxx.${INSTANCE_ID}@us2.ethermine.org:5555 \
    -P stratums://xxx.${INSTANCE_ID}@eu1.ethermine.org:5555 \
    -P stratums://xxx.${INSTANCE_ID}@asia1.ethermine.org:5555 \
  >> /tmp/ethminer.log 2>&1
done
__EOF__
sudo chmod +x runner.sh
sudo nohup ./runner.sh &
Marcin
  • 215,873
  • 14
  • 235
  • 294