I want to capture output of the following command in a shell script:
我想在shell脚本中捕获以下命令的输出:
echo "User-Name=root,User-Password=root123" | radclient 192.168.19.104 auth testing123
I have a shell script as follows:
我有一个shell脚本,如下所示:
FILE=server
while IFS="\t" read -r ip key;
do
case "$ip" in
"0.0.0.0") continue ;;
esac
echo "User-Name=root,User-Password=root123" | radclient $ip auth $key
done < "$FILE"
exit 1
Edit: Removed the extra quotes and it works.
编辑:删除多余的引号,它可以工作。
Now, Upon running the command:
现在,运行命令:
echo "User-Name=root,User-Password=root123" | radclient 192.168.19.104 auth testing123
It returns following output: (Actually the radclient returns the following output).
它返回以下输出:(实际上radclient返回以下输出)。
Received response ID 1, code 2, length = 33
Reply-Message = "Hello, root"
How to capture output from the command.
如何从命令捕获输出。
Edit: As per Answer below I used:
编辑:按照我下面的回答:
OUTPUT=`echo "User-Name=$username,User-Password=$passwd" | radclient $ip auth $key`
This captures returned string in OUTPUT. However it also prints the output on screen.
它在输出中捕获返回的字符串。不过,它也会在屏幕上打印输出。
How can we suppress output of radclient from printing on screen as well as store the ouput in OUTPUT.
如何抑制radclient在屏幕上的打印输出,并将输出存储在输出中。
1 个解决方案
#1
2
You can store the output in a variable like this:
可以将输出存储在如下变量中:
OUTPUT=$(echo "User-Name=root,User-Password=root123" | radclient $ip auth $key)
echo "$OUTPUT"
#1
2
You can store the output in a variable like this:
可以将输出存储在如下变量中:
OUTPUT=$(echo "User-Name=root,User-Password=root123" | radclient $ip auth $key)
echo "$OUTPUT"