LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-17-2012, 03:08 AM   #1
dsimha
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Rep: Reputation: Disabled
Post Difference between running script (.sh) from .bash_profile and running from login


Hi,

I've a script (checkVncServer.sh) which checks if vncserver is running or not. If not, it starts the vncserver.

This scripts needs to be executed when user logs in (through ssh/putty).
Hence, called it in .bash_profile.
However, when user logs out from ssh, the vncserver processes become <defunct>. “ps –ea | grep vnc” shows Xvnc <Defunct>

If same script is manually executed from command prompt ($ ./checkVncServer.sh) and user logs out, vncserver processes are running normally.

What is the difference between above two methods of running the scripts?

I want to run script from .bash_profile. Processes should run even after user logs out from ssh. How can this be achieved?

Environment: RHEL 5.7

Thanks.
 
Old 01-17-2012, 03:40 AM   #2
jayaramprasad
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Rep: Reputation: Disabled
Thumbs up

Hi,
In-order to run your script in bash_profile please add keyword nohup as a background job which doesn't hangup even the user is logged-out.

Ex: nohup ./checkVncServer.sh &

Generally bash_profile is used to execute all the scripts when user is logged in and automatically the processes initiated by that user will get closed once heloggedout.




Quote:
Originally Posted by dsimha View Post
Hi,

I've a script (checkVncServer.sh) which checks if vncserver is running or not. If not, it starts the vncserver.

This scripts needs to be executed when user logs in (through ssh/putty).
Hence, called it in .bash_profile.
However, when user logs out from ssh, the vncserver processes become <defunct>. “ps –ea | grep vnc” shows Xvnc <Defunct>

If same script is manually executed from command prompt ($ ./checkVncServer.sh) and user logs out, vncserver processes are running normally.

What is the difference between above two methods of running the scripts?

I want to run script from .bash_profile. Processes should run even after user logs out from ssh. How can this be achieved?

Environment: RHEL 5.7

Thanks.
 
Old 01-17-2012, 05:03 AM   #3
dsimha
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Tried <nohup ./checkVncServer.sh &> in .bash_profile

Now, when user logs out, ps -ea | grep vnc is blank; i.e. all the vnc processes are deleted.

Earlier, Xvnc was listed as below:
2252 ? 00:00:00 Xvnc-core
2253 ? 00:00:00 Xvnc <defunct>

Quote:
Originally Posted by jayaramprasad View Post
Hi,
In-order to run your script in bash_profile please add keyword nohup as a background job which doesn't hangup even the user is logged-out.

Ex: nohup ./checkVncServer.sh &

Generally bash_profile is used to execute all the scripts when user is logged in and automatically the processes initiated by that user will get closed once heloggedout.
 
Old 01-17-2012, 05:46 AM   #4
jayaramprasad
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Rep: Reputation: Disabled
Then,

Plz also try in this way;

make a copy of this script in /etc/init.d/ directory which leads to start/run all the scripts when the machine is got rebooted, its nowhere related to user logged in or loggedout.

Now you can remove that script from bash profile and try this if you have a chance to re-boot then check it once.

Thanx

Quote:
Originally Posted by dsimha View Post
Tried <nohup ./checkVncServer.sh &> in .bash_profile

Now, when user logs out, ps -ea | grep vnc is blank; i.e. all the vnc processes are deleted.

Earlier, Xvnc was listed as below:
2252 ? 00:00:00 Xvnc-core
2253 ? 00:00:00 Xvnc <defunct>
 
Old 01-17-2012, 10:06 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,

Welcome to LQ!

I would source the '.bashrc' from '.bash_profile'.

You could setup a .bashrc & .bash_profile for your user;


Code:
sample .bash_profile;
 ~$ cat .bash_profile
 # .bash_profile
 #08-30-06 12:21
 #
 # Source .bashrc
 if [ -f ~/.bashrc ]; then
         . ~/.bashrc
 fi
Code:
 sample .bashrc;
 :~$ cat .bashrc
 
 #.bashrc
 #08-30-06 12:20  
 
 # Add bin to path
 
export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"
 
#export PATH="$PATH:$HOME/bin"
 
# Dynamic resizing
 shopt -s checkwinsize
  
# Custom prompt
 #PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  
 #08-29-06 11:40
  
 if [ `id -un` = root ]; then
    PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
  else
    PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
 fi
  #
 # Add color
 eval `dircolors -b`
  
 # User defined aliases
 alias cls='clear'
 alias clls='clear; ls'
 alias ll='ls -l'
 alias lsa='ls -A'
 alias lsg='ls | grep'
 alias lsp='ls -1 /var/log/packages/ > package-list'
 alias na='nano'
 alias web='links -g -download-dir ~/ www.google.com'
 
#08-29-06 11:50
#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
    trap "rm -f ~$LOGNAME/.bash_history" 0

 #The older KSH-style form #   trap 0 rm -f ~$LOGNAME/.bash_history
The .bashrc is very useful! You could modify the above '.bashrc' script example to include your users needs. That way the source of '.bashrc' from '.bash_profile' will handle the issues.

Just a few links to aid you to gaining some understanding. Sure some may seem beyond a newbie but you must start somewhere;



Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Bash Beginners Guide
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking



The above links and others can be found at '
Slackware-Links'. More than just Slackware® links!

HTH!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Slackware 13.0 ~/.bash_profile not running at login ash_zz_00 Linux - Newbie 9 03-09-2012 01:58 PM
[SOLVED] running a script before login mahmoodn Ubuntu 17 08-22-2010 09:30 AM
Running a mount script on login targettl Linux - Software 4 10-12-2009 07:19 PM
Running Script Upon Login edwin11 Linux - Software 7 06-26-2006 04:24 AM
Running a script at user login? brucebearau Debian 1 01-19-2004 04:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration