0

I'm a beginner to Ubuntu, working on a script to save the current user name in a file in /tmp.. Previously I've used /etc/gdm3/PostLogin/Default script to do this

#!bin/sh

current_user= "$USER"

echo " $current_user" > /tmp/postlogin.log

and it worked well. But when we switch between users the file is being over-written and when we switch back to the previous user, it's not being updated, as the postlogin script is run only at logins.

Suggest me someway around this issue, which files I can use to make this script run. P.S. I've tried editing /etc/bash.bashrc , .profile, .bashrc and other related files to run my script and made a huge mess of things.

  • What do you mean by "current user"? Multiple users may be logged in in Ubuntu at any time. If what you really want is to create a log of logins, you may want to not overwrite the file but append to it (with >> instead of >) and perhaps add a time stamp to it, e.g. echo "$(date) $USER" >> /tmp/postlogin.log. – Jos Aug 19 '19 at 11:21
  • @Jos My definition of "current user" was suppose if both Admin user and a guest user are running parallel (like constantly switching between users), I needed to definitely know which user is currently operating on the system, which will be later used by some applications to apply restrictions. For this I started using .bash_profile and .profile files and its working fine now. – frankenstein Aug 21 '19 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.