bash - exit code from ssh command -


i'm trying retrieve code return script:

#!/bin/bash echo "cm  1" ssh -i key/keyid.ppk user@x.x.x.x " grep blabla ddd if [ ! $? -eq 0 ]; exit 1; fi " echo $? 

but last command echo $? returns 0 instead of 1.

and if try run separately (not script) :

  • the ssh command: ssh -i key/keyid.ppk user@x.x.x.x
  • grep blabla ddd => msg "grep: ddd: no such file or directory"
  • then: if [ ! $? -eq 0 ]; exit 1; fi
  • then: echo $? => returns 1 expected

do have idea why doesn't work in script ?

thank you

this code

ssh -i key/keyid.ppk user@x.x.x.x " grep blabla ddd if [ ! $? -eq 0 ]; exit 1; fi " 

evaluates $? in shell , not in remote one, because $ not escaped in single quotes. should escape reach desired behaviour. once avoid evaluation in local shell, second time avoid evaluation when passed bash on remote side. or rather put command single quotes:

ssh -i key/keyid.ppk user@x.x.x.x ' grep blabla ddd if [ ! $? -eq 0 ]; exit 1; fi ' 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -