I am trying to monitor the changes of a file via SSH and copy the changes of it in local computer using BASH. I ran the following command to monitor and copy:

```
ssh root@192.168.88.238 "tail -F /media/sdcard/SA000001.log"> ~/Desktop/Modem.log

```

Which works perfectly. But then it keeps running. I want to terminate the tail and the ssh after certain period (Or when a certain string is found).

I tried the following command, but it didn't work:

```
ssh -t root@192.168.88.238 "tail -F /media/sdcard/SA000001.log && sleep 10 && exit"> ~/Desktop/Modem.log

```

I also tried passing `exit` and the ASCII value of `CTRL+C` via echo, but was unable to end/kill the tail and ssh. 

Then I tried the following:

```
#!/bin/sh 

ssh -t root@192.168.88.238 "tail -F /media/sdcard/SA000001.log | while read TEMPLOGLINE"> ~/Desktop/Modem.log

do
   [[ "${TEMPLOGLINE}" == *"temp"* ]] && pkill -P $$ tail
done

exit

```

I have also tried this:

```
#!/bin/sh 

ssh -t root@192.168.88.238 "tail -F /media/sdcard/SA000001.log"> ~/Desktop/Modem.log

ssh -t root@192.168.88.238 "/X03"
ssh -t root@192.168.88.238 "exit"

```

Here is my bash file at this moment:

```
#!/bin/sh 

ssh -t root@192.168.88.238 "tail -F /media/sdcard/SA000001.log"> ~/Desktop/Modem.log

```

Any suggestions on how I should proceed with this?

Thanks in advance.