SEnding a process to backgorund (&) in here document

Trying to do the following

ssh root@192.168.0.111 'bash -s' <<ENDSSH
mkfifo a.pipe
gzip -c < a.pipe > aa.gzip &

ENDSSH

it does not seems to be able to send the gzip process to background.

I suspect that your problem is that there is no command with the name bash -s rather than that gzip isn't run in the background.

Try:

bash <<ENDSSH
mkfifo a.pipe
gzip -c < a.pipe > aa.gzip &
ENDSSH

instead and see if you get what you wanted.

If there is some reason why you think you need to invoke bash with the -s option to run this here document (even though that doesn't make any sense to me for this set of commands), at least drop the single quotes.

And if your current shell is bash (or any other shell that uses Bourne shell syntax), the following will do the same thing without the complexity of starting a new shell and having it read commands from a here-document:

mkfifo a.pipe
gzip -c < a.pipe > aa.gzip &

Thanks for your reply.

Actually this is what i am doing.

#!/bin/ksh
FILE="a.pipe"
DS="DS1"
TIMESTAMP="TS"

ssh root@192.168.0.112 'ksh' <<ENDSSH
  # commands to run on remote host

for i in {1..8}
do
if [[ ! -e $DS\_$TIMESTAMP\_\$i.pipe ]]
then
mkfifo $DS\_$TIMESTAMP\_\$i.pipe
fi

gzip -c \< $DS\_$TIMESTAMP\_\$i.pipe \> $DS$TIMESTAMP\$i.gz &

done

ENDSSH

I am trying to trigger this script to a remote server to setup 8 pipe for 'on the fly' compression. I'm always getting

[root@twslinux1 ~]# ./a.sh
gzip: <: No such file or directory                                                                                           �D\QDS1_TS_1.pipegzip: >: No such file or directory
gzip: DS1TS1.gz: No such file or directory
gzip: &: No such file or directory
gzip: <: No such file or directory                                                                                           �D\QDS1_TS_2.pipegzip: >: No such file or directory
gzip: DS1TS2.gz: No such file or directory
gzip: &: No such file or directory
gzip: <: No such file or directory                                                                                           �D\QDS1_TS_3.pipegzip: >: No such file or directory
gzip: DS1TS3.gz: No such file or directory
gzip: &: No such file or directory
gzip: <: No such file or directory                                                                                           9J\QDS1_TS_4.pipegzip: >: No such file or directory
gzip: DS1TS4.gz: No such file or directory
gzip: &: No such file or directory
gzip: <: No such file or directory                                                                                           9J\QDS1_TS_5.pipegzip: >: No such file or directory
gzip: DS1TS5.gz: No such file or directory
gzip: &: No such file or directory
gzip: <: No such file or directory                                                                                           9J\QDS1_TS_6.pipegzip: >: No such file or directory
gzip: DS1TS6.gz: No such file or directory
gzip: &: No such file or directory                                                                                           9J\QDS1_TS_7.pipegzip: <: No such file or directory
gzip: >: No such file or directory
gzip: DS1TS7.gz: No such file or directory
gzip: &: No such file or directory                                                                                           9J\QDS1_TS_8.pipegzip: <: No such file or directory
gzip: >: No such file or directory
gzip: DS1TS8.gz: No such file or directory
gzip: &: No such file or directory
[root@twslinux1 ~]# vi a.sh
[root@twslinux1 ~]# ./a.sh                                                                                                   �D\QDS1_TS_1.pipegzip: <: No such file or directory
gzip: >: No such file or directory
gzip: DS1TS1.gz: No such file or directory

Replace ssh root@192.168.0.112 'ksh' with cat so you can see exactly what values the here-document ends up with, and paste its output here in code tags please.

You don't need to escape < > . You do need to escape $ unless you want them substituted with local variables "right now".

You should use ${braces} for variables instead of separating them with \ too.