i have thoroughly searched for an answer before asking my question. i searched google and stackoverflow for "stderr to function failed compare -file" i found on google these: http://mywiki.wooledge.org/BashPitfalls ,
Redirect stdout and stderr to Function ,
but none of them really answers my question. they focus on how to transfer the stderr correctly rather than how to compare the error string.
im having trouble to understand why the compare doesn't work and how to fix it.
also if the input to the function is not from stderr it compares successfully. if the input to the function does come from stderr of other command it compares successfully
im sorry but my question is very specific to these conditions so i don't know how many people will benefit from the answer (probably why i didn't find the answer myself)
and now to the question itself:
this is my function:
helpPrintError(){
read line
error='Pseudo-terminal will not be allocated because stdin is not a terminal.'
if [[ "$line" == "$error" ]]; then
:
else
echo -e "\e[31m\e[1m$line\e[0m"
fi
}
this is how i tried to make this work:
( cat $commandsFile | sshpass -p "$userPswrd" ssh -o StrictHostKeyChecking=no admin@${mainIP} > $resultsFile ) 2>&1 | helpPrintError
well it's only one way i tried to solve this. i tried in many other ways.
result:
Pseudo-terminal will not be allocated because stdin is not a terminal.
problem and intent: i want to see (in bold red) any error messages that are not: "Pseudo-terminal will not be allocated because stdin is not a terminal."
problem is i fail to filter the error message time after time. i tried alot of variations to solve it but no success.
additional backgroung:
in $commandsFile i have commands for the ssh server to execute.
i have no control over the ssh server keys so i use sshpass and connect with $userPswd and $mainIP
results of the commands executed on the server are (to be) written to $resultsFile
any error messages from ssh attempts are to be filtered as in the function (one error message type is not to be seen.others are to be shown in bold red)
i tried the -t -t option on ssh but thats just messing my commands results
any suggestions and solutions will be welcome and appreciated!