logname unset with input redirection (stdin) - linux

For linux why when providing stdin (input redirection) to logname it is not able to determine the user?
#> echo `logname`
<username>
#> echo `logname` < /dev/null
logname: no login name
#> echo `logname` < /dev/tty
logname: no login name
Moverover this does not seem to affect whoami.
#> echo `whoami`
<username>
#> echo `whoami` < /dev/null
<username>
Edit: Adding OS versions (tested it on multiple different Linux machines).
#> uname -a
Linux <machine1> 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
#> uname -a
Linux <machine2> 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22:44 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
#> uname -a
Linux <machine3> 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux

On Unix/Linux systems, you can have multiple users logged in through different windows, ssh sessions etc. Each currently logged in user may or may not have a tty associated with the session. If there is a tty session allocated for a user, the association between tty and the user logged in on it is stored in the systems utmp file (the path may vary). logname wants to first see what tty you are on, then look up the associated record in the utmp file to see who you are. When you do logname < /dev/null, logname is disassociated from your tty, and so fails to find out which record it needs to lookup, which is why it reports "no login name".

Related

udev rules for sd* and dm-* device not working as expected

# cat /etc/oracle-release
Oracle Linux Server release 7.8
uname -a
Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
cat 99-custom.rules
ACTION!="add|change", GOTO="rule_end"
ENV{ID_VENDOR}=="NETAPP*", RUN+="/bin/sh -c 'echo 4096 > /sys%p/queue/max_sectors_kb'"
LABEL="rule_end"
----2nd option using KERNEL option just for dm-* devices
ACTION!="add|change", GOTO="rule_end"
KERNEL=="dm-[0-9]*",ENV{ID_VENDOR}=="NETAPP*", RUN+="/bin/sh -c 'echo 4096 > /sys%p/queue/max_sectors_kb'"
LABEL="rule_end"
udevadm control --reload-rules && udevadm trigger
/sbin/udevadm trigger --type=devices --action=change
Issue : We don't see udev rule applied to all dm-* device
/sys/block/dm-19/queue/max_sectors_kb:512
/sys/block/dm-9/queue/max_sectors_kb:512
We even tried to remove ENV{ID_VENDOR}=="NETAPP*" from rule
What we need to apply max_sectors_kb to 4096 to all dm-* ( multipath devices )
and all sd* devices can be left default of 512
Any idea what could be wrong ?

can`t find "cpu.cfs_period_us" and "cpu.cfs_quota_us" in cgroup

I want to limit the CPU usage of the process through CGroup.After searching for some information on the Internet, I learned that it needed to be revised "cpu.cfs_period_us" and "cpu.cfs_quota_us",but now I can`t find these two files in cgroup.
My steps are as follows
The path "/sys/fs/cgroup" already exists in my Linux system, but there are no files in it.So I mount the cgroup/cpu/ file according to the reference standard steps:
cd /sys/fs/
mount -t tmpfs cgroup_root ./cgroup
mkdir cgroup/cpu
mount -t cgroup -ocpu cpu ./cgroup/cpu/
What puzzles me is that my ./cgroup/cpu/ directory doesn't have "cpu.cfs_period_us" and "cpu.cfs_quota_us"... What's the reason? Is it a kernel configuration problem?
I have these files in my ./cgroup/cpu path:
/sys/fs # ls ./cgroup/cpu/
cgroup.clone_children cpu.rt_period_us release_agent
cgroup.procs cpu.rt_runtime_us tasks
cgroup.sane_behavior haoel
cpu.notify_on_migrate notify_on_release
Other information
1)my linux system info
/ # cat /proc/version
Linux version 3.18.20 (gcc version 4.9.2 (GCC) ) #1 PREEMPT Tue Mar 9 03:52:45 CST 2021
/ # uname -a
Linux mdm9607-perf 3.18.20 #1 PREEMPT Tue Mar 9 03:52:45 CST 2021 armv7l GNU/Linux
2)Related kernel configuration
CONFIG_CGROUPS=y
CONFIG_CGROUP_DEBUG=y
CONFIG_CGROUP_FREEZER=y
# CONFIG_CGROUP_DEVICE is not set
# CONFIG_CPUSETS is not set
CONFIG_CGROUP_CPUACCT=y
CONFIG_RESOURCE_COUNTERS=y
# CONFIG_MEMCG is not set
# CONFIG_CGROUP_PERF is not set
CONFIG_CGROUP_SCHED=y
# CONFIG_FAIR_GROUP_SCHED is not set
CONFIG_RT_GROUP_SCHED=y
# CONFIG_BLK_CGROUP is not set

Check Which operating system is installed ( CentOS, Ubuntu, Redhat, ... etc)

I have been given a server with OS installed. I want to check which Operating system is installed in it. I have used uname -a with ouput of
Linux ctl 2.6.32-573.3.1.el6.x86_64 #1 SMP Mon Aug 10 09:44:54 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
Any suggestions ?
You could use the /etc/os-release file, which contains information on the os using the freedesktop spec.
Printing out just the OS name and version:
awk -F '=' '/PRETTY_NAME/ { print $2 }' /etc/os-release
Using os-release file available in Linux:
cat /etc/os-release
on many OS's, you can get the os via:
lsb_release -d
The el6 in the kernel version could indicate a RedHat (thus Fedora as well), Oracle, Centos, Scientific Linux. Potentially others as well.
At least on some of these systems (others as well) the distribution can be identified from the /etc/issue* files. For example:
> ls -la /etc/issue*
-rw-r--r-- 1 root root 57 Oct 22 2014 /etc/issue
-rw-r--r-- 1 root root 55 Oct 22 2014 /etc/issue.net
> cat /etc/issue
Welcome to openSUSE 13.2 "Harlequin" - Kernel \r (\l).
you can try this command to check all detail related to operating system version:
cat /etc/*elease

sysctl: setting key "kernel.softlockup_panic": Invalid argument

When I am trying to set kernel.softlockup_panic value to 30 instead of 0. I am getting Invalid argument error
# sysctl -w kernel.softlockup_panic=30
Error message
# sysctl: setting key "kernel.softlockup_panic": Invalid argument
kernel.softlockup_panic = 30
Can anyone please guide?
I am using SLES12 64bit OS
# uname -a
Linux linux-r1qg 3.12.28-4-default #1 SMP Thu Sep 25 17:02:34 UTC 2014 (9879bd4) x86_64 x86_64 x86_64 GNU/Linux
I Have used syctl for other purposes. Guess this params is not supported by kernel .
you can check this thru either of the commands
sudo sysctl -a | grep softlockup
cat /proc/sys /etc/sysctl.conf

Finding if kernel is 32-bit or 64-bit on Linux

When I run uname -a, I get:
Linux 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
and I understand that x86_64 is supposed to imply 64-bit kernel, but why does this number appear 3 times? What does each instance signify?
Uname has separate commands to print "machine, processor and hardware platform" -- all of these are all the same in your case. The following outputs, respectively, may make it clear:
~$ uname -m # print machine
x86_64
~$ uname -p # print processor
x86_64
~$ uname -i # print hw platform
x86_64
use uname -m command to display only name of the kernel.
in your case
uname -m
x86_64
means 64-bit
uname -a
will give you all details about your system. It includes machine hardware name, processor type & hardware platform too.
So,
x86_64 is machine name.
x86_64 is processor type.
x86_64 is hardware platform.
Use:
uname --help
to get more idea about its options.

Resources