Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using watch with ssh

I have the below commands which is running properly on the local machine.

watch -t -n1 "echo `date '+%Y-%m-%d %H:%M:%S'` | tee -a Time.txt" &>/dev/null &

But when I run it from the remote machine I won't create the expected output i.e. Time.txt is not created and will not be running as a background process.

ssh ipaddress watch -t -n1 "echo `date '+%Y-%m-%d %H:%M:%S'` | tee -a Time.txt" &>/dev/null &

Please help me on this. I have tried multiple options like putting ', " for watch command but it did not helped me out.

like image 374
sush Avatar asked Mar 07 '23 07:03

sush


1 Answers

  • No need to use echo to output the result of a sub shell.
  • No need to use tee to append to a file.
  • No need to use watch to sleep for one second.

Try this instead.

ssh -t ipaddress 'while sleep 1; do date +%Y-%m-%d\ %H:%M:%S >> Time.txt; done &'
like image 172
ceving Avatar answered Mar 16 '23 06:03

ceving