Determine if user is logged in via CLI?

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read this

Determine if user is logged in via CLI?

Postby NotoriousPyro on Sun Feb 17, 2013 7:54 pm

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
Image
NotoriousPyro
Level 1
Level 1
 
Posts: 6
Joined: Sun Feb 10, 2013 12:29 pm

Linux Mint is funded by ads and donations.
 

Re: Determine if user is logged in via CLI?

Postby Talegolas on Tue Feb 19, 2013 7:23 pm

the command "who" tells you the name of the user and if they are connected to tty or pts.. would that work?
Talegolas
Level 1
Level 1
 
Posts: 29
Joined: Tue Feb 12, 2013 6:31 pm

Re: Determine if user is logged in via CLI?

Postby bjornmu on Wed Feb 20, 2013 2:54 am

I think this might work:
Code: Select all
if tty > /dev/null ; then
  echo CLI
else
  echo Not CLI
fi
User avatar
bjornmu
Level 3
Level 3
 
Posts: 158
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway


Return to Other topics

Who is online

Users browsing this forum: Bing [Bot] and 4 guests