How do I edit bash_logout for all users on a system [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Now I know I can edit bash_logout to execute commands once the user types exit, but only for a specific user by editing their bash_logout in their home directory. But how do I edit this for all users?

bash doesn't recognize a system-wide logout script. The best you can do is create a world-readable file like /etc/bash_logout, and recommend that users add . /etc/bash_logout to their personal ~/.bash_logout files.
The only system-wide configuration file bash recognizes is /etc/profile for login shells. You could add
trap 'on_logout' EXIT
(where on_logout is the name of a function you define that contains the desired log-out code) to this file and hope users don't reset the handler. (Technically, /etc/profile is shared amongst all POSIX-compatible shells, so don't put any bash-specific code in such a handler.)

What chepner said above .... if you wanted to be a BOFH you could create a .bash_logout for each user fairly easily ...
Variations based on your OS/Distro may (will?) apply ... assuming all ordinary users exist locally (you didn't mention LDAP) and have UID's in the range [1000...50000] ...
# iterate over all user accounts that are likely to be people with awk,
# print their home, loop over those homes and copy the logout file into place.
awk -F: '$3 >999 && $3 < 50000 { print $6}' /etc/passwd | while read home
do
cp /path/to/your/logout-script $home/.bash_logout
# if you want to be **reallY** nasty uncomment the next two lines.
# that will stop users from deleting the file.
# chown root $home/.bash_logout
# chattr +i $home/.bash_logout
done
If you ran that as root everyone on the system (be careful, see assumption above, make sure no system users get hit ... ) would get your desired logout file.

Related

Readline does not read user config specified in INPUTRC variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am trying to change the location of my inputrc. The docs say that it reads the config location from the INPUTRC environment variable
Readline is customized by putting commands in an initialization file (the inputrc file). The name of this file is taken from the value of the INPUTRC environment variable
I exported this variable in my ~/.bash_profile
export INPUTRC="~/.config/readline/inputrc"
and added the following lines to ~/.config/readline/inputrc
$include /etc/inputrc
# Case insensitive tab completion
set completion-ignore-case on
# Single tab partially completes and shows all options
set show-all-if-ambiguous on
# shift + arrows to go back and forth one word at a time
"\e[1;2D": backward-word
"\e[1;2C": forward-word
# Cycle through completions inline
Tab: menu-complete
"\e[Z": menu-complete-backward
Now if i try to open a new bash session, none of these options seem to have taken effect. It works as expected if I put them in ~/.inputrc with or without the INPUTRC variable exported. I've also tried exporting it from ~/.bashrc and ~/.profile, neither has worked.
I could add these lines to my bashrc using bind but that would mean that other programs that use readline wouldn't share these options.

How to change the username displayed within terminal window on Linux Mint? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am trying to change my current username on Linux Mint that shows up when I open a terminal window.
Currently:
john#myLinux
I want to change to:
gary#myLinux
I have tried:
(1) Start -> Settings -> Account Detail and altered the 'name' field.
(2) The steps mentioned here: https://askubuntu.com/questions/34074/how-do-i-change-my-username
(3) Altering the passwd file: https://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/
Option #3 seems to affect the username displaying in the terminal window but causes issues with logging in(my password becomes incorrect).
How can I successfully change the username that is displayed in my terminal window on Linux Mint OS?
This assumes you are using bash, and might not work for a different shell.
This will only change the terminal prompt text, it will not update your user account or change any other system files.
in a terminal type DEFAULT=$PS1
next type PS1='gary#\h\$ '
last of all, if you want to return to your default prompt type PS1=$DEFAULT
Note 1: Make sure to save these settings in your .bashrc file under the home directory to have changes persist across terminal sessions.
Note 2: In step 2, \h tells the bash prompt to print out the computer hostname, the \$ prints out show the (#) symbol if you're ROOT otherwise show the ($) symbol.
More information can be found here: https://www.howtogeek.com/307701/how-to-customize-and-colorize-your-bash-prompt/

'usr/bin' is not included in the path environment [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Whenever I start a new terminal and try to run a command, I get this error.
I have found out that it can be solved with export PATH=/usr/bin:/bin, but it has to be done for each terminal I open. In the etc/environment file, the path is correct, so hence I do not understand what is wrong.(But this error appeared after I added some lines to bashrc and paths to have some shortcuts for ruby, rails , git ; ( was following a course on Coursera )).
How can this be fixed?
What's happened here is you've clobbered your PATH variable. Your PATH is pretty important, whenever you enter a command your shell (usually bash), will check each of the directories specified in your PATH for a program of the same name.
Each directory specified in your path is separated by a colon :, and a minimal PATH variable usually looks something like /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin.
When you have the line export PATH=/usr/bin/git at the end of your .bashrc you are telling your shell that you only want to search /usr/bin/git for commands.
Instead, the line export PATH="$PATH:/usr/bin/git" will tell your shell to search all of the directories previously specified in your shell, and then search /usr/bin/git.
Another thing to note is that your shell will search the directories in your PATH in the order they're specified, and use the first matching command found, so the order that directories are specified in the PATH can matter too.

creating a function to alias linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Background
I am pretty new to Linux and using aliases.
I understand that in order to add a permanent alias, I need to edit the .bashrc file and I've doing this a lot.
I was wondering if there is a way I could just add an alias permenantly
Without having to open the file and actually adding it.
Current knowledge
I did some research and learned I could give an alias to a function,
And that function could get parameters (the alias I want to add each time)
But I still don't know where I can write this function.
The question
My question is how exactly do I create an alias for a function, and where do I write it.
Also if you can explain to me the syntax of those functions I would be very happy.
function_name () { command1 command2 }
function_name () { command1 p1 command2 p1}
Example
nd () {
mkdir -p $1
cd $1
}
Add this to bashrc, and then nd <folder>
create a new folder and move into that.
Clarification
I decided to answer this old quiestion of mine
To contribute the solution I finally went with.
The solution
First thing I did after some research, was to move
My aliases to .bash_aliases file.
This helped my keep an organized and minimal .bashrc
And gather togeter all of my aliases.
Secondly, in order to achieve adding an alias permanently and without
having to reopen and edit .bashrc file I added a function in .bash_aliases
Function guidlines
Handle terminal arguments
This function received an argument of format:
'new_alias=commands'
Append the new alias received to .bash_aliases
Source .bash_aliases file to include new aliases added to the current terminal window.
Handle modification of aliases:
If an alias with the same name was received, sed was used to replace
The commands executed in 'alias'

Postfix: set privileges for a certain command pipe alias [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm trying to set up an alias that pipes incoming mail for a command in Postfix. So I have something like this in my /etc/aliases:
myuser: "|/usr/bin/command --parameter1 --parameter2"
The problem is that Postfix executes /usr/bin/command as user nobody:nogroup. According to this description it can be changed, but not for a single alias. So the question is how to set the user for a certain alias? Setting nobody:nogroup for a directory /usr/bin/command should operate is not an option.
Replace /usr/bin/command with /usr/bin/sudo -u <user> /usr/bin/command and configure sudo to allow nobody to execute this command.
[EDIT] There are two solutions for your problem:
Make all necessary files read/writable for nobody:nogroup
Change the user (either with a suid script or su/sudo).
If you don't like either, then there is no solution for your problem. You can't do it in aliases(5) because the format doesn't support this (other programs read this file as well, so postfix can't change the syntax).
You could use default_privs but that would change the user for all external commands and you don't want that (huge security risk).

Resources