Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.
typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "
  $(cat);
  IFERROR=$(checkscript);
  echo "$IFERROR"" > ${SSHTEMPFILE} 2>&1    

This line...I can't exclude the "user authorized" message from the ssh...IFERROR returns the values I need to track, but also, the "!!! AUTHORIZED USE ONLY !!!" horrible message from the ssh... Already tried something like this, but its not working:

typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "
  $(cat);
  IFERROR=$(checkscript);
  echo "$IFERROR"" | grep -v "AUTHORIZED"  > ${SSHTEMPFILE} 2>&1    
share|improve this question

2 Answers 2

The message you try to exclude is likely a ssh banner. This one is displayed on stderr, that's why the grep -v doesn't work in your script.

Just try to redirect stderr to stdin before the grep. It should work. I don't really understand your command, but it would look like this:

typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "$(cat); IFERROR=$(checkscript); echo "$IFERROR"" 2>&1 | grep -v "AUTHORIZED" > ${SSHTEMPFILE}

PS: What's the purpose of $(cat) ?

share|improve this answer

I'm not sure what you're trying to do, but there's at least one obvious mistake in your script. You have

ssh "$(cat); …"$IFERROR"" | …

The fragment $IFERROR is not inside quotes, it is expanded by the local shell in order to build the SSH command that is executed. You want to execute echo "$IFERROR" on the remote side, so you need to quote the $ to prevent it from being expanded locally:

typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "
  $(cat);
  IFERROR=$(checkscript);
  echo \"\$IFERROR\"" > ${SSHTEMPFILE} 2>&1

The checkscript command is also executed locally. If you meant for it to be executed remotely, change IFERROR=$(checkscript) to IFERROR=\$(checkscript).

You don't need to store the output of checkscript in a variable. You can, but it made your life more complicated for no benefit. Just get its output directly.

typeset -f |
sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "$(cat); checkscript" > ${SSHTEMPFILE} 2>&1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.