Reputation: 1642
I want to capture output of the following command in a shell script:
echo "User-Name=root,User-Password=root123" | radclient 192.168.19.104 auth testing123
I have a shell script as follows:
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).
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.
Upvotes: 2
Views: 1342
Reputation: 1289
You can store the output in a variable like this:
OUTPUT=$(echo "User-Name=root,User-Password=root123" | radclient $ip auth $key)
echo "$OUTPUT"
Upvotes: 2