?
Solved

automatic process start after login

Posted on 1998-10-14
4
Medium Priority
?
297 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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