软件编程
位置:首页>> 软件编程>> java编程>> java中如何执行xshell命令

java中如何执行xshell命令

作者:fostlin  发布时间:2021-10-06 16:22:18 

标签:java,xshell,命令

java执行xshell命令

实例

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Lin {
public static void main(String[] args) {  
   Process process =null;
             //chmod 777 有时需要给文件权限
              //备注 在Android上执行可能需要su权限
   String command1 = "md5sum "+ " /root/lin";//命令加路径
   try {
process = Runtime.getRuntime().exec(command1);//执行命令

InputStreamReader ips = new InputStreamReader(process.getInputStream());
   BufferedReader br = new BufferedReader(ips);
   String line;
   while ((line = br.readLine()) != null) {
System.out.println(line);
}
   } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Xshell启动java项目脚本(标本参考)

项目启动脚本

cp /opt/stpackage/aia-front.jar /opt/project/aia-front/webapps/aia-front.jar
cd /opt/project/aia-front/webapps
echo "init success begin start jar"
ps -ef|grep aia-front.jar|grep -v grep|awk '{print $2}'|xargs --no-run-if-empty kill -s 9
nohup java -Xms512m -Xmx512m -jar -DDEPLOY_ENV=rst /opt/project/aia-front/webapps/aia-front.jar &

此脚本是笔者纯手工打造,项目实战运用脚本

创建相对应的文件目录,可以双向修改,比较灵活

如果不设置日志路径,默认在与项目jar包并级存放

  • 脚本类型:start.sh

  • 启动命令:sh start.sh

  • 查看日志命名:tail -f(500) nohup.out    注:500可写可不写,加上500显示从当前往上推500行日志,不加就实时日志

来源:https://blog.csdn.net/fouling/article/details/88662642

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com