[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

automatic process start after login

Posted on 1998-10-14
4
Medium Priority
?
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
blowfish earned 100 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
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.:
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…

649 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