Solved

automatic process start after login

Posted on 1998-10-14
4
292 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

813 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

16 Experts available now in Live!

Get 1:1 Help Now