【发布时间】:2020-10-27 15:33:07
【问题描述】:
需要帮助!我已经编写了以下 Ubuntu 终端命令并生成输出。现在我想通过编写下面的 (.sh) 脚本检查来做同样的事情:
Ubuntu terminal command:
sudo journalctl | grep -E 'authentication failure' | grep -E 'testusr1' | more
Output:
Jul 05 13:44:56 khUbuntu su[20464]: pam_unix(su-l:auth): authentication failure; logname= uid=1000 euid=0 tty=pts/1 ruser=kh rhost= user=testusr1
Jul 05 14:56:44 khUbuntu su[23766]: pam_unix(su-l:auth): authentication failure; logname= uid=1000 euid=0 tty=pts/2 ruser=kh rhost= user=testusr1
然后我写了以下word.sh(shell脚本),但它没有像上面的终端命令那样生成任何输出,我写错了什么??
#!/bin/bash
# User input:
echo "Enter what you want to Search : "
read inputword
#userinput="authentication failure AND testusr1"
b=$(echo ${inputword%*AND*}) # remove AND from the inputword and get 'authentication failure'
length=${#b}
echo "$length" # get the length of b
removeBack1=${b%%*( )} #remove any white space from tail
length=${#removeBack1} #check length again to verify with the top lenth $b
echo "$length"
echo "This is 1st value:$removeBack1"
a=$(echo ${inputword#*AND}) # removing word AND from inputword and get 'testusr1'
length=${#a}
echo "$length"
removeBack2=${a%%*( )}
length=${#removeBack2}
echo "$length"
echo "This is 2nd value:$removeBack2"
## --- This is not generating any output -----------
sudo journalctl | grep -E '$removeBack1' | grep -E '$removeBack2' | more
【问题讨论】:
标签: linux bash shell ubuntu terminal