0

I want a shell script that connects to a server via ssh, starts watching a log, and then touches a file. It's important that I do them in that order, because I want to see in the log the effects of the second command. How do I write this? If I try something like:

ssh myserver tail -f /some/path/logfile &
ssh myserver touch /some/path/another-file
fg  # hoping to see the output of first command

I get error about "no job control in this shell".

Rob N
  • 101
  • 4

2 Answers2

1

The answer that @aviv-lo provided should work.

But few things that may fix your current method

  • Add set -m for job control
  • You might be also seeing an issue with your ssh client session is failing because it tries to use stdin.

Add -n to the backgrounded tail command. For good measure maybe also can add -T

#!/usr/bin/env bash
set -m
ssh -Tn myserver tail -f /var/log/messages &
ssh mysrever logger blah blah 
fg
nhed
  • 590
  • 1
  • 8
  • 14
0

What you might be able to do is that you create the shell script locally as it's like on the server and pipe it to the ssh client

cat shell_script.sh | ssh syntax_to_connect_to_the_server
Algo7
  • 297
  • 1
  • 8