Visit Our UNIX and Linux User Community


program that boots at OS startup


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users program that boots at OS startup
# 1  
Old 09-16-2002
program that boots at OS startup

Hi All:
I wanted to know if i can write a program in UNIX, a program that does not run under a particular user login, but starts up at BOOT time.
Are there any online material that i could look into to do that.
Appreciate the help.
Thanks,
Preetham
# 2  
Old 09-16-2002
Your file locations may vary but should be similar

Sure you can. It would help to know what OS you are running.

You will need to do a few things. All these things are based on an HPUX system. But should be similar to yours

You will need to edit the /etc/inittab file to add it to the bootup.

Create a script and put it in a directory similar to /sbin/init.d, may be diff place on your box.

Create a link to the startup directory similary to /sbin/rc3.d linked to the script in /sbin/init.d. The link name will start with an "S" and a number and the script name. Like S342myscript.

You will also need a Kill script in a lower directory probably in /etc/rc1.d. This script may be called K342myscript.


So you will have 3 files basically.

/sbin/init.d/myscript # actual script here
/etc/rc3.d/S342myscript # link to above script for startup on bootup.
/etc/rc1.d/K342myscript # link to above script for kill script on shutdown.

You can look at the syntax of other scripts in this file to include the "start" and "stop" functionality with your script so you can stop it and restart it when it gets out of whack.

Look at the /sbin/init.d/cron script. This is a fairly short example of a good script to copy. There should also be a template file in there as well.

Here are a few posts that give some help.

https://www.unix.com/showthread.php?s...hlight=inittab
# 3  
Old 09-16-2002
please note that all services run as a user. most services run as root. or whom ever you have it specified as.

a server still needs an environment to work in.

i havnt ever found a service that just starts as a unknown user or group.
# 4  
Old 09-17-2002
Re: Your file locations may vary but should be similar

Thanx,
i am using Redhat 7.2.
I am looking at writing a program that would listen at a particular socket and based on what it reads from the socket, it sends back some data(logic/program it does not matter..). what i basically would like to know is: given such a program xyz.c, how can i get it to run after the OS has Booted up. Are the any changes i need to make to the program.
i would like to know if i have to write a Kernal Program or module(im new to this kinda situation....All i know is to write a c program that does some socket operations). How must i compile this code and where should i place it.
I guess that the instructions you mentioned earlier is on how i could get the kernal to start and manage the application.
Thanks,
Preetham.
# 5  
Old 09-17-2002
Re: Re: Your file locations may vary but should be similar

Quote:
Originally posted by preetham
Thanx,
1) I am looking at writing a program that would listen at a particular socket and based on what it reads from the socket, it sends back some data(logic/program it does not matter..). what i basically would like to know is: given such a program xyz.c, how can i get it to run after the OS has Booted up. Are the any changes i need to make to the program.

2) i would like to know if i have to write a Kernal Program or module(im new to this kinda situation....All i know is to write a c program that does some socket operations). How must i compile this code and where should i place it.

3) I guess that the instructions you mentioned earlier is on how i could get the kernal to start and manage the application.
Thanks,
Preetham.
1) login and execute it. if you put it in the inetd.conf file then just HUP the inetd process.

2) use a compiler to make a binary from your c code. and Kelam answered the 2nd part to this question.

3) the tips we gave you are how you load a program at boot time.

4) i would suggest befor trying to make a prog. that listens to sockets and what not, you should familarize yourself with basic system administration so you will at least know if there is a problem where you can look and what not.

5) please (altho i now have my suspicion about this being a hacking related question) post legitimate questions.
# 6  
Old 09-17-2002
Sounds like a hax0ring question, but here's to being helpful...
Since you have to be root to do this, I figure I'm not really aiding and abbetting...

The easiest way to start it up under Redhat Linux 7.* is to add the full path to the command in the /etc/rc.d/rc.local file.
# 7  
Old 09-17-2002
Re: Re: Re: Your file locations may vary but should be similar

thank you Optimus,
First, let me assure you that i have no intention of hacking, im not a hacker, can't afford to be one...i just code for food man Smilie

I have this hello world kernal module code:
Code:
/* Declare what kind of code we want from the header files */
#define __KERNEL__         /* We're part of the kernel */
#define MODULE             /* Not a permanent part, though. */

/* Standard headers for LKMs */
#include <linux/modversions.h> 
#include <linux/module.h>  

#define _LOOSE_KERNEL_NAMES
    /* With some combinations of Linux and gcc, tty.h will not compile if
       you don't define _LOOSE_KERNEL_NAMES.  It's a bug somewhere.
    */
#include <linux/tty.h>      /* console_print() interface */

/* Initialize the LKM */
int init_module()
{
  console_print("Hello, world - this is the kernel speaking\n");
  /* More normal is printk(), but there's less that can go wrong with 
     console_print(), so let's start simple.
  */

  /* If we return a non zero value, it means that 
   * init_module failed and the LKM can't be loaded 
   */
  return 0;
}


/* Cleanup - undo whatever init_module did */
void cleanup_module()
{
  console_print("Short is the life of an LKM\n");
}

i compile the program using the command:
gcc -c hello.c -Wall

When i compile the program i get the following errors:
/usr/include/linux/modversions.h:1:2: #error Modules should never use kernel-headers system headers,
/usr/include/linux/modversions.h:2:2: #error but rather headers from an appropriate kernel-source package.
/usr/include/linux/modversions.h:3:2: #error Change -I/usr/src/linux/include (or similar) to
/usr/include/linux/modversions.h:4:2: #error -I/lib/modules/$(uname -r)/build/include
/usr/include/linux/modversions.h:5:2: #error to build against the currently-running kernel.

Appreciate the help.
thanks,
Preetham.

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 03:43 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #202
Difficulty: Easy
At compile time, the interpreter parses Perl code into a recursive flat-space module.
True or False?

9 More Discussions You Might Find Interesting

1. HP-UX

HP-UX server boots to black graphical screen

hello all, please can you help me crack this.... i have an hp-ux server which when after booting it does not completely boot to graphical. it stops aa black screen with only an hour glass showing. at this stage only the mouse responds but the keyboard does not respond. any idea to find... (5 Replies)
Discussion started by: steveGH
5 Replies

2. Shell Programming and Scripting

Apache tomcat startup script not booting at startup.

I copied the script from an AskUbuntu post - #!/bin/bash ### BEGIN INIT INFO # Provides: tomcat7 # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/Stop Tomcat server ### END INIT INFO ... (14 Replies)
Discussion started by: Hijanoqu
14 Replies

3. Shell Programming and Scripting

Launch a text program inside a konsole at startup

Hi ULFers, I am trying to setup a (very) simple startup script on a centos 6.4 computer and it kind of failed.... Here are the details : As said just above the computer setup is running a CentOS 6.4 x64, on this computer a vncserver is automatically started (by a chkconfig vncserver on), i... (1 Reply)
Discussion started by: pierpier
1 Replies

4. Ubuntu

execute command when Ubuntu boots up ?

hey all,, I want to add comments when Ubuntu starts up.. now I know that there is a directory called /etc/init.d which I can place my scripts there to run them at Ubuntu's startup.. but I prefer if there would be a file which runs when Ubuntu starts!! because it is only one command. not... (2 Replies)
Discussion started by: eawedat
2 Replies

5. OS X (Apple)

How to execute a command when system boots?

Hi all, I want to execute a command when system boots. I tried to edit /etc/rc.common and add my command at the end of rc.common, but it does not work! Anyone knows how to do it? Thanks :) (6 Replies)
Discussion started by: andrewust
6 Replies

6. Red Hat

Fedora on Laptop No Longer Boots

Hi, I'm a bit of a newbie, so please bare with me. I installed Fedora 10 on a Dell Latitude D610 a few weeks ago. The computer previously had Windows on it, but I wiped it clean. I've been trying out Fedora successfully for the past couple of weeks and I was able to use the computer as recently... (1 Reply)
Discussion started by: iansocool
1 Replies

7. Shell Programming and Scripting

How can I make a program start up automatically after the computer restart/startup?

hi all How can I make a program start up automatically after the computer restart/startup in fedora? something like: ... Establish a shell then run some of command code. Thanks for Help!! (1 Reply)
Discussion started by: munna_dude
1 Replies

8. Solaris

NIS Boots Me Out

I have a NIS environment using all Solaris 9 systems. After all kinds of trobleshooting i am to the point where I can login to a NIS account from a client system. However, the logon process starts and the splash screen is displayed and then the desk top is displayed but then it flashes and kicks... (1 Reply)
Discussion started by: meyersp
1 Replies

9. UNIX for Dummies Questions & Answers

auto startup of a program

how do i make a program run at system startup? is there a hirarchy i have to consider? is there any equivalent to an NT "Service" in unix? how do you set it up? thanx Ron (2 Replies)
Discussion started by: exoron
2 Replies

Featured Tech Videos