Solved

automatic process start after login

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

708 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

17 Experts available now in Live!

Get 1:1 Help Now