#!/bin/bash
echo "=============================="
echo $1
echo $2
echo $3

splitip () {
    local IFS
    IFS=.
    set -- $*
    echo "ec2-$1-$2-$3-$4.compute-1.amazonaws.com"
}

DNS_ADDR=$(splitip $2)
echo 'Link second app'
cd myapp
sudo sed -i "s/url2/$DNS_ADDR/g" app.js
sudo forever stopall
sudo forever start app.js