Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Autostarting a program under a specific user account when the machine boots

Posted on 2005-04-11
6
Medium Priority
?
488 Views
Last Modified: 2013-12-16
I know how to autostart a program when the machine boots (without having to login), but how can I do this
under a specific user account.  I have a program which will not run under root, but under the user account
it created when installed.  I need it to autostart when the machine is rebooted so I do not have to login and
run it manually.  Thanks in advance!
0
Comment
Question by:dmccampbell
6 Comments
 
LVL 9

Expert Comment

by:David Piniella
ID: 13758862
place the command to run the program in the user's shell profile (.bash_profile or .bash_rc) or their .xinitrc file if they always log in graphically. If you place it in the .xinitrc, it shuold be the second to last line (before the line that calls the desktop environment).
0
 
LVL 1

Expert Comment

by:kusuma_hs
ID: 13760077
hi,

place a script in /etc/init.d and link it to the run level for ex. in /etc/rc2.d or /etc/rd3.d. The sample script which runs as oracle user is as below :

#!/bin/bash
#
# Startup script for starting oracle listener & databases
#
# chkconfig: 345 56 50
# description: Starts/Stops the Oracle DB, the Oracle Listener,

# Source function library.
. /etc/rc.d/init.d/functions

# Used variables
export ORACLE_HOME=/oracle
DBSTART=$ORACLE_HOME/bin/dbstart
DBSHUT=$ORACLE_HOME/bin/dbshut
LSNRCTL=$ORACLE_HOME/bin/lsnrctl
RETVAL=0

startora()
{
        echo -n $"Starting Oracle DB: "
        daemon --user oracle $DBSTART
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/oradb
        return $RETVAL
}
startlsnr()
{
        echo -n $"Starting Oracle Listener: "
        daemon --user oracle $LSNRCTL start
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/oranet
        return $RETVAL
}
stoplsnr()
{
      echo -n $"Stopping Oracle Listener: "
        daemon --user oracle $LSNRCTL stop
      RETVAL=$?
      echo
      [ $RETVAL = 0 ] && rm -f /var/lock/subsys/oranet
        return $RETVAL
}
stopora()
{
      echo -n $"Stopping Oracle DB: "
        daemon --user oracle $DBSHUT
      RETVAL=$?
      echo
      [ $RETVAL = 0 ] && rm -f /var/lock/subsys/oradb
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        startora
        startlsnr
      ;;
  stop)
        stoplsnr
        stopora
      ;;
  restart)
        stoplsnr
        stopora
        startora
        startlsnr

      ;;
  *)
      echo $"Usage: $prog {start|stop|restart}"
      exit 1
esac

exit $RETVAL

Regards,
Kusuma
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 13760541
>  but how can I do this
under a specific user account.
write a rc-script in /etc/init.d and make proper links in /etc/rc.? (check your system how to do this)

The script simply looks like:

#!/bin/sh
/bin/su - user -c '/full/path/to/your-program some args if you like'
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:kusuma_hs
ID: 13760959
Hi ahoffmann,

It works fine. absolutely no problem. I am using such scripts from long time on linux.

1. write this script as root under /etc/init.d. But that script will contain the respective user and the command what has to be run.
2. create a link in /etc/rc2.d or /etc/rc3.d to the above script as required.
3. enable this through ntsysv if you want this script to be run at the boot time.

Whatever u have said above is fine for executing it manually by root. but the requirement was to run as someother user at the boot time automatically. I am sure above method works fine.

Regards,
Kusuma
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13760971
> kusuma_hs, please re-read my comment
I just focused on the question, the method is the same as described in your suggestion ;-)
0
 

Author Comment

by:dmccampbell
ID: 13761307
Per ahoffman's comments I just added the line to the rc.local file he mentions and it works perfectly.  Thanks for the comments.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question