0

I am trying to execute the below command.

ssh node1 "nohup sleep 66 &; echo $!"

But I am getting the error:

-bash: !": event not found
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Ravikanth
  • 353
  • 1
  • 6
  • 17

2 Answers2

2

You should use single quotes to prevent interpretation of the $!:

ssh node1 'nohup sleep 66 &; echo $!'

It also looks like the ; isn't useful here. This seems to work:

ssh node1 'nohup sleep 66 & echo $!'
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0
ssh node1 'Pgrep -f sleep 66'

solved the issue

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Ravikanth
  • 353
  • 1
  • 6
  • 17
  • 1
    Please extend your answer: Why does your answer solve the question? – Artjom B. Jun 19 '15 at 13:05
  • storing the value of the above command in variable that will store the process id of sleep 66 . And we can check the process id status using variable anytime. The pupose of question was to store the process id of remote machine in variable. so we can use:1) ssh node1 `nohup sleep 66 &` 2) x(variable)=`ssh node1 'pgrep -f sleep 66' – Ravikanth Jun 24 '15 at 06:41