- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里遇到了如此奇怪的行为。
我有以下方法:
public static void loadMonitorsFromCron(){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
File ism_dir = new File("/var/app/ism/");
String line = "/usr/bin/ksh /var/app/ism/ism_check_cron.ksh";
CommandLine commandLine = CommandLine.parse(line);
try {
DefaultExecutor exec = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
exec.setWorkingDirectory(ism_dir);
exec.setStreamHandler(streamHandler);
exec.execute(commandLine);
} catch (ExecuteException e1) {
System.out.println("ERROR: "+e1.getMessage());
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
System.out.println("ERROR: "+e1.getMessage());
// TODO Auto-generated catch block
e1.printStackTrace();
}
String[] paths = outputStream.toString().split("\n");
System.out.println("Paths: ");
for(int i=0;i<paths.length;i++)
System.out.println(paths[i]);
loadErrorCodeFromPath(paths);
}
这是我正在尝试执行的脚本:ism_check_cron.ksh:
#!/usr/bin/ksh
echo "inbound_monitor.ksh"
echo "$(crontab -l | grep ism | grep -v '#' | cut -d ' ' -f 6 | cut -d '/' -f 5)"
echo "ism_heapdump.ksh"
当我查看 systemOut 的输出时,我只看到:
SystemOut O Paths:
SystemOut O inbound_monitor.ksh
SystemOut O
SystemOut O ism_heapdump.ksh
crontab -l 应该列出许多其他字符串,如上面的字符串,但如您所见,我通过 Java 没有得到任何结果。
如果我在 Linux 终端中执行脚本,它就可以正常工作。由于 Java 可以执行脚本的“某些部分”,我也认为该方法也很好。所以我完全迷失了。有什么提示吗?
========更新=========
问题已解决,以后的读者可以引用下面的评论。
最佳答案
执行不带 -u 选项的 crontab -l 将仅列出当前用户的 crontab 条目。
解决方案是使用 -u 参数指向实际用户:
echo "$(crontab -u myuser -l | grep ism | grep -v '#' | cut -d ' ' -f 6 | cut -d '/' -f 5)"
第二个解决方案是为正在运行 java 程序的用户添加所有 crantab 条目,并从不需要它们的用户中删除条目。
关于Java 不会使用 Apache commons exec 执行 shellscript 中的所有命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39733610/
这个问题在这里已经有了答案: What does the $# construct mean in bash? [duplicate] (3 个答案) 关闭 7 年前。 我有一个包含以下几行的 sh
如何在shell脚本中将字符串拆分为数组? 我试过 IFS='delimiter'它适用于循环 (for, while)但我需要一个来自该字符串的数组。 如何从字符串创建数组? 谢谢! 最佳答案 st
我的 shellscript 不工作: #!/bin/bash LIST="$(ls -rt *.log.*)" for i in "$LIST"; do echo $i mysql --user=
这个问题在这里已经有了答案: Why would a correct shell script give a wrapped/truncated/corrupted error message? [
我有一个列表,例如: 10、汽车轮胎 8、汽车轮胎 4、轮子 18、 pry 棍 5、插孔 5、插孔 8、 jack 斯 第一个数字是数量,第二个数字是商品名称。我需要获取此列表,以便它只显示每个项目
我正在尝试检查文件是否超过 5 分钟,如果是这种情况,我想调用另一个 shell 脚本,它会向我发送邮件。 检查文件.sh: #!/bin/sh if [$(( (`date +%s` - `stat
我有名为“images123.jpg”、“images456.jpg”等的文件 我想将这些文件 mv 到 testfolder 文件夹中,并相应地将它们重命名为“123.jpg”、“456.jpg”等
我正在尝试编写一个简单的 shell 脚本,如果有第一个参数则打印出第一个参数,如果没有则打印“无”。该脚本名为 test.sh if [$1 = ""] then e
我正在使用此命令将文件导入我的服务器: scp zumodo@shold:/test/test/test/server.py /test/test/test/test.py~/; 如果新导入的文件 t
我正在尝试使用正则表达式编写一个 bashscript 检查来区分以下文件。我试图在 if 语句中选择 DRLIC_INFO_20170912.out 而不是 DRLIC_INFO_20170912_
我想通过 shell 脚本对系统间缓存执行一些命令。我知道的一种解决方案是制作配置文件,但问题是我不知道如何通过 shell 脚本使用配置文件。有没有其他解决方案... 例如我必须在缓存上运行的是 c
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我正在尝试在 bash 中创建我的第一个 shell 脚本。我已经创建了代码,并设法将脚本保存在我的主目录中,但它无法运行。首先,我尝试从主目录运行它:./testscript.sh,并以“权限被拒绝
我一直试图让我的脚本在每天早上 6:01 运行。 脚本获取数据并将其输出到如下所示的 .xml 文件。 #!/bin/sh tv_grab_se_swedb --days 1 --quiet --ou
我正在尝试通过像这样非常简单的 bash 脚本来激活我的 pyenv-virtualenv 环境。 set -e pyenv activate myenv 但我无法激活我的环境并出现以下错误: Fai
我正在尝试制作一个执行以下操作的 shell 脚本: 启动程序 x 在 x 运行时执行一些命令,例如: echo "blabla" >> ~/blabla.txt 执行这些命令后,程序 x 应该在前台
这个问题已经有答案了: Propagate all arguments in a Bash shell script (12 个回答) 已关闭 4 年前。 从一个shell脚本中,我想调用一个调用ja
现在我对 shell 脚本和 Linux 本身还很陌生,我很困惑为什么这不起作用。解释和答案会很有帮助,因为我真的很想学习这个。无论如何,这是我的代码: #!/bin/bash
我们想从 XML 文件中读取 XML 属性。文件内容示例如下: 我们想使用 shell 脚本读取属性“abc”的值(即 15)。 请建议 shell 命令来实现这一点。 最佳答案 您可
您可以在下面看到我尝试使用 shell 脚本更改 umask,并被对话框覆盖。 基本上,我将输入框的输入读取到一个变量中,然后使用它通过 umask 执行它以最终更改它。但是.. 它不起作用.. 我取
我是一名优秀的程序员,十分优秀!