LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-17-2012, 06:30 PM   #1
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Rep: Reputation: Disabled
Shell script remote notifications


Hello forum,
I'm looking for a method to send fast and reliable notifications to a remote server within a trusted LAN via shell script, but I haven't found any way to use UDP with shell script commands. Is that possible? If not, I could only use rsh and then execute a remote command that sends a signal to some process or does anyone know a better option? Thank you.

Some further questions:
Which privileges are appropriate for the user who executes the rsh command? The rsh is executed from within a shell script, that several users are allowed to execute. The target of the rsh connection is always the same server.

Last edited by a2326; 11-18-2012 at 03:50 AM.
 
Old 11-18-2012, 06:43 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Bash has a feature that allows you to:
Code:
echo "this" > /dev/tcp
REPLY=$(cat /dev/udp)
Unfortunately some distributions seem to have chosen to disable this at compile time. So you cannot rely on it for your script to run on every system.

Another option would be to use "netcat" (a.k.a. "nc").
See http://www.binarytides.com/netcat-tu...for-beginners/
 
2 members found this post helpful.
Old 11-18-2012, 09:22 AM   #3
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
That sounds interesting, but it seems that this doesn't allow multiple client connections at the same time.

My goal is to implement a notification service, that enables the client to notify the server immediately after he has sent him a file. When the server has received the notification, he shall read and process this file.

Last edited by a2326; 11-18-2012 at 10:10 AM.
 
Old 11-18-2012, 11:02 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,543
Blog Entries: 54

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Quote:
Originally Posted by a2326 View Post
I'm looking for a method to send (..) notifications to a (..) server
SNMP?
 
1 members found this post helpful.
Old 11-18-2012, 11:45 AM   #5
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
Might also be an option, but I don't know how to use it in conjunction with xinetd.
 
Old 11-18-2012, 01:16 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,543
Blog Entries: 54

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Then maybe it's time you post your requirements in full because first saying:
Quote:
Originally Posted by a2326 View Post
(..) send (..) notifications to a remote server (..) via shell script
then adding:
Quote:
Originally Posted by a2326 View Post
(..) allow multiple client connections at the same time.
and then saying:
Quote:
Originally Posted by a2326 View Post
(..) use it in conjunction with xinetd.
shows me you haven't. Else it really doesn't make sense suggesting anything.


BTW this doesn't add up:
Quote:
Originally Posted by a2326 View Post
(..) reliable notifications (..) use UDP
because the "U" in UDP may not officially stand for "unreliable" but UDP doesn't keep state and it doesn't guarantee delivery.
 
1 members found this post helpful.
Old 11-18-2012, 02:01 PM   #7
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
OK, this has been not very precise. Basically, I would like to have some simple service that allows me to send small notifications from multiple clients to a server. The notifications don't have to contain any significant data, because they shall be used as signals. All this should work in a small LAN with less than 10 hosts and it doesn't have to be scalable. However, I am quite unsure which option I should follow, because I can't evaluate the pros and cons very well, but maybe in a small network with just a few connections, TCP's "heaviness" doesn't become a real issue.
 
Old 11-18-2012, 02:24 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by a2326 View Post
My goal is to implement a notification service, that enables the client to notify the server immediately after he has sent him a file. When the server has received the notification, he shall read and process this file.
The Linux kernel has a mechanism called "inotify" to signal a process asynchronously when something specific happens on a specific part of the filesystem. Using that you would not need a networked mechanism, just a daemon on the server that runs some script, or sends a signal if a file is created in some specific directory. Debian and ubuntu ship a daemon called "inoticoming" to do just that. I bet other distro's have the same or something similar as well.
 
1 members found this post helpful.
Old 11-18-2012, 02:51 PM   #9
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
Thanks. Can "inotify" be used without making use of C or C++ and can incoming notifications be queued?
 
Old 11-19-2012, 04:14 AM   #10
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
There are command line tools and daemons ("services") written in C/C++, that make it possible to use inotify in all kinds of programming languages and shell scripts.

For shell scripts, the easiest to use is probably "inotifywait" from the
"inotify-tools". I think (never tried it) it can not be used asynchronously, if you need that try: http://inotify.aiken.cz/?section=inc...=about&lang=en. Or of course "inoticoming" I already linked to in my previous post.
 
1 members found this post helpful.
Old 11-19-2012, 06:13 AM   #11
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
If I am right, inotify only reacts to local (in this case server-side) file changes, but it can't be used if the event arises from the client. I think that in this case I am better off with netcat, though I don't know how to find the right port that netcat should use. This script should only be used in a LAN, so I think I can use TCP here. Important is, that the server-side script listens constantly, so that any client can inform him at any time.
The client should then be able to execute one single command on the server, but for this task, rsh/ssh might be a better choice.

Last edited by a2326; 11-19-2012 at 07:43 AM.
 
Old 11-19-2012, 09:49 AM   #12
bradvan
Member
 
Registered: Mar 2009
Posts: 200

Rep: Reputation: 41
As a236 suggested, I think using ssh will be your simplest option. Set up authentication from your "clients" to your server. Designate a directory for them to write to (and make sure the permissions are correct). Then when a client needs to inform the server, ssh server "echo '1' > /my/place/client" or you can scp a file to the location. Then on the server, have a daemon watching the directory an process accordingly when it finds a file.
 
1 members found this post helpful.
Old 11-19-2012, 10:18 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,543
Blog Entries: 54

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Quote:
Originally Posted by a2326 View Post
Important is, that the server-side script listens constantly, so that any client can inform him at any time.
Yep, sounds like SNMP alright.


Quote:
Originally Posted by a2326 View Post
The client should then be able to execute one single command on the server, (..)
SNMP has been around for ages, is well-documented and by using traps allows for complete separation: no interactive service, no shell account or login necessary. Of course you're free to blithely re-invent the wheel regardless.
 
1 members found this post helpful.
Old 11-20-2012, 04:44 AM   #14
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by a2326 View Post
If I am right, inotify only reacts to local (in this case server-side) file changes [..]
That is correct.

Quote:
Originally Posted by a2326 View Post
[..] but it can't be used if the event arises from the client.
If the server receives a file from a client over the network over scp, sftp, ftp, nfs, or whatever, you can use inotify to trigger some action. It is local to the server indeed, but the change in the file or directory can very well arise from a client over the network. If I understood you right, that is what you were looking for.
 
1 members found this post helpful.
Old 11-20-2012, 05:19 AM   #15
a2326
LQ Newbie
 
Registered: Oct 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
I need notifications that are initiated by the client, independent of incoming files. SNMP seems to be a good option, but it's usage seems to be quite complicated.

Which is the best place for a server-side script that should be accessible from multiple clients to be located?

Last edited by a2326; 11-20-2012 at 06:22 AM.
 
  


Reply

Tags
networking, rsh, server


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
Detect Remote Logins Within Shell Script JRomeo Linux - Newbie 1 04-19-2011 09:10 PM
a shall script for remote shell execution ramesh14 Linux - Newbie 3 03-27-2011 08:59 AM
How to call Shell Script on a remote server with remote servers env variables need Linux - Server 1 10-14-2009 09:37 PM
Cannot run shell script on the remote server haresh_dba Linux - General 2 04-14-2007 10:26 AM
telneting remote machine from a shell script sanjith11 Programming 11 05-26-2004 07:50 AM


All times are GMT -5. The time now is 05:15 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration