Why ip_forward_use_pmtu added in the result of sysctl in linux server - linux

So I did an OS version-up in a linux server, and was seeing if any setting has been changed.
And when I typed "sysctl -a | grep "net.ipv4.ip_forward"
The following line was added,
net.ipv4.ip_forward_use_pmtu = 0
I know that this is because this parameter is in /proc/sys.
But I think if the result of sysctl before upload did not show this line, it was not in /proc/sys before as well, right ?
I know that 0 means " this setting is not applied...So basically it does not do anything.
But why this line is added.
The question is
Is there any possible reason that can add this line?
Thank you, ahead.

Even the question itself "added in the result of sysctl in linux server" is wrong here.
sysctl in the way you invoked it, lists all the entries.
grep which you used to filter those entries "selects" matching texts, if you'd run grep foo against the list:
foo
foobar
both items would be matched. That's exactly what you see but the only difference is instead of "foo" you have "net.ipv4.ip_forward".
Using --color shows that clearly:
Pay attention to the use of fgrep instead of grep because people tend to forget that grep interprets some characters as regular expressions, and the dot . means any character, which might also lead to unexpected matches.

Related

Is there a simple alternative to "who am i" and "logname"?

I noticed that RHEL 8 and Fedora 30 don't update the utmp file properly.
As a result, commands such as 'who am i', 'last', 'w' etc print incorrect results (who am i actually doesn't print anything)
After a bit of googling, I found 'logname' which worked in this case but I read that gnome is dropping support for utmp altogether so it's a matter of time until this stops working too.
I wrote the following script which finds the login name of the user (even if he is using sudo the moment he runs the command) but it's way too complicated so I'm looking for alternatives.
LOGIN_UID=$(cat /proc/self/loginuid)
LOGIN_NAME=$(awk -v val=LOGIN_UID -F ":" '$3==val{print $1}' /etc/passwd)
Is there a simple alternative which is not based on proper updating of /var/run/utmp ?
Edit 1: Solutions that don't work $HOME, $USER and id return incorrect values when used in a script that has been run with the sudo command. who am i and logname depend on utmp which isn't always updated by the terminal.
Working solution: After a bit of searching, a simpler way than the aforementioned was found in https://unix.stackexchange.com/users/5685/frederik-deweerdt 's comment to his own answer
Link to answer which contains the commment: https://unix.stackexchange.com/a/74312
Answer 1
stat -c "%U" $(tty)
Second answer found at https://stackoverflow.com/a/51765389/10630167
Answer 2
`pstree -lu -s $$ | grep --max-count=1 -o '([^)]*)' | head -n 1 | sed 's/[()]//g'`
Your question is not well-defined because if X and Y are not working, what are the chances that Z will work? This depends entirely on the precise failure mode you are attempting to handle, and there is nothing in your question to reveal the specific circumstances in which you need this.
With that out of the way, perhaps look at the POSIX id command, which has explicit options to print the real (login) or effective (after any setuid command) user id with -r or -u, respectively. Of course, the precise means by which it obtains this information are not specified, and will remain implementation-dependent, and thus might or might not work on your platform under your specific circumstances.
As an aside, here is a refactoring of your code to avoid polluting the variable name space with two separate variables.
LOGIN_NAME=$(awk 'NR==FNR { val=$0; next }
$3==val{print $1}' /proc/self/loginuid FS=":" /etc/passwd)

removing {^D ctrl+d } junk from a file using shell

I'm using a shell & TCL script to login to a switch and get the output of certain commands and in some places I can see ^D coming up. I tried to use the dos2unix utility but still it didn't go away.
Eth1/37 NOM: xcvrAbsen routed auto auto --
^DEth1/38 NOM: xcvrAbsen routed auto auto --
Eth1/39 NOM: xcvrAbsen routed auto auto --
Eth101/1/45 eth 1000 NOM:NO_PATCHING CABLE
^DEth101/1/46 eth 1000 NOM:NO_PATCHING CABLE
Eth101/1/47 eth 1000 NOM:NO_PATCHING CABLE
How can this be eliminated, are there any standard tools like dos2unix which can get rid of such data?
What I'm trying to do is to compare two files which are from the same switch and the same command and the same output, but due to these ^D, Vimdiff shows it as different lines.
How to get this eliminated?
Command I'm using is something like this:
$cdir/ciscocmd -Y -u $operator -p $password -s $password -t $switch -r rfc_sa_commands | sed 's/^^D//' > $switch.$NOW
dos2unix removes carriage returns, no other control characters.
The tool to remove all occurrences of an arbitrary character is called tr.
tr -d '\004' <inputfile >outputfile
This assumes you have literal ctrl-D characters, not sequences of caret ^ and D. The tr utility cannot remove a specific sequence; it just processes individual characters. To remove a sequence, you'd need
sed 's/\^D//g' inputfile >outputfile
where the backslash is required because the caret alone has a special meaning in regular expressions (it matches beginning of line). Doubling it does not escape it; ^^ probably still just matches beginning of line, though it's not really well-defined, and could introduce apparently random behavior.
Even if the special character is visible as '^D', it may be NOT catchable like this.
Interesting readings, are:
https://en.wikipedia.org/wiki/ASCII#Character_groups
https://en.wikipedia.org/wiki/End-of-Transmission_character
I think a way to do it would be:
<your command>|sed -e 's/\x04//g'
Does it solve your issue?

What does "cat -A" command option mean in Unix

I'm currently working on a Unix box and came across this post which I found helpful, in order to learn about cat command in Unix. At the bottom of the page found this line saying: -A = Equivalent to -vET
As I'm new into Unix, I'm unaware of what does this mean actually? For example lets say I've created a file called new using cat and then apply this command to the file:
cat -A new, I tried this command but an error message comes up saying it's and illegal option.
To cut short, wanted to know what does cat -A really mean and how does it effect when I apply it to a file. Any help would be appreciated.
It means show ALL.
Basically its a combination of -vET
E : It will display '$' at the end of every line.
T : It will display tab character as ^I
v : It will use ^ and M-notation
^ and M-notation:
(Display control characters except for LFD(LineFeed or NewLine) and TAB using '^' notation and precede characters that have the high bit set with
'M-') M- notation is a way to display high-bit characters as low bit ones by preceding them with M-
You should read about little-endian and big-endian if you like to know more about M notation.
For example:
!http://i.imgur.com/0DGET5k.png?1
Check your manual page as below and it will list all options avaialable with your command and check is there -A present, if it is not present it is an illegal option.
man cat
It displays non-printing characters
In Mac OS you need to use -e flag and
-e Display non-printing characters (see the -v option), and display a dollar sign (`$') at the end of each line.

Using -s command in bash script

I have a trivial error that I cant seem to get around. Im trying to return the various section numbers of lets say "man" since it resides in all the sections. I am using the -s command but am having problems. Every time I use it I keep getting "what manual page do you want". Any help?
In the case of getting the section number of a command, you want something like man -k "page_name" | awk -F'-' "/^page_name \(/ {print $1}", replacing any occurrence of page_name with whatever command you're needing.
This won't work for all systems necessarily as the format for the "man" output is "implementation-defined". In other words, the format on FreeBSD, OS X, various flavours of Linux, etc. may not be the same. For example, mine is:
page_name (1) - description
If you want the section number only, I'm sure there is something you can do such as saving the result of that line in a shell variable and use parameter expansion to remove the parentheses around the section number:
man -k "page_name" | awk -F'-' "/^page_name \(/ {print $1}" | while IFS= read sect ; do
sect="${sect##*[(]}"
sect="${sect%[)]*}"
printf '%s\n' "$sect"
done
To get the number of sections a command appears in, add | wc -l at the end on the same line as the done keyword. For the mount command, I have 3:
2
2freebsd
8
You've misinterpreted the nature of -s. From man man:
-S list, -s list, --sections=list
List is a colon- or comma-separated list of `order specific' manual sections to search. This option overrides the
$MANSECT environment variable. (The -s
spelling is for compatibility with System V.)
So when man sees man -s man it thinks you want to look for a page in section "man" (which most likely doesn't exist, since it is not a normal section), but you didn't say what page, so it asks:
What manual page do you want?
BTW, wrt "man is just the test case cuz i believe its in all the sections" -- nope, it is probably only in one, and AFAIK there isn't any word with a page in all sections. More than 2 or 3 would be very unusual.
The various standard sections are described in man man too.
The correct syntax requires an argument. Typically you're looking for either
man -s 1 man
to read the documentation for the man(1) command, or
man -s 7 man
to read about the man(7) macro package.
If you want a list of standard sections, the former contains that. You may have additional sections installed locally, though. A directory listing of /usr/local/share/man might reveal additional sections, for example.
(Incidentally, -s is not a "command" in this context, it's an option.)

Bind/Named named.conf deleted/replaced accidently.. recovery help

Apologies my bad english.
Well, I accidentally replace named.conf ..
is there any way to see the configuration again ...
named continues running without restart
show me something like configurations running ....
Thanks to all
PS. i tried to recover the file but it was not erased.
Unless you have a backup of some kind you're going to be out of luck. Although you might get some vague details from rndc you'll never recover the actual file...
You may grep your disk for it.
I usually add the same comment to all the configuration files i touch. Something like
## (pablo) /etc/inputrc
...
## eof
If i delete /etc/inputrc i can grep for it with:
fgrep -a -A 50 '## (pablo) /etc/inputrc' /dev/sda >/some/file/outside/dev/sda
You may use the same technique looking for something you know is in the file, like some domain name you were serving.
-a force text search
-A 50 display 50 lines after the pattern matched
-B 50 display 50 lines before the pattern matched
-B is usefull if you don't know exactly where the pattern will match.

Resources