Created
April 25, 2017 03:14
-
-
Save Aeternam/82dac25790994530a1469f8966e861f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
func ConnectSSH( host string, sshuser string, cmdbuser string ) { | |
config := &ssh.ClientConfig{ | |
User: "jenkins", | |
Auth: []ssh.AuthMethod{ | |
ssh.Password("654321"), | |
}, | |
} | |
cmd := fmt.Sprintf("export SSH_SHTERM_NAME=%s;ssh -o ConnectTimeout=3 -o SendEnv=SSH_SHTERM_NAME %s@%s ", cmdbuser, sshuser, host) | |
client, err := ssh.Dial("tcp", "11.22.33.44:22", config) | |
if err != nil { | |
panic("Failed to dial: " + err.Error()) | |
} | |
// Each ClientConn can support multiple interactive sessions, | |
// represented by a Session. | |
session, err := client.NewSession() | |
if err != nil { | |
panic("Failed to create session: " + err.Error()) | |
} | |
defer session.Close() | |
// Once a Session is created, you can execute a single command on | |
// the remote side using the Run method. | |
var b bytes.Buffer | |
session.Stdout = &b | |
if err := session.Run("/usr/bin/whoami"); err != nil { | |
panic("Failed to run: " + err.Error()) | |
} | |
fmt.Println(b.String()) | |
} | |
*/ | |
func (e *env) read(fp *os.File, wrCh, quitCh chan<- bool, imptQ chan<- imptSpec) { | |
// read from shell prompt | |
go func() { | |
reader := bufio.NewReader(fp) | |
for { | |
if e.readFlag == 0 { | |
fmt.Print(">>> ") | |
} else { | |
e.readFlag-- | |
} | |
line, _, err := reader.ReadLine() | |
if err != nil { | |
e.logger("read", "", err) | |
cleanDir(e.bldDir) | |
quitCh <- true | |
return | |
} | |
// append token.SEMICOLON | |
line = append(line, 59) | |
if e.parserSrc.parseLine(line, imptQ) { | |
wrCh <- true | |
e.readFlag = 3 | |
} | |
} | |
}() | |
} | |
func (e *env) write(imptCh chan<- bool) { | |
// write tmporary source code file | |
go func() { | |
f, err := os.OpenFile(e.tmpPath, os.O_WRONLY|os.O_CREATE, 0600) | |
if err != nil { | |
return | |
} | |
f.Truncate(0) | |
f.WriteString(concatLines(e.parserSrc.mergeLines(), "\n")) | |
e.logger("write", concatLines(e.parserSrc.mergeLines(), "\n"), nil) | |
f.Sync() | |
if err := f.Close(); err != nil { | |
e.logger("writer", "", err) | |
return | |
} | |
imptCh <- true | |
e.parserSrc.main = nil | |
removePrintStmt(&e.parserSrc.mainHist) | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment