views:

226

answers:

4

I built a batch file from my windows machine that connects to a UNIX server. I Then want commands to execute in UNIX from the batch file. UNIX doesn't seem to recognize my commands after I am logged into the server. This is what I coded:

ssh SERVERNAME exit

Right now, I am just trying to make it log in and exit. I get logged into the server, but then the exit command does not execute. Does anyone know to make UNIX execute my commands after I'm logged in using this batch file?

+5  A: 

exit isn't being executed because it isn't a command, it's a shell internal (which exit if you don't believe me). Try echo hello world instead.

chaos
This is a good answer and could also be paraphrased as "try basic troubleshooting."
T Pops
ssh servername exit works perfectly fine for me.
innaM
+3  A: 

hi gerry, try:

ssh SERVERNAME 'exit'

you will probably end up with something such as:

ssh SERVERNAME 'bash some_remote_script.sh'

(replace bash with whatever shell you please)

im not sure why "chaos" keeps getting upvoted, his response has nothing to do whatsoever with the question. ssh SERVERNAME 'exit' works perfectly fine.

A: 

Take a look at section "7.3 Using Plink in batch files and scripts" at the plink documentation. That might do what you want.

wr
+3  A: 

Well, it seems to work for me, but try this:

ssh -t server command

You might just need the pseudo-tty allocated.

sharth