Page 1 of 1

Determine if user is logged in via CLI?

Posted: Sun Feb 17, 2013 7:54 pm
by NotoriousPyro
Is there any way to determine if a user is logged in via CLI or on desktop?

I've got this script which mounts user directories on login, and do not want it to execute certain parts when the user is logged in via CLI:

Code: Select all

if [ "$USER" != "root" ]; then
  pulseaudio --start&
  g15aiostats&
  nvidia-settings -a [gpu:0]/GPUPowerMizerMode=1&
  # User profile setup
  # Variables
  NW_MNTD=/home/$USER/.network
  
  # Remove redundant stuff
  rmdir ~/Documents ~/Music ~/Pictures ~/Videos ~/Public
  
  # Change user folder permissions
  chmod 0700 /home/$USER
  
  # Create softlinks
  ln -sf $NW_MNTD/$USER/Documents	~/Documents
  ln -sf $NW_MNTD/$USER/Music		~/Music
  ln -sf $NW_MNTD/$USER/Pictures	~/Pictures
  ln -sf $NW_MNTD/$USER/Videos		~/Videos
  ln -sf $NW_MNTD/Media			~/Media
  if grep -qs $NW_MNTD/Admin /proc/mounts; then
    ln -sf $NW_MNTD/Admin		~/Admin
  fi
fi

Re: Determine if user is logged in via CLI?

Posted: Tue Feb 19, 2013 7:23 pm
by Talegolas
the command "who" tells you the name of the user and if they are connected to tty or pts.. would that work?

Re: Determine if user is logged in via CLI?

Posted: Wed Feb 20, 2013 2:54 am
by bjornmu
I think this might work:

Code: Select all

if tty > /dev/null ; then
  echo CLI
else
  echo Not CLI
fi