4

I run a remote script using ssh:

local script:

local_command
ssh -p 222 user@server 'sh -s' < ./remote_run.sh

remote script:

some_command & 
sleep 10000
trap 'echo exiting' SIGINT SIGTERM SIGABRT SIGKILL EXIT

I need a trap on remote script for cleaning up (kill running processes and remove files). But used approach does not work.

Any suggestions?

Dmitry Eskin
  • 141
  • 4

1 Answers1

0

Tried and worked like charm.

ssh -p 222 user@server "nohup ./remote_run.sh"

and in remote_run.sh

some_command &
sleep 10000
ps -aux | grep "[r]emote_run.sh" | awk '{print $2}' | xargs kill -9
#killed

obviously, the script is transferred to remote host first. :)

Thomas
  • 6,242
  • 8
  • 26
  • 32