我写了一个小脚本,它将egrep
来自服务器日志的两个模式
pattern - 'Unable to resolve location classpath:db/migration|Processing PersistenceUnitInfo'
代码段
#/bin/sh
ssh tomcat@x.x.x.x egrep -e 'Unable to resolve location classpath:db/migration|Processing PersistenceUnitInfo' /usr/local/dd/logs/ddservice.log
执行结果
bash: Processing: command not found
grep: to: No such file or directory
grep: resolve: No such file or directory
grep: location: No such file or directory
grep: classpath:db/migration: No such file or directory
事实上,属于上述模式的关键字很少。如何修改脚本以获取模式。
答案 0 :(得分:1)
您必须使用搜索字符串中的\
来转义空格。
尝试
ssh tomcat@x.x.x.x egrep -e 'Unable\ to\ resolve\ location\classpath\:db/migration|Processing\ PersistenceUnitInfo' /usr/local/dd/logs/ddservice.log
答案 1 :(得分:0)
我在这里有几个假设:
这是可行的代码:
$ ssh username@somehost "egrep -e \"Unable to resolve location classpath:db/migration|Processing PersistenceUnitInfo\" /somepath/test.log"
Unable to resolve location classpath:db/migration
Processing PersistenceUnitInfo
然后:
$ cat 1.log
Unable to resolve location classpath:db/migration
Processing PersistenceUnitInfo