【问题标题】:Write a shell script with find, cat and if用 find、cat 和 if 编写一个 shell 脚本
【发布时间】:2012-12-29 18:37:16
【问题描述】:

我正在做一个 scipt 来搜索一个有年龄的日志文件,并比较日志中谁有一个文本字符串,如果继续执行函数是正确的,但没有影响。我感谢任何建议或帮助

#!/bin/bash
file= find /AUX/backup/log/ -iname "*.log" -daystart -type f -mtime 1
if cat $file | grep -qw “INF - Status = completed."  
then
  echo "there is OK" 
else
  echo "there is KO" 
fi

【问题讨论】:

    标签: shell if-statement grep cat


    【解决方案1】:
    #!/bin/bash
    file=`find /AUX/backup/log/ -iname "*.log" -daystart -type f -mtime 1`
    if grep -qw “INF - Status = completed."  < $file
    then
      echo "there is OK" 
    else
      echo "there is KO" 
    fi
    

    【讨论】:

    • 请也添加解释,很难发现添加的`字符...(即使有语法高亮...)
    猜你喜欢
    • 2012-08-22
    • 2020-07-22
    • 1970-01-01
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多