Wednesday, October 20, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


NixOS: how to apply a patch to GRUB 2

Posted: 20 Oct 2021 11:05 AM PDT

How to apply a patch to GRUB in NixOS? Something like

boot.loader.grub.package = ....  

Tried this, but it didn't work

  nixpkgs.config = {      packageOverrides = pkgs: {        grub2 = (pkgs.grub2.override {      }).overrideAttrs (attrs: {        patches = attrs.patches ++ [          ./01-my-patch.patch       ];      });      };    };    

Can not delete files

Posted: 20 Oct 2021 11:08 AM PDT

I copied some files from a DVD using the 'cp -a' command. Now, I can't delete any of the copied files. I set selinux to "permissive" to remove that as source of the problem. Here is what I have tried so far:

root@zeus:/NGS# getenforce  Permissive  root@zeus:/NGS# rm TRANS.TBL   rm: remove regular file 'TRANS.TBL'? y  rm: cannot remove 'TRANS.TBL': Read-only file system  root@zeus:/NGS# chmod 755 TRANS.TBL   chmod: changing permissions of 'TRANS.TBL': Read-only file system  root@zeus:/NGS# lsattr TRANS.TBL   lsattr: Inappropriate ioctl for device While reading flags on TRANS.TBL  root@zeus:/NGS# ls -lZ TRANS.TBL   -r--r--r--. root root system_u:object_r:iso9660_t:s0   TRANS.TBL  root@zeus:/NGS# chcon unconfined_u:object_r:default_t:s0  root@zeus:/NGS# chcon unconfined_u:object_r:default_t:s0 TRANS.TBL   chcon: failed to change context of 'TRANS.TBL' to 'unconfined_u:object_r:default_t:s0': Read-only file system  

Any suggestions appreciated.

process not killed even we used kill -9 and process actually was belong to container that already removed

Posted: 20 Oct 2021 11:07 AM PDT

here is a strange behavior that show how to kill a process , but actually process not killed

example ( from rhel 7.6 server )

ps -ef | grep kafka-exporter  root     15340 19528  0 17:25 pts/0    00:00:00 grep --color=auto kafka-exporter  root     28326     1 99 Oct18 ?        3-03:04:32 /bin/kafka-exporter --kafka.server=kafka1.sys76.com:6667  

now we try to kill the process

kill -9 28326  

and again see if process killed , but as we can see process still up

ps -ef | grep kafka-exporter  root     20204 19528  0 17:27 pts/0    00:00:00 grep --color=auto kafka-exporter  root     28326     1 99 Oct18 ?        3-03:07:54 /bin/kafka-exporter --kafka.server=kafka1.sys76.com:6667  

as we know the process kafka-exporter is belong to docker container , but docker container already removed as we can see from the following

 docker ps  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES  

but from some unclear reason the binary - /bin/kafka-exporter that should run in container also appears on the Linux OS

and actually when we did ls -l /bin/kafka-exporter , we can see that this binary file not exist

so any idea how to kill the process from the Linux OS , in spite this process was running under docker container that already removed

If the `-p` flag not needed anymore in `mkdir` 9.0?

Posted: 20 Oct 2021 11:09 AM PDT

I can't find any reference of this change of behaviour

$ mkdir --version  mkdir (GNU coreutils) 9.0  Copyright (C) 2021 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.  This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.    Written by David MacKenzie.  

None of the folders exists.

$ mkdir asdfg/qwerty  mkdir: created directory 'asdfg'  mkdir: created directory 'asdfg/qwerty'  

However, with mkdir (GNU coreutils) 8.25 the behaviour is as expected.

➜  ~ mkdir asdfg/qwerty  mkdir: cannot create directory 'asdfg/qwerty': No such file or directory  

Thinkpad T460 - how do I disable the touchpad?

Posted: 20 Oct 2021 10:32 AM PDT

I recently got a Thinkpad T460 and am running Ubuntu 20.04 on it. I don't use a DE, just plain old i3.

I'm like to keep my hands on the keyboard. That's why I like the trackpoint. However, I keep accidentally touching the touchpad, resulting in unwanted mouse movements and even clicks (even though I barely touch it!)

I'm exploring multiple options to improve the situation. This question is about disabling the touchpad completely. According to xinput list, there is only one device (see below):

$ xinput list  ⎡ Virtual core pointer                          id=2    [master pointer  (3)]  ⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]  ⎜   ↳ PS/2 Synaptics TouchPad                   id=11   [slave  pointer  (2)]  ⎣ Virtual core keyboard                         id=3    [master keyboard (2)]      ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]      ↳ Power Button                              id=6    [slave  keyboard (3)]      ↳ Video Bus                                 id=7    [slave  keyboard (3)]      ↳ Sleep Button                              id=8    [slave  keyboard (3)]      ↳ Integrated Camera: Integrated C           id=9    [slave  keyboard (3)]      ↳ AT Translated Set 2 keyboard              id=10   [slave  keyboard (3)]      ↳ ThinkPad Extra Buttons                    id=12   [slave  keyboard (3)]  

And if I run xinput disable 11, both trackpoint and touchpad are disabled.

How can I disable ONLY the touchpad?

quota and xfs_quota not working for NFS clients

Posted: 20 Oct 2021 10:19 AM PDT

I've been bumping up against this issue for years, but have never been able to find a resolution. Prior to RHEL7 (i.e. RHEL 5, RHEL 6, and CentOS 6), I was able to...

  1. Implement user quotas on my NFS servers, via the usrquota option in the /etc/fstab file
  2. Mount the NFS shares to a cluster of various EL clients (RHEL 5 & 6, CentOS 6, Fedora 17 thru 21, Pidora, and even Raspbian)
  3. Enforce quotas across all of those clients
  4. Query quotas via the quota command on ALL of those clients

Problem:

With CentOS7, I have made the jump to XFS (from ext4), and I am able to do all of the above except "4. Query quotas via the quota command on ALL of those clients", and the xfs_quota command also does not report any information relating to the XFS formatted file systems mounted from the NFS Server with quotas enabled. The CentOS7 NFS Server does enforce those quotas, which is useful to my administration of the NFS Server, but frustrating for hundreds of NFS Client users as well as when supporting users who repeatedly run into quota limitations.

The following "Workaround" allows users to query disk usage of their NFS mounted file systems, but is not an accurate or sufficient substitution for quota/xfs_quota queries, nor is it an intuitive solution for most users...

du ‐s .[A‐z]* * | sort ‐n  

I've danced around this issue long enough, and would really appreciate if this community could assist with my understanding why reporting user quotas across my XFS formatted NFS shares is not working. RHEL support, and CentOS support forums are all turning up empty.

Assistance would be appreciated!

Notes:

  • I have the uquota,gquota options in the /etc/fstab file on the NFS Server, as so...

    /dev/mapper/nfs-home  /home        xfs    defaults,uquota,gquota    0 0  
  • The following is the NFS mount entry in the NFS Client /etc/fstab file...

    123.45.67.89:/        /home        nfs    rw,hard,intr,bg           0 0  
  • The rpcbind, quotad and rquotad TCP & UDP ports are opened in the Server's firewall.

  • There are subnet entries for the rpcbind, quotad, and rquotad services in the /etc/hosts.allow file.

  • A df query on the NFS Client(s) shows the mounted NFS shares, while the xfs_quota -c 'df' command does not return any NFS mounted file systems.

I am happy to provide more information on the Client-Server relationship if anyone shows interest.

How do I connect a Linux machine so that it's the "headphones" to a bluetooth sound device?

Posted: 20 Oct 2021 10:03 AM PDT

The simple version of this is that I have a sound playing device, that normally connects to bluetooth headphones. But instead I want my Linux machine to see that device as a "virtual microphone".

Concretely, this is a ham radio that would normally want a headset. But I want it into my Linux machine so that I can record it as wav files, or process the audio live.

I actually want both directions, ideally. In other words I want to play audio on Linux box to transmit on the radio.

Reformatting text using sed or awk

Posted: 20 Oct 2021 10:07 AM PDT

I have a input like where first row is the header, is it possible to reformat the text as the output below?

awk '{if ($2=="b" || $3 == "c" || $4 == "d" || $5 == "e" || $6 == "f" || $7 == "g" || $8 == "9" )'}'   

I tried above not working, I am a new beginner in Linux, any idea would be appreciated.

Input:

a b c d e f g h  a c g h  a e h   

Output:

a b c d e f g h  a   c       g h  a       e     h   

force Host setting group when ssh-ing via ip

Posted: 20 Oct 2021 09:45 AM PDT

supposed I have a ~/.ssh/config file with a few settings to apply to Host *.work.example.com

but sometimes I need to connect to hosts that doesn't yet have a DNS record.

I know of work arounds that are not practical:

  • add host to /etc/hosts
  • copy all the settings to the command line
  • duplicate the settings to another file and use ssh -F otherconfig

and solutions that are not possible:

  • move settings to the Host * section. I can't have the options applied to non-work hosts.

Is there a more practical way? maybe something like ssh -F but that picks a host group from the default config file, instead of duplicating file contents? or a way to provide ssh with a temporary hostname along with the ip?


edit: openssh manpage shows Host as a possible option for -o, but trying it i get "Host directive not supported as a command-line option"

Cant edit sources.list using mousepad [duplicate]

Posted: 20 Oct 2021 09:41 AM PDT

I'm trying to edit sources.list by sudo mousepad /etc/apt/sources.list

(mousepad:2161): Mousepad-CRITICAL **: 18:23:26.693: Failed to initialize xfconf: Failed to execute child process "dbus-launch" (No such file or directory)

mousepad /etc/apt/sources.list  

opens the file and I can see the contents.

Why is this, and how can I fix it?

How can I display directory file counts recursively with the ls command?

Posted: 20 Oct 2021 10:13 AM PDT

Under bash in Ubuntu, I want to ls -lah a directory and have it display file counts for directories recursively. That's to say I want it to count all files in the directories and their subdirectories.

Is this possible?

FFMPEG Multiple Filters (Scale Video + Scale / Apply Watermark)

Posted: 20 Oct 2021 08:40 AM PDT

Can someone please tell me the proper syntax for combining the following filters into a single command? I can't seem to figure it out.

The following command is being used to scale the video.

ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 -vf scale="'if(gt(a,4/3),1280,-1)':'if(gt(a,4/3),-1,720)'" -movflags +faststart output.mp4 2>&1  

Then, I use the following code to scale and apply the watermark.

ffmpeg -i input.mp4 -vf "movie=logo.png, scale=200:-1 [wm]; [in][wm] overlay=5:main_h-overlay_h-5 [out]" output.mp4 2>&1  

They work fine independently but every attempt I've made to combine the filter commands has been unsuccessful. Some assistance would be appreciated.

How do I tell ls -h to change the block size when calculating the human values?

Posted: 20 Oct 2021 09:12 AM PDT

I have already read this: https://www.gnu.org/software/coreutils/manual/html_node/Block-size.html#Block-size, I don't believe it addresses my question.

The issue is this: we're working on a file system where the blocks on the file system are 520 bytes each, rather than 512. So when I do a 'ls -h' it looks at a file, says "this file has 100 blocks, therefore it's (512B * 100) = 50 kb", but it's actually (520B * 100) = 51kb. Which means when we upload files to that file system, and check to make sure that the file was uploaded correctly, ls -h reports that all the sizes are wrong.

Is there a fix for this?

bash brace expansion: is it possible to associate another list(s) with the initial list?

Posted: 20 Oct 2021 09:29 AM PDT

Example:

$ eval echo "{x,y,z}\ --opt\; "  x --opt; y --opt; z --opt;  

Assume that the 2nd list is {1,2,3} and its length is equal to the length of the previous list.

Questions:

  1. How to make bash produce:
x --opt 1; y --opt 2; z --opt 3;  
  1. How to make bash produce (i.e. to refer the elements from the {x,y,z} list):
x --opt x; y --opt y; z --opt z;  

One-liners are preferred.

When writing a bash script, how does the script know which usage() to call?

Posted: 20 Oct 2021 09:55 AM PDT

Let's say I write a bash function like so:

function.sh

usage () {echo "No arguments are needed";}    myfunction () {    if [[ $# -qt 0 ]] ;  then     usage  fi    echo "Hello World"  }  

Then I source function.sh. However, I have another script with usage() defined there too and I have sourced it too.

I run myfunction -myWorld and I hit the usage() call and it calls the correct one somehow.

How does bash know which usage() to call?

vi doesn't see a file

Posted: 20 Oct 2021 08:22 AM PDT

I have been editing and trouble shooting a script. When I tried to edit it now, it shows an empty file and says[New File]. The file exists both ls and cat see it. And, I had edited about 10 minutes before. It doesn't appear to be a permission problem since I am logged in as root. Both vi and vim are acting the same way.

-rwxr-xr-x. 1 root root 3.2K Oct 20 10:30 CreateNgsIso.sh*  

UPDATE:

I figured out the problem. My script inadvertently deleted all the files in the directory. I am doing this remotely via ssh. In all the established ssh sessions, 'ls', 'cat', and 'scp' see the original files. If I initate another ssh session, I see the new files installed by the script and none of the old files. The new question is why does the established ssh sessions see the old files while the new session sees the new files.

Concatenate files by table values

Posted: 20 Oct 2021 10:31 AM PDT

I have a number of files each containing a specific pattern in their names like ABC1234001 which carry information about certain groups of my data (tables of multiple columns). I also have a table info.tsv like this:

group1    ABC1234001    ABC1234010  group2    ABC1234011    ABC1234018  group3    ABC1234019    ABC1234028  ...       ...           ...  

It contains:

  • "group" column, which specifies the group,
  • "first file" column, which specifies pattern for the first file (alphabetical order) containing info for the corresponding group,
  • "last file" column, which specifies pattern for the last file (alphabetical order) containing info for the corresponding group.

So what I need to do is combine files for each group into one file - just like

cat ABC123401{1..8}* >> group2.tsv  

would be for group2 as an example - while reading this info.tsv file. In this given example all files (ABC1234011.tsv, ABC1234012.tsv, ABC1234013.tsv, ABC1234014.tsv, ABC1234015.tsv, ABC1234016.tsv, ABC1234017.tsv, ABC1234018.tsv) are concatenated into a group2.tsv file

What I'm going to do is as follows:

while read $file; do    #assign columns to variables like $1="group", $2="firstfile", $3="lastfile"    cat *{$2..$3}* > $1.tsv;  done < info.tsv  

But I'm not quite sure how to iteratively change variables for this approach. Maybe using awk is more useful, but I don't know. The script should produce a bunch of files called group1.tsv, group2.tsv, that contain the contents of corresponding files from "first file" to "last file" in table. Please help me to write the script to do so.

How to type less/greater than (<, >) characters in US keyboard with non-US layout in settings

Posted: 20 Oct 2021 09:42 AM PDT

I'm using a Keychron K2 with a physical US layout that I set as Italian in my settings. This means I'm missing a few keys that exists only in the physical Italian layout keyboards. Specifically the keys highlighted in yellow are missing: enter image description here

My question is: how do I type the "<" and ">" characters if the key is missing?

I've dealt with this problem in the past and by pressing the right ALT + Shift + Z I was able to type the "less than" character. This solution is not working anymore, as with that combo of keys I get this ‹ character. What am I doing wrong?

How to set a file that is owned by a user but not readable by the owner?

Posted: 20 Oct 2021 09:44 AM PDT

I'm looking through the /proc directory and, as user, I'm not able to list a directory even though it shows that user is the owner.

Why and how does this happen?

For instance, in ls -l /proc/2323/map_files it says ls: reading directory '.': Permission denied. But the owner is clearly user. The user can cd into the directory but not ls. Doing this as root is fine though.

Added Backstory:

Currently the process is using firejail, which is a setuid binary, to drop caps and namespace isolate firefox. Without firejail, everything works as expected, i.e. user is able to ls map_files, but with firejail, the map_files directory cannot be ls by the user, though cd is fine. It isn't a permissions issue, since the directory is user readable, and the files, which are symlinks to .so files show u+r as well.

Create set of fixed sized compressed files from a large number of files

Posted: 20 Oct 2021 08:31 AM PDT

I have set of large number of files to be archived in a linux server. I need to compress those files in to set of 1GB compressed files.

I am using gzip to compress the files but I don't know the final size of the compressed folders until I really compressed the files. I am using below command to get the final size of the compressed file but it's not really efficient as I need to keep adding new files and compress until I get the desired final size.

tar -czf - /path/to/compressed-directory | wc -c  

Is there an efficient way to do this? Or should I consider compressing individual files and then create the final archive using individual compressed files?

Installing GCC 4.8.5 on CentOS 8

Posted: 20 Oct 2021 08:36 AM PDT

I am trying to install GCC 4.8.5 under CentOS 8 Classic using GCC 8.4.1. Here's what I did (the question has been updated to reflect the recent progress)

Get the prerequisites

yum install gcc make glibc-devel glibc-devel.i686  

Get the compiler and its dependencies as described here:

https://bytefreaks.net/gnulinux/downgrade-gcc-on-centos-7-0-64bit-to-version-4-8-2

wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz  tar -xvf gcc-4.8.5.tar.gz;  cd gcc-4.8.5/  ./contrib/download_prerequisites;  

Patch the files to avoid the double definition of libc_name_p as described here:

https://unix.stackexchange.com/a/571800

in file cfns.h included in except.c

Edit cfns.h and change the function declaration

#ifdef __GNUC__  __inline  

No comments:

Post a Comment