-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (47 loc) · 1.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"fmt"
"github.com/ibmendoza/easyssh"
"log"
)
//For example, pass -user root -server 192.168.56.101 -keypath path/to/id_rsa -cmd pwd
var user = flag.String("user", "", "username")
var server = flag.String("server", "", "server name or IP address")
var pswd = flag.String("pswd", "", "password")
var keypath = flag.String("keypath", "", "keypath")
var scp = flag.String("scp", "", "optional file to upload")
var cmd = flag.String("cmd", "", "optional command to run")
func main() {
flag.Parse()
if *user == "" || *server == "" {
log.Fatal("User and server cannot be blank")
}
ssh := &easyssh.MakeConfig{
User: *user,
Server: *server,
Key: *keypath,
Password: *pswd,
Port: "22",
}
// Call Run method with command you want to run on remote server.
if *cmd != "" {
response, err := ssh.Run(*cmd)
if err != nil {
log.Fatal("Can't run remote command: " + err.Error())
} else {
fmt.Println(response)
}
}
if *scp != "" {
// Call Scp method with file you want to upload to remote server.
err := ssh.Scp(*scp)
if err != nil {
log.Fatal("Can't run remote command: " + err.Error())
} else {
fmt.Println("success")
response, _ := ssh.Run("ls -al " + *scp)
fmt.Println(response)
}
}
}