Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-31-2008, 07:08 PM
|
#1
|
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:
|
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.
|
|
|
03-31-2008, 07:58 PM
|
#2
|
Member
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209
Rep:
|
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?
|
|
|
03-31-2008, 10:01 PM
|
#3
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
|
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.
|
|
|
04-02-2008, 01:29 PM
|
#4
|
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:
|
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.
|
|
|
04-02-2008, 03:37 PM
|
#5
|
Member
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209
Rep:
|
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.
|
|
|
04-02-2008, 05:25 PM
|
#6
|
Member
Registered: Jul 2004
Location: Netherlands
Distribution: fedora core 8, suse 10.3, ubuntu 7.10, kamikaze 7.09
Posts: 515
Rep:
|
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.
|
|
|
04-02-2008, 09:28 PM
|
#7
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
|
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 ).
|
|
|
04-07-2008, 01:11 PM
|
#8
|
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:
|
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.
|
|
|
All times are GMT -5. The time now is 03:13 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|