Create an Inetd Service with Shell Script

In my kiosk system (Read Continue to update my blog for more information), I am going to supply some service such as reboot/shutdown with root permission. The service may be run by HTTPD user apache or another local user.

I realized it with an inetd service, and found it so easy to supply a socket service with shell script.

I will show a simple example (on Slackware 13.0) here.

Edit /etc/services, add the following line:

my_inetd 45678/tcp #My own inetd service

Edit /etc/inetd.conf, add the following line:

my_inetd stream tcp nowait root /usr/local/sbin/my_inetd my_inetd

Create service file /usr/local/sbin/my_inetd (bash script)

while true; do
echo "Please input your command:"
read command
echo "Your command is: $command"

Remember to add x permission, and restart inetd service:

chmod a+x /usr/local/sbin/my_inetd
/etc/rc.d/rc.inetd restart

Now let's check the service:

telnet localhost 45678

You will see our prompt information "Please input your command:". Great! It works now. You can change the script to run anything you like. NOTICE: if you run the server on internet, please take care of security issue, maybe iptables can deal with it —- disable access from outside, only allow local access to the service port.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s