Solved

automatic process start after login

Posted on 1998-10-14
4
291 Views
Last Modified: 2010-04-21
What is the best way for a user to automatically start up processes when they log in?    Is it to add the process commands to the .profile file?

0
Comment
Question by:aplatti
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
blowfish earned 50 total points
ID: 2007416
I can actually think of two ways, and the one you choose depends on what you are trying to do at login.  

The first method uses a conventional login shell and initialization file .  If your shell is the csh, the initialization file is .cshrc.  If your shell is the ksh or sh, the initialization file is .profile.  If your shell is bash, the initialization file is .bashrc.  

Put your commands in the initialization file to cause them to run automatically at login.  You may want to run some of them (longer running commands) in background to be able to continue to use the shell from foreground.  To run a command in background mode, put "&" after the command; ie.

  /usr/bin/who | mail ${LOGNAME} &

The second way would be to write a shell script, and specify it as the user's login shell; ie. when you define the user, don't specify the login shell to be /bin/sh, instead specify the full path and command name of the shell script.  This approach could be used if you wanted to present a menu of commands upon successful login.  If the user exits your script, they get logged off.  

Hope this helps,

--frankf
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007417
Never ever use $HOME/.cshrc for starting such programs !!

cshrc will be sourced for every csh script you start, unless it has the -f option, so your program is started again and again ..
Use $HOME/.login  for such things.

Something similar applies to all other shell's resource files like: $HOME/.{profile,bashrc,tcshrc,zshrc}
Check your manuals before doing it.
0
 
LVL 2

Expert Comment

by:blowfish
ID: 2007418
That's probably one of the reasons why I don't use csh, I should have checked it out though before proposing it in an answer :(

However, for sh and ksh, the commands in .profile are run only when the shell is started, not every time a script is run.  
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007419
> only when the shell is started
You mean "only when a shell at login is started".
Well, this might be true for modern sh and ksh, but there are version (at least for ksh) which source .profile every time you start a script. And they have no -f option like csh or tcsh :(
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Audit HISTFILE for all users on AIX 9 108
How to find files recursively in ftp server quickly? 7 102
unix scripting question 1 89
Install MySQL 5.6 and PHP on Centos Linux 6 101
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now