diff --git a/aws_ec2.go b/aws_ec2.go index 3ab737c..9b4323c 100644 --- a/aws_ec2.go +++ b/aws_ec2.go @@ -70,13 +70,17 @@ func (e *EC2) Init(sess *session.Session, reload bool, quickConnect int) { server = servers[quickConnect-1] } - cmd := exec.Command("ssh", "-i", "./av.pem", server.User+"@"+server.PublicIPAddress) - fmt.Println(cmd) - cmd.Stdout = os.Stdout - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - err := cmd.Run() - Check(err) + if server.State == "stopped" || server.State == "terminated" || server.PublicIPAddress == "-" { + fmt.Printf("Cannot connect to %s(%s) (IP:%s) \n", color.YellowString(server.Name), server.State, server.PublicIPAddress) + } else { + cmd := exec.Command("ssh", "-i", "./av.pem", server.User+"@"+server.PublicIPAddress) + fmt.Println(cmd) + cmd.Stdout = os.Stdout + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + err := cmd.Run() + Check(err) + } } func sortServers(servers []Server) []Server { @@ -110,7 +114,7 @@ func setColor(status string, s string) string { return color.RedString(s) } if status == "terminated" { - return color.WhiteString(s) + return color.YellowString(s) } return s } @@ -185,7 +189,10 @@ func fetchEC2Instances(sess *session.Session) { server.State = *instance.State.Name server.InstanceType = *instance.InstanceType server.LaunchTime = *instance.LaunchTime - server.PrivateIPAddress = *instance.PrivateIpAddress + server.PrivateIPAddress = "-" + if instance.PrivateIpAddress != nil { + server.PrivateIPAddress = *instance.PrivateIpAddress + } server.PublicIPAddress = "-" server.InstanceID = *instance.InstanceId if instance.PublicIpAddress != nil { @@ -209,7 +216,7 @@ func fetchEC2Instances(sess *session.Session) { homeDir, _ := filepath.Abs(filepath.Dir(os.Args[0])) serversJSON := path.Join(homeDir, "servers.json") - file, err := os.Create(serversJSON) + file, _ := os.Create(serversJSON) defer file.Close() file.WriteString(string(s)) file.Sync() diff --git a/build.sh b/build.sh index 2b0cff0..9dbe223 100755 --- a/build.sh +++ b/build.sh @@ -9,7 +9,7 @@ env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/avconnect-linux-amd echo "env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o bin/avconnect-mac ." env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o bin/avconnect-mac . -cd bin +cd bin || exit md5sum avconnect-linux-386 > md5sum.txt md5sum avconnect-linux-amd64 >> md5sum.txt diff --git a/lib_credentialHandler.go b/lib_credentialHandler.go index 3112850..448362e 100644 --- a/lib_credentialHandler.go +++ b/lib_credentialHandler.go @@ -42,7 +42,7 @@ func (ch *CredentialHandler) getCredentials() { homeDir, _ := filepath.Abs(filepath.Dir(os.Args[0])) credentialsFile := path.Join(homeDir, "credentials") - file, err := os.Create(credentialsFile) + file, _ := os.Create(credentialsFile) defer file.Close() file.WriteString("[default]\n") file.WriteString("aws_access_key_id = " + answers.AccessKey + "\n")