LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-31-2008, 07:08 PM   #1
a2brute
Member
 
Registered: Feb 2005
Location: State of Denial
Distribution: (X/K)Ubuntu for desktop/laptop, DSL for old machines, Debian for Servers.
Posts: 36

Rep: Reputation: 15
Question Possible to call a client side command from a script on server, via SSH connection.


Ok, if my thread subject line wasn't confusing enough, let me see if I can make it more confusing.

I have read several help pages and manuals regarding SSH clients and servers, and none seem to answer the question of if/how one may script a client side command to be called from a shell on the server.

I am connecting to a server via SSH client. I need to execute a script on the server that will read a local variable and then execute a command on the client machine passing it the value just read from the server.

Does that make sense?

If anyone is aware of how this can be accomplished, some instruction or a link on where to find this instruction would be greatly appreciated.

I have read about the SSH escape character "~C" but that does not appear to work if called by a script on the server.

Many thanks to anyone that may be able to help.
 
Old 03-31-2008, 07:58 PM   #2
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
I'm pretty sure you can't do what you want directly. It breaks the client/server model, and afaik the ssh protocol specification specifically disallows it. It'd be a major security problem if a server could execute arbitrary commands on a client.

However,if I understand what you want correctly, you could achieve the same by redirecting the output from the ssh client into your script. So you need to get some variable off of a server, for subsequent use in a client script? Have your client script log in to the server and execute a serverside script that dumps the variable to stdout. You can catch this output client side and use it for whatever you want. Making the logins passwordless with entries in authorized_keys would make it transparent to the user. Would that work for you?
 
Old 03-31-2008, 10:01 PM   #3
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Depends on what and how you try to do it.

I use a line like

Code:
( /usr/lib/fs/ufs/ufsdump ${LEVEL}cnlTfuN 2h - ${RDEV} ${WHICHSNAP}; STATCODE=$?; echo ${STATCODE} > ${CODEFILE} ) | su - backup -c "ssh ${TAPESERVER} \"dd obs=64b of=${TAPDEV}\"";
in a script that's backing up a server using a tape drive on another server. In this case it is running off the root cron. But, you can see that variables from the one machine's environment (in the script) are being passed in through the ssh command to the other machine. They don't come in as variables, they come in as a literal.

In principle, you could ssh to one machine with a line that calls a script using variables from the first machine, which would then be used in the script on the second machine calling back to the first machine. All depends on exactly what it is you are trying to do, and your ingenuity in constructing it. It's part of the mental contortions people sometimes go through with shell substitutions, quoting and escaping.
 
Old 04-02-2008, 01:29 PM   #4
a2brute
Member
 
Registered: Feb 2005
Location: State of Denial
Distribution: (X/K)Ubuntu for desktop/laptop, DSL for old machines, Debian for Servers.
Posts: 36

Original Poster
Rep: Reputation: 15
Thumbs up

Thanks to both of you. Mental contortions it always is, but I think I could get this to work.

Specifically, I have a room full of phone interview stations (xubuntu 7.10) that log in to the main server (ubuntu 7.04) which displays questions and possible answers to our people on the phones via an SSH terminal. I have discovered we can program the survey files to tell the server to execute system commands. I am hoping to use this feature to send a dial command to the modem on each interviewer workstation so we can automate the dialing process. I was hoping to be able to run an escape sequence and have the server echo a dial string to the modem on the client side of the ssh tunnel. Since that is not possible, I think I could just have the survey server spit out the phone number or dial string into a variable that could be read by the client. I suppose I would need to have the client station check for the command to dial every 5 seconds or so. and then somehow signal the server to clear the string once dialed.
 
Old 04-02-2008, 03:37 PM   #5
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
Is there a reason you can't run sshd on the client machines as well? Why not have your server script just ssh into the clients, where it can run anything you want. It would save having to mess about polling the original server output, and allow you a lot more options for controlling the client automagically. With public keys for automatic logins, imho it's the best way to do what you want.
 
Old 04-02-2008, 05:25 PM   #6
arno
Member
 
Registered: Jul 2004
Location: Netherlands
Distribution: fedora core 8, suse 10.3, ubuntu 7.10, kamikaze 7.09
Posts: 515

Rep: Reputation: 30
Why dont you make a ssh connection with that server.
Create a script on that server.
Use scp to copy that script to the client.
Run that script on the client.
 
Old 04-02-2008, 09:28 PM   #7
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
I think beadyallen nailed it: Set up public key automatic login from the server to each of the workstations, and then have it just shoot the dial command across an ssh channel. That's just a one liner (inasmuch as the code I gave you above is a one liner ).
 
Old 04-07-2008, 01:11 PM   #8
a2brute
Member
 
Registered: Feb 2005
Location: State of Denial
Distribution: (X/K)Ubuntu for desktop/laptop, DSL for old machines, Debian for Servers.
Posts: 36

Original Poster
Rep: Reputation: 15
Thumbs up SSH the way to go

Indeed, sometimes I overlook the simplest most rudimentary way to accomplish something and make a task much more difficult than it needs to be. Just having the server SSH into each workstation when needed, pass an environment variable (the number to dial), and run a dial script, would be the easiest and quickest way to accomplish my goal. It means I'll need to install the openSSH server on every workstation but thanks to apt, that should be fairly quick. I think I can write a script to run from a network drive that will quickly copy the RSA to every station as well.

Thanks for all the suggestions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
x264 Streaming media server & client decompressing on server-side? Pearlseattle Linux - General 2 12-12-2007 12:04 PM
Retain Server Connection Up, If Client Break, write system call return SIGPIPE anandss2004 Programming 2 10-24-2005 01:16 AM
LDAP SERVER Client Connection on SUSE 9.2 - connection error jcarton Linux - Networking 3 03-19-2005 01:40 PM
making a secure client/server connection with command prompt williamp0044 *BSD 4 03-06-2004 09:43 AM
help with client side NFS-firewall setup and server side NIS-firewall setup niverson Linux - Networking 3 02-02-2004 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration