linux - bash: what to do when stdout does not exist -


in simplified scenario, have script looks this:

mv test _test sleep 10 echo $1 mv _test test 

and if execute with:

ssh localhost "test.sh foo" 

the test file have underscore in name long script running, , when script finished, send foo back. script should keep running, if terminate ssh command pressing ctrl+c or if lose connection the server, doesn't (the file not renamed "test"). so, tried following:

nohup ssh localhost "test.sh foo" 

and makes ssh immune ctrl+c flaky connection server still causes trouble. after debugging, turns out script reach end if there no echo in it. , when think it, makes sense - when connection dropped, there no more stdout (ssh socket) echo to, fail, silently.

i can, of course, echo file , file, prefer smarter, along lines of test tty && echo $1 (but tty invoked returns false). suggestions appreciated.

the following command want:

ssh -t user@host 'nohup ~/test.sh foo > nohup.out 2>&1 & p1=$!; tail -f ~/nohup.out & wait $p1' 

... test.sh located in users home directory

explanation:

1.) "ssh -t user@host " ... pretty clear ... starts remote session
2.) "nohup ~/test.sh foo > nohup.out 2>&1" ... starts test.sh script nohup in background
3.) "p1=$!;" ... stores child pid of previous command in p1
4.) "tail -f ~/nohup.out &" ... tail nohup.out in background see output of test.sh
5.) "wait $p1" ... waits proccess test.sh (which pid stored in p1) finish

the above command works if interrupt ctrl+c.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -