0

I want to run script B on machine B by a call from script A on machine A that is run by crontab on regular interval. I'm not a unix user myself and after looking at similar questions, couple things are confusing to me.

  1. Are single quotes necessary because I see they're sometimes used but sometimes not used.

    ssh user@host './path/foo.sh'
    ssh user@host foo.sh
    
  2. If I want to use variables will this work:A.sh:

    path="some/path"
    ssh user@host @path/foo.sh
    

    or do I need to put them in single quotes?

  3. Is password always needed? The answers at how to run a script file remotely using ssh had no mention of passwords at all, so I was wondering if there are types of scripts that require password and those that don't. Since my script will have to run on schedule, I would need to automate the authentication process. I found several solutions that involve expect scripts, key-pair authentication. But some answers that have no mention of passwords have me questioning whether if they're necessary at all.
l0b0
  • 55,365
  • 30
  • 138
  • 223
dono
  • 149
  • 1
  • 4
  • 16
  • These are two/three orthogonal questions. I would suggest moving the last one to a separate question (although you will definitely find answers here and on unix.stackexchange.com about passwordless ssh). – l0b0 Feb 14 '19 at 09:26
  • Possible duplicate of [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – l0b0 Feb 14 '19 at 09:30

1 Answers1

1
  1. Single quotes are only necessary if the string contains special characters, most notably spaces. Almost anything inside single quotes is interpreted literally by the shell.

  2. Variables are expanded using $, not @, but you cannot use it inside single quotes, so you are better off using double quotes for that. Those still protect against spaces, but allow for $ expansion:

    path="some/path"
    ssh user@host "$path/foo.sh"
    
  3. To ssh to a remote machine, you typically use either a password or a keypair. For automation, a keypair is pretty much your only option, because you don't want to store the password in plain text anywhere and ssh makes it difficult to input it from a file anyway.

Thomas
  • 174,939
  • 50
  • 355
  • 478