Fork me on GitHub
#off-topic
<
2017-10-23
>
qqq09:10:22

this writes to a local file

/bin/cat <<EOM >$FILE
text1
text2
text3
text4
EOM
Is there a way to write directly to a remote-file (that I can access via ssh), WITHOUT 1. writing file locally and 2. scp-ing it over ?

pesterhazy09:10:32

@qqq, of course. As a first approximation, cat | ssh remote.host tee out.file

qqq09:10:19

@pesterhazy turns out my actual problem is slightly different from what I described (running multi line ssh commands), and I ended up finding ssh [email protected] <<EOF ... EOF (originally was write script on remote, then run it, but turns out running multi line remote cmds is possible)

pesterhazy09:10:19

unfortunately quoting is a huge hassle with ssh

pesterhazy09:10:26

unix at its worst

pesterhazy09:10:50

probably better in almost all circumstances to scp a shell script and then execute it

qqq09:10:56

too bad https://scsh.net/ never took off

pesterhazy09:10:06

that's what ansible does for example

pesterhazy09:10:39

yeah I'm really intrigued by scsh

qqq09:10:37

port it to the lumo repl 🙂

pesterhazy09:10:50

believe me I've thought about it many times

pesterhazy09:10:11

but it's too big of a project, and lumo is not fast enough

qqq09:10:38

lumo vs planck -- which is the faster of the two ?

pesterhazy09:10:33

for a simple "println" - bash: 30ms, lumo: 250ms

pesterhazy09:10:56

it gets much slower if you add heavy macros like core.async

pesterhazy09:10:10

it's just not the right tool for building a shell unfortunately

qqq09:10:18

250ms I can tolerate, but if adding packages brings it to seconds, then it's hard to use

pesterhazy09:10:46

remember that shells use subshells for lots of things, so it adds up

pesterhazy09:10:01

it's kind of incredible there's no unix tool to "write stdin to file"

pesterhazy09:10:44

there's tee, which writes to the file passed as an arg but also to stdout (so you need to redirect to /dev/null)

pesterhazy10:10:25

there's bash -c 'cat>"$0"' but who can remember that??

joelgluth12:10:26

cat > filename ? Clearly I am missing something 😄

dominicm12:10:19

Yeah, that's just > file if you only want file. tee is for both.

pesterhazy13:10:28

@joelgluth right I buried the lede there. I'm thinking of contexts where a simple process call is needed (not a bash command). So for example, sudo echo aasdf > /etc/hosts won't work

pesterhazy13:10:33

but echo asdf | sudo tee /etc/hosts will, or echo asdf | sudo bash -c 'cat>"$0"' /etc/hosts

pesterhazy13:10:37

using bash as glue is not desirable in a lot of situations, especially because then you need to worry about quoting

eggsyntax14:10:43

Sounds like maybe you want process substitution. I just discovered it recently, and dang is it cool. http://wiki.bash-hackers.org/syntax/expansion/proc_subst

dominicm13:10:59

right, makes sense.

pesterhazy13:10:56

If only cat had a --out-file option!

pesterhazy13:10:25

dd of=my.fil would work I guess