Linux下执行shell脚本
2015-10-14 00:00
351 查看
package com.lshop.common.util; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.lshop.html.action.InitIndexAction; public class ShellUtil { private static final Log logger = LogFactory.getLog(InitIndexAction.class); public static boolean ExeShell(String shellPath){ // String cmd = "/usr/bin/rsync -av /var/log/www.solive.kv/access_log testuser@10.0.1.219::store --password-file=/etc/client/rsync.pwd"; String cmd = "sh /www/www.itvpad.com/www/manager/synRes.sh"+; System.out.println(cmd); Runtime run = Runtime.getRuntime(); String result = ""; BufferedReader br=null; BufferedInputStream in=null; try { Process p = run.exec(cmd); if(p.waitFor() != 0){ result+="没有进程号"; return false; } in = new BufferedInputStream(p.getInputStream()); br = new BufferedReader(new InputStreamReader(in)); String lineStr; while ((lineStr = br.readLine()) != null) { result += lineStr; } } catch (Exception e) { e.printStackTrace(); return false; }finally{ if(br!=null){ try { br.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } logger.info("ShellUtil.ExeShell=>"+result); } return true; } }
相关文章推荐
- Shell Script不同运行方式的区别
- shell获取当前工作目录绝对路径
- :>/dev/null 2>&1 的作用
- Mysql Shell 日常管理命令查漏
- sudo: cd: command not found
- shell自学笔记2
- Bash 替换连续多个空格为一个
- 解决VMware8安装CentOS等系统时出现Fatal IO error 11(Resource temporarilt unavaliable) on Xshell:1问题
- lmgrd - License Server Manager Linux系统下遇到 bash: ./lmutil: No such file or directory
- shell正则表达式
- 在linux系统中的shell命令下如何访问一个url地址呢?
- shell命令之(一) 初探grep
- ShellExecute与ShellExecuteEx的用法
- #!/bin/bash
- Hbase shell
- shell数组和字典
- SHELL 示例
- grep 精确匹配与完全匹配
- PowerShell: 远程调用
- PowerShell: 隐藏明文密码