Author: I write code in bamboo garden
Reading time: 8 minutes
Technical preparation: shell command, maven
Java uses Ganymed’s SSH package class library, connecting to Linux server becomes very simple, just a few lines of code can complete the connection, authentication operation is handed over to Ganymed, but Ganymed’s source code does not have annotations, the use of API needs to be slowly considered, to understand what each of its classes is responsible for.
1. How to introduce Genymed?
1.1 Maven project adds dependencies in red boxes to POM files
1.2 For projects not managed by Maven, download the JAR package and manually add all projects
How to use GenyMed-SSH to connect to Linux?
2.1 Preparing Server connection information
2.2 Connect to the Linux server and go to the [/home] directory to create the [Genymed] folder
The execCommand() method can execute multiple shell commands at a time, each terminated by a semicolon. Note. TXT file execCommand(” CD /home; touch note.txt; Cp note. TXT/usr/local “).
Note. TXT files have been created in the [/home] directory
Close the Connection object
The application scenario of Java connecting to Linux
3.1 To back up files uploaded by the client, run the cp command
3.2 Server A periodically scans for the mysql. TXT file generated by server B and runs the SCP command to copy the file to server A
3.3 Viewing the CPU, Memory, and Disk Indicator Usage of the Linux Server
—– End —–
More oliver
Please scan the qr code below
Welcome to pay attention ~