Search in logfile

I have some legacy softwares that I need to automate under Control-M. These job are under Windows 2008R2. These jobs have an exit code 0 if they run ok, but also if they can manage some errors. I need to raise an alarm when a specific string is in the log. The string is not in the output of executable. I implemented another job for this. It goes to search a string inthe file and in "

在日志文件中搜索

我有一些传统软件需要在Control-M下自动运行。 这些工作都在Windows 2008R2之下。 如果它们运行正常,这些作业的退出代码为0,但是如果它们可以管理一些错误。 当特定的字符串在日志中时,我需要发出警报。 该字符串不在可执行文件的输出中。 我为此执行了另一项工作。 它会搜索文件中的字符串,然后在“执行操作”中搜索该语句。 要在输出中声明我认为使用类似grep的东西。 我用了: findstr findstr "myerrorcode"

Unix shell script find out which directory the script file resides?

基本上我需要使用与脚本文件位置相关的路径运行脚本,如何将当前目录更改为脚本文件所在的同一目录? 在Bash中,你应该得到你需要的这样的东西: #!/usr/bin/env bash BASEDIR=$(dirname "$0") echo "$BASEDIR" The original post contains the solution (ignore the responses, they don't add anything useful). The interesting work is done by the mentioned unix command readlink with option -f . Works when the

Unix shell脚本找出脚本文件所在的目录?

基本上我需要使用与脚本文件位置相关的路径运行脚本,如何将当前目录更改为脚本文件所在的同一目录? 在Bash中,你应该得到你需要的这样的东西: #!/usr/bin/env bash BASEDIR=$(dirname "$0") echo "$BASEDIR" 原始帖子包含解决方案(忽略响应,他们不添加任何有用的东西)。 有趣的工作是由提到的带选项-f unix命令readlink完成的。 当脚本被绝对以及相对路径调用时起作用。 对于bash,sh,ksh: #!/bin/bash # Absolute

ExitCodes bigger than 255, possible?

If yes, on which operating system, shell or whatever? Consider the following java program (I'm using java just as an example, any language would be good for this question, which is more about operation systems): public class ExitCode { public static void main(String args[]) { System.exit(Integer.parseInt(args[0])); } } Running it on Linux and bash, it returns always values

ExitCodes大于255,可能吗?

如果是的话,在哪个操作系统,shell或其他? 考虑下面的java程序(我只是用java作为例子,任何语言都适合这个问题,这更多的是关于操作系统): public class ExitCode { public static void main(String args[]) { System.exit(Integer.parseInt(args[0])); } } 在Linux和bash上运行它,它总是返回小于等于255的值,例如( echo $?打印先前执行的命令的退出代码) > java ExitCode 2; echo $? 2 > j

How can I check the version of sed in OS X?

I know if sed is GNU version, version check can be done like $ sed --version But this doesn't work in OS X. How can I do that? This probably isn't the answer you're looking for, but you can't. Mac OS X sed has no option to show the version number. There is not even a version number in the binary: $ strings $(which sed) $FreeBSD: src/usr.bin/sed/compile.c,v 1.28 2005/08/04

我如何检查OS X中的sed版本?

我知道如果sed是GNU版本,版本检查可以像做一样 $ sed --version 但是这在OS X中不起作用,我该怎么做? 这可能不是你正在寻找的答案,但你不能。 Mac OS X sed无法显示版本号。 二进制文件中甚至没有版本号: $ strings $(which sed) $FreeBSD: src/usr.bin/sed/compile.c,v 1.28 2005/08/04 10:05:11 dds Exp $ $FreeBSD: src/usr.bin/sed/main.c,v 1.36 2005/05/10 13:40:50 glebius Exp $ $FreeBSD: src/usr.bin/sed/

cp command should ignore some files

Sometimes I need to perform following command cp -rv demo demo_bkp However I want to ignore all the files in directory .git . How do I achieve that? It takes a long time to copy .git files and I do not need those files. To ignore a git directory specifically, I'd try git export first. But in general, to copy a directory tree excluding certain files or folders, I'd recommend using

cp命令应该忽略一些文件

有时我需要执行以下命令 cp -rv demo demo_bkp 但是我想忽略目录.git中的所有文件。 我如何实现这一目标? 复制.git文件需要很长时间,我不需要这些文件。 要特别忽略一个git目录,我会先尝试git export 。 但一般来说,要复制一个不包含某些文件或文件夹的目录树,我建议使用rsync而不是cp 。 语法大多相同,但rsync有更多选择,其中包括一个用于排除选定文件的选项: rsync -rv --exclude=.git demo demo_bkp 请参

How to add timestamp to STDERR redirection

In bash/ksh can we add timestamp to STDERR redirection? Eg myscript.sh 2> error.log I want to get a timestamp written on the log too. If you're talking about an up-to-date timestamp on each line, that's something you'd probably want to do in your actual script (but see below for a nifty solution if you have no power to change it). If you just want a marker date on its own li

如何将时间戳添加到STDERR重定向

在bash / ksh中,我们可以添加时间戳到STDERR重定向吗? 例如myscript.sh 2> error.log 我想获得写在日志上的时间戳。 如果您正在讨论每行最新的时间戳,那么您可能希望在您的实际脚本中执行此操作(但如果您无权更改它,请参阅下面的解决方案)。 如果你只想在你的脚本开始写之前在自己的行上设置一个标记日期,我会使用: ( date 1>&2 ; myscript.sh ) 2>error.log 你需要的是通过另一个可以为每行添加

What is the use of 2>&1 in shell scripting

This question already has an answer here: In the shell, what does “ 2>&1 ” mean? 15 answers The short answer is you are redirecting stderr to stdout so you get both error messages written to FD2 as well as normal output on FD1 written to FD1 . (FD = File Descriptor). It generally allows you to capture the output of error messages you want to save in a log file, etc.. that would othe

在shell脚本中使用2>&1有什么用处

这个问题在这里已经有了答案: 在shell中,“2>&1”是什么意思? 15个答案 简短的回答是,您将stderr重定向到stdout以便您将写入FD2错误消息以及FD1上的正常输出写入FD1 。 (FD =文件描述符)。 它通常允许您捕获想要保存在日志文件中的错误消息的输出等。否则,仅通过将stdout重定向到日志就不能捕获这些错误消息。 通过简短的背景介绍,您的shell有3个众所周知的文件描述符,涵盖基本的读写操作: 0 - stdin(

What does 1>&2 mean in shell?

This question already has an answer here: echo that outputs to stderr 13 answers In the shell, what does “ 2>&1 ” mean? 15 answers That redirects the line "This script must be run as root" from standard out (STDOUT) to standard error output (STDERR). It's a easy way to print an error message to STDERR - this matters if you run the bash script from another script (lik

1>&2在shell中的含义是什么?

这个问题在这里已经有了答案: 回应输出到标准错误13答案 在shell中,“2>&1”是什么意思? 15个答案 将标准输出(STDOUT)到标准错误输出(STDERR)的重定向行“此脚本必须以root身份运行”。 这是向STDERR打印错误消息的简单方法 - 如果从另一个脚本(如crontab)运行bash脚本,这很重要,如果从命令行直接运行bash脚本,则由于终端将同时显示STDOUT和STDERR,这一点很重要。 另请参见将输出回显到stderr

${1:+"$@"} in /bin/sh

I've noticed that sometimes wrapper scripts will use ${1:+"$@"} for the parameters rather than just "$@" . For example, http://svn.macosforge.org/repository/macports/trunk/dports/editors/vim-app/files/gvim.sh uses exec "$binary" $opts ${1:+"$@"} Can anyone break ${1:+"$@"} down into English and explain why it would be an advantage over plain "$@" ?

/ bin / sh中的$ {1:+“$ @”}

我注意到有时包装脚本将使用${1:+"$@"}作为参数,而不仅仅是"$@" 。 例如,http://svn.macosforge.org/repository/macports/trunk/dports/editors/vim-app/files/gvim.sh使用 exec "$binary" $opts ${1:+"$@"} 任何人都可以将${1:+"$@"}分解为英文,并解释为什么它比纯"$@"更具优势? '歇斯底里葡萄干',又名历史原因。 JesperE(或Bash手册页)的解释对于它的作用是准

How to check if a file exists in a shell script

I'd like to write a shell script which checks if a certain file, archived_sensor_data.json , exists, and if so, deletes it. Following http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html, I've tried the following: [-e archived_sensor_data.json] && rm archived_sensor_data.json However, this throws an error [-e: command not found when I try to

如何检查文件是否存在于shell脚本中

我想编写一个shell脚本来检查某个文件archived_sensor_data.json是否存在,如果是,则删除它。 遵循http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html,我试过以下内容: [-e archived_sensor_data.json] && rm archived_sensor_data.json 但是,这会引发错误 [-e: command not found 当我尝试使用./test_controller命令运行生成的test_controller脚本时。 代码有什么问