]>
git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.support/src/org/argeo/slc/jsch/GetMachineId.java
1 package org
.argeo
.slc
.jsch
;
4 import java
.util
.ArrayList
;
7 import javax
.security
.auth
.Subject
;
8 import javax
.security
.auth
.login
.LoginContext
;
12 public static void main(String
[] args
) {
13 URL url
= GetMachineId
.class.getResource("jaas.cfg");
14 System
.setProperty("java.security.auth.login.config", url
.toExternalForm());
16 String hostname
= args
[0];
18 LoginContext lc
= new LoginContext("SINGLE_USER");
21 SshTarget sshTarget
= new SshTarget();
22 sshTarget
.setHost(hostname
);
23 RemoteExec remoteExec
= new RemoteExec();
24 remoteExec
.setCommand("cat /etc/machine-id");
25 remoteExec
.setSshTarget(sshTarget
);
26 List
<String
> lines
= new ArrayList
<>();
27 remoteExec
.setStdOutLines(lines
);
29 Subject
.doAs(lc
.getSubject(), remoteExec
.asPrivilegedAction());
31 String machineId
= lines
.get(0);
32 System
.out
.println(hostname
+ ": " + machineId
);
33 } catch (Exception e
) {