LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-13-2014, 06:03 PM   #1
actmnophn
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
netcat to run remote script


I am having trouble finding this because I am not sure what to look for. I want to execute a command on another machine on my local network. I do want to use ssh because there is a little(? 5sec) delay until the command gets sent.
I have seen commands sent to servers vi netcat to a server. I was wondering if/how to set up a script as a aimple server to listen for a small set of commands and execute commands based on nc inpuut.
Thanks

--edit:
I am looking in the direction of nc -l -k -p 12345 -e ~/myscript.sh but I am not sure of 2 points. How to keep it listening (-k did not seem to work when i tried it with -e /bin/bash). And how to make the script listen to input (Its a local network so its not the end of the world if I use -e /bin/bash)

Last edited by actmnophn; 03-13-2014 at 06:23 PM.
 
Old 03-13-2014, 06:44 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,680

Rep: Reputation: Disabled
I guess you could use a script to pull data from nc and execute them with eval, but it'd be bloody dangerous. Why is the ssh delay such a big deal? Do you need to run the command(s) at a specific time, right down to the second?

(I'll readily admit that the idea of using netcat to send commands to a remote server would never, ever have occurred to me.)
 
Old 03-13-2014, 07:27 PM   #3
actmnophn
Member
 
Registered: Mar 2008
Posts: 53

Original Poster
Rep: Reputation: 15
I am using gpio input from raspberry pi to play a sound on another machine on a local (no internet yes wifi not bullet-proof) network when a button is pressed and ssh is a few seconds off. Imagine a doorbell that lags 5 seconds not the end of the world but very annoying.
Another idea I came up with is to keep open an ssh connection and send the commands that way.
 
Old 03-13-2014, 09:36 PM   #4
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,680

Rep: Reputation: Disabled
I see your point, and just for fun, this netcat script will work (for very particular values of 'work'):
Code:
#!/bin/sh
while true ; do
  x=$(nc -l -q 0 -p 54321)
  eval $x
done
54321 is the port number. To send a command to the server running this script, do this (or not, please):
Code:
user@linux:~$ echo <command> | nc -q 0 <IP_address_of_server> 54321
If the <command> is break, the server script will terminate.

Remember that anyone with access to the network will:

a) be able to send any command to your server, and
b) may be able to spy on the commands you're sending.

If you just want to run a limited set of commands, it would make more sense to send a simple number or identifier, and have the script interpret that as "run command X". It would vastly improve security too.
 
1 members found this post helpful.
Old 03-14-2014, 02:00 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,700

Rep: Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494Reputation: 2494
Would an ssh tunnel work; ie set it up in advance, then use on demand?
 
Old 03-15-2014, 09:56 PM   #6
actmnophn
Member
 
Registered: Mar 2008
Posts: 53

Original Poster
Rep: Reputation: 15
I think it would. I'm not sure how to implement though. I tried searching but could not word the search the right way to find anything helpful enough. I am going to work on using eval meanwhile because I dont really need to open up everything it will be like a mini server and respond to specific keywords that are defined in a script on the server side to represent commands.
Thanks
 
  


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
[SOLVED] Netcat accpeting remote connections juiceb0x Linux - Software 2 11-14-2011 03:04 PM
Fedora 13 Netcat remote connection problem bonewagon Linux - Software 2 03-07-2011 05:23 PM
run script on remote server ust Linux - Newbie 1 07-22-2009 11:02 PM
Cannot run shell script on the remote server haresh_dba Linux - General 2 04-14-2007 10:26 AM
run programs on a remote computer with script, how? cmisip Linux - Networking 5 07-07-2003 02:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration