Add new PLC passwords
This commit is contained in:
parent
b8e528dfff
commit
73de386857
3 changed files with 197 additions and 69 deletions
|
|
@ -8,23 +8,40 @@ import java.io.PrintStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CommandExecutor {
|
||||
|
||||
private Session session;
|
||||
private final String fileToRead = "monitor.txt";
|
||||
private String commandsToExecute = "";
|
||||
private ArrayList<Server> allServers = new ArrayList<>();
|
||||
private int timeBetweenCommands;
|
||||
private final ArrayList<Server> allServers;
|
||||
|
||||
public CommandExecutor() {
|
||||
|
||||
allServers = new BuildServerArray().getAllServers();
|
||||
// commandsToExecute = "tail -n 20 flowserver/" + fileToRead;
|
||||
// commandsToExecute = "ls -l flowserver/";
|
||||
timeBetweenCommands = 1; // in seconds (if rebooting, put cca 20 seconds between reboots)
|
||||
// commandsToExecute = "tail -n 3 flowserver/monitor.txt";
|
||||
// commandsToExecute = "sudo journalctl --vacuum-size=1M";
|
||||
// commandsToExecute = "sudo rm flowserver/monitor.1.txt.gz";
|
||||
commandsToExecute = "sudo service nodejs restart";
|
||||
// commandsToExecute = "sudo service nodejs stop";
|
||||
// commandsToExecute = "sudo service nodejs restart";
|
||||
commandsToExecute = "sudo service nodejs start";
|
||||
// commandsToExecute = "rm -rf /home/unipi/flowserver/flow";
|
||||
// commandsToExecute = "mkdir -p /home/unipi/flowserver/flow/helper";
|
||||
// commandsToExecute = "sudo reboot";
|
||||
commandsToExecute = "python /root/flowserver/addSwitch.py";
|
||||
|
||||
// commandsToExecute = "ls -l /home/unipi/flowserver/databases";
|
||||
// commandsToExecute = "ls -l /root/flowserver/databases";
|
||||
// commandsToExecute = "rm /home/unipi/flowserver/databases/1.tbdata.nosql /home/unipi/flowserver/databases/2.tbdata.nosql /home/unipi/flowserver/databases/3.tbdata.nosql /home/unipi/flowserver/databases/4.tbdata.nosql /home/unipi/flowserver/databases/5.tbdata.nosql /home/unipi/flowserver/databases/6.tbdata.nosql /home/unipi/flowserver/databases/7.tbdata.nosql /home/unipi/flowserver/databases/8.tbdata.nosql /home/unipi/flowserver/databases/9.tbdata.nosql /home/unipi/flowserver/databases/10.tbdata.nosql";
|
||||
// commandsToExecute = "head -n 1 /home/unipi/flowserver/databases/nodes_original/nodes_original.table";
|
||||
// commandsToExecute = "sudo sh -c 'chmod 777 /etc/owfs.conf; chmod 777 /etc/fuse.conf; chmod 777 /etc/evok.conf; chmod 777 /lib/systemd/system/owfs.service; mkdir /mnt/1wire'";
|
||||
|
||||
// commandsToExecute = "sudo sh -c 'service owfs stop; service evok stop; service nodejs stop; chmod 777 /etc/owfs.conf; chmod 777 /etc/fuse.conf; chmod 777 /etc/evok.conf; chmod 777 /lib/systemd/system/owfs.service; mkdir /mnt/1wire'";
|
||||
// commandsToExecute = "sudo sh -c 'chmod 644 /etc/owfs.conf; chmod 644 /etc/fuse.conf; chmod 644 /etc/evok.conf; chmod 644 /lib/systemd/system/owfs.service'";
|
||||
// commandsToExecute = "python /home/unipi/flowserver/cloud_topic.py && rm /home/unipi/flowserver/databases/status.table";
|
||||
}
|
||||
|
||||
|
||||
public void open(String username, String hostname, String password) throws JSchException {
|
||||
|
||||
JSch jSch = new JSch();
|
||||
|
|
@ -95,16 +112,13 @@ public class CommandExecutor {
|
|||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
CommandExecutor ssh = new CommandExecutor();
|
||||
|
||||
for (Server s : ssh.allServers) {
|
||||
try {
|
||||
ssh.open(s.getUsername(), s.getHost(), s.getPassword());
|
||||
// String ret = ssh.runCommand("tail -n 20 " + s.getPath() + "/flowserver/" + ssh.fileToRead);
|
||||
// String ret = ssh.runCommand("ls -la /home/unipi/flowserver/flow");
|
||||
// String ret = ssh.runCommand("sudo service nodejs restart");
|
||||
String ret = ssh.runCommand(ssh.commandsToExecute);
|
||||
System.out.println(ret);
|
||||
ssh.close();
|
||||
|
|
@ -112,6 +126,8 @@ public class CommandExecutor {
|
|||
System.out.println(e);
|
||||
//throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
TimeUnit.SECONDS.sleep(ssh.timeBetweenCommands);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue