Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: How to execute commands on a server through a script on my computer?

Posted on 2007-06-06 18:40:01 by pod69

Hello

I want to write a script that executes some commands on a server -
therefore i generated some keys - so i can connect to the server
without a password. The problem is now i can do ssh user@host /bin/
date and transfer files with scp but i dont know how to execute
specific commands on the servers shell because i need some environment
variables - I need the servers environment? thx for any help and info!

thx p=E4ttr

Report this message

#2: Re: How to execute commands on a server through a script on mycomputer?

Posted on 2007-06-06 18:57:08 by Icarus Sparry

On Wed, 06 Jun 2007 09:40:01 -0700, pod69 wrote:

> Hello
>
> I want to write a script that executes some commands on a server -
> therefore i generated some keys - so i can connect to the server without
> a password. The problem is now i can do ssh user@host /bin/ date and
> transfer files with scp but i dont know how to execute specific commands
> on the servers shell because i need some environment variables - I need
> the servers environment? thx for any help and info!
>
> thx pättr

For simple cases, where there are no difficult quoting characters in the
variable names, and if you have a "sh" family login shell, you can do

ssh user@host VAR1="$VAR1" VAR2="$VAR2" /bin/date

to set the environment variables VAR1 and VAR2 on the remote machine to
be the same as they are on the local machine.

You should also read your manual page for ssh, to see if it supports
~/.ssh/environment in the same way that openssh does.

Let us know if you need anything more complicated.

Report this message

#3: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-06 19:36:34 by pod69

On Jun 6, 6:57 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
> On Wed, 06 Jun 2007 09:40:01 -0700, pod69 wrote:
> > Hello
>
> > I want to write a script that executes some commands on a server -
> > therefore i generated some keys - so i can connect to the server without
> > a password. The problem is now i can do ssh user@host /bin/ date and
> > transfer files with scp but i dont know how to execute specific commands
> > on the servers shell because i need some environment variables - I need
> > the servers environment? thx for any help and info!
>
> > thx p=E4ttr
>
> For simple cases, where there are no difficult quoting characters in the
> variable names, and if you have a "sh" family login shell, you can do
>
> ssh user@host VAR1=3D"$VAR1" VAR2=3D"$VAR2" /bin/date
>
> to set the environment variables VAR1 and VAR2 on the remote machine to
> be the same as they are on the local machine.
>
> You should also read your manual page for ssh, to see if it supports
> ~/.ssh/environment in the same way that openssh does.
>
> Let us know if you need anything more complicated.



ok - i guess i have to set the environment variables again - there is
no other way to just use the environment on the server?


is there a way to connect to the server and see whats going on and
then exit?

e=2Eg ssh user@host -> executes some comands -> exit - so that i see on
the console whats going on and then go back to my home?

thx

Report this message

#4: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-06 20:19:28 by Rich Grise

On Wed, 06 Jun 2007 10:36:34 -0700, pod69 wrote:
> On Jun 6, 6:57 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
>> On Wed, 06 Jun 2007 09:40:01 -0700, pod69 wrote:
>>
>> > I want to write a script that executes some commands on a server -
>> > therefore i generated some keys - so i can connect to the server without
>> > a password. The problem is now i can do ssh user@host /bin/ date and
>> > transfer files with scp but i dont know how to execute specific commands
>> > on the servers shell because i need some environment variables - I need
>> > the servers environment? thx for any help and info!
>>
>> For simple cases, where there are no difficult quoting characters in the
>> variable names, and if you have a "sh" family login shell, you can do
>>
>> ssh user@host VAR1="$VAR1" VAR2="$VAR2" /bin/date
>>
>> to set the environment variables VAR1 and VAR2 on the remote machine to
>> be the same as they are on the local machine.
>>
>> You should also read your manual page for ssh, to see if it supports
>> ~/.ssh/environment in the same way that openssh does.
>>
>> Let us know if you need anything more complicated.
>
> ok - i guess i have to set the environment variables again - there is
> no other way to just use the environment on the server?

It should do that anyway.

> is there a way to connect to the server and see whats going on and
> then exit?
>
> e.g ssh user@host -> executes some comands -> exit - so that i see on
> the console whats going on and then go back to my home?

Sure. Just like you said, and the command
# set
will dump the whole environment to stdout.

Good Luck!
Rich

Report this message

#5: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-06 20:54:20 by Bill Marcum

On Wed, 06 Jun 2007 10:36:34 -0700, pod69@gmx.net
<pod69@gmx.net> wrote:
>
>
>
> is there a way to connect to the server and see whats going on and
> then exit?
>
> e.g ssh user@host -> executes some comands -> exit - so that i see on
> the console whats going on and then go back to my home?
>
ssh user@host "some command"
or
ssh user@host <<END
command1
command2
....
END


--
Murray's Rule:
Any country with "democratic" in the title isn't.

Report this message

#6: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-06 21:56:04 by pod69

i tried now to execute a script which exports all my variables - i
thought it should work but it doesnt and i dont know why?

Report this message

#7: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-06 22:03:40 by Ed Morton

pod69@gmx.net wrote:

> i tried now to execute a script which exports all my variables - i
> thought it should work but it doesnt and i dont know why?
>

You're probably not using ". " in front of it. If you posted a screen
snapshot of what you're doing and the output you're getting, we'd have a
better idea how to help you.

Ed.

Report this message

#8: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-07 02:13:55 by Glenn Jackman

At 2007-06-06 01:36PM, "pod69@gmx.net" wrote:
> ok - i guess i have to set the environment variables again - there is
> no other way to just use the environment on the server?
>
> is there a way to connect to the server and see whats going on and
> then exit?
>
> e.g ssh user@host -> executes some comands -> exit - so that i see on
> the console whats going on and then go back to my home?

Compare:
ssh user@host env
with
ssh user@host '. ~/.bash_profile; env'
(adjust for your login shell)

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

Report this message

#9: Re: How to execute commands on a server through a script on my computer?

Posted on 2007-06-09 22:10:31 by gazelle

In article <1181151394.915818.70900@i13g2000prf.googlegroups.com>,
<pod69@gmx.net> wrote:
>On Jun 6, 6:57 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
>> On Wed, 06 Jun 2007 09:40:01 -0700, pod69 wrote:
>> > Hello
>>
>> > I want to write a script that executes some commands on a server -
>> > therefore i generated some keys - so i can connect to the server without
>> > a password. The problem is now i can do ssh user@host /bin/ date and
>> > transfer files with scp but i dont know how to execute specific commands
>> > on the servers shell because i need some environment variables - I need
>> > the servers environment? thx for any help and info!
>>
>> > thx pättr
>>
>> For simple cases, where there are no difficult quoting characters in the
>> variable names, and if you have a "sh" family login shell, you can do
>>
>> ssh user@host VAR1="$VAR1" VAR2="$VAR2" /bin/date
>>
>> to set the environment variables VAR1 and VAR2 on the remote machine to
>> be the same as they are on the local machine.
>>
>> You should also read your manual page for ssh, to see if it supports
>> ~/.ssh/environment in the same way that openssh does.

I'm not real up on ssh and all its little nuances, but I think the issue
here is that when you invoke ssh in the "run a command and return" mode,
as opposed to the "log me in like telnet and give me a shell prompt"
mode, that your startup files (.login/.cshrc/.profile/.whatever) don't
get sourced. Assuming this to be the case, one solution (that some here
will think kludgy, but which really does make a lot of sense, once you
get used to it) is to use "Expect" to automate a normal shell login.
Then you get the best of both worlds.

Report this message