SSH MOTD per User [closed] - shell

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 10 years ago.
Improve this question
After connection to the ssh you get a welcome message that is fed by /etc/motd. Now I would like to have those messages per user but I am not allowed to edit /etc/motd.
So I wonder if there is something possible with ~/.ssh/motd so that those messages will be stored in the users dir. This would be great because every user shall have it's own instructions for the given path-structure.
Does someone know how to solve this?
Thanks in advance!

The "Message of the day" is a cheap way to send a message to all users. If you want to target individual users, you have these options:
Send them an email.
Edit the login script (look into /etc/profile for Bourne shells) and add a line which looks for a per-user message in a certain path and which displays that. Example:
test -e /var/motd/$LOGNAME && cat /var/motd/$LOGNAME
The second approach has the advantage that you can define which path is used (so you can use one which you can write; if you can't write /etc/motd, then you can't edit anything in ~/.ssh/ either).
You will need to be root to set this up this, of course.

Related

Running a script on startup for specific users on a linux vps [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
How can i run a script everytime on start up, but for specific users? Like lets say i want to run 1 script on startup for the user (bob) and a differnt script or no script at all for the user (rick). Note: on a linux vps
When bash starts, it will run the /etc/bashrc script for all users, then the ~/.bashrc script for the specific user. Here ~ stands for the home directory of the user.
If you need something different for a few users, it is easier to use the second script (if you own those accounts.) In case you want to run something from a central point, then the first is better.
For the first approach, you can use the variable $USER to differentiate one user from another using if or case clauses. $EUID is safer because it is read-only, but that will give you the user id, not its name.
Using case at /etc/bashrc you could do:
case $USER in
bob)
<do something for bob>
# No ";;" here so it follows through
rick)
<do something for bob and rick>
;;
user9*)
<do something for user9*>
;;
esac

How to filter out useless messages in `bash` shell by default? [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
Is there any way to filter out absolutely useless messages in bash session by default?
For example, I would like to never see this absolutely useless message: Binary file ... matches while running grep .... It's extremely hard to type something like grep ... 2>/dev/null each time, especially considering how often I need to run this command. Besides it will filter out useful messages as well and this is unwanted.
What I would like to see, is some sort of file in /etc where I could put a bunch of regular expressions of the useless messages line by line. This filter must apply to tty only, i.e. redirected output must stay untouched!
There are some ways to play with your stderr, but there are a number of issues that make that undesirable. For example:
exec 2>/tmp/errorfile
will put all the STDERR output in the errorfile. You could start a
tail -f /tmp/errorfile | grep -v 'Binary file' &
in your .bashrc to get the other messages as well. You will see some funny side effects; for example I found that the prompt is written on STDERR.
You will probably have to create a more elaborate command than the tail|grep to filter-out the undesirable messages and do something about your prompt as well. And you might need to clean-up your errorfile as well.

How can a script know whether a user can input or not? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is there a way a bash script (or whatever language) can determine whether its being run in a headless way? I want to know whether a user can input or not. If they can, I am going to ask them something.
From man bash:
An interactive shell is one started without non-option arguments and without the -c option whose standard input and
error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and
$- includes i if bash is interactive, allowing a shell script or a startup file to test this state.

Linux mint terminal output disappearing [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 7 years ago.
Improve this question
I'm running a script on terminal and it is supposed to produce a long output, but for some reason the terminal is just showing me the end of the result and I cannot scroll up to see the complete result. Is there a way to save all the terminal instructions and results until I type clear.
The script I'm using has a loop so I need to add the output of the loop if Ill be redirecting the output to a file.
Depending on your system, the size of the terminal buffer may be fixed and hence you may not be able to scroll far enough to see the full output.
A good alternative would be to output your program/script to a text file using:
user#terminal # ./nameofprogram > text_file.txt
Otherwise you will have to find a way to increase the number of lines. In some terminal applications you can go to edit>profiles>edit>scrolling tab and adjust your settings.
You can either redirect the output of your script in a file:
script > file
(Be careful to choose a file that does not exist otherwise the content will be erased)
Or you can buffer the output with less:
script | less

How to repeat last command parameter in ZSH [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 10 years ago.
Improve this question
I often need to move file from one location to other, but it requires copying and pasting huge part of the command. For example:
mv ~/Projects/foo/bar/baz.img ~/Projects/foo/bar/fiz.dmg
Is it possible after entering ~/Projects/foo/bar/baz.iso part of above command to use some shortcut that duplicates it so I can change the very end to fiz.dmg?
You don’t need this:
mv ~/Projects/foo/bar/baz.img ~/Projects/foo/bar/fiz.dmg
easily turns into
mv ~/Projects/foo/bar/{baz,fiz}.img
. Note: zsh completion is still available when you write { (unless you have a habit of writing closing } right away) if you want it.
I actually discovered one possible solution. Just press:
Ctrl+W few times and then Ctrl+Y two times (and space between pastes).

Resources