Sunday, October 24, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


How to store a nonconstant value in a certain moment in kernel modules

Posted: 24 Oct 2021 09:31 AM PDT

I wanna make a kernel module that displays the time past since the insertion of the module; and i'm gonna do that by subtracting values of Jiffies in the first moment and in the moment its /proc file is read. I tried to store jiffies in the very first moment through init function(which is called when the module is inserted). But I faced, 2 problems:

  1. I guess the value of jiffies is still changing, while i want only the value when the module was loaded
  2. The variable that i used to store jiffies is not global to other functions, so that i can operate on it.

Here is a part of my code:

#include<linux/module.h>  #include<linux/kernel.h>  #include<linux/init.h>  #include<linux/jiffies.h>  #define j jiffies    void init_function(void)   {       //This variable init_jif is not recognized by other functions and        //i think its value is still changing just like j         static unsigned long init_jif = j;         //rest of the code  }  module_init(init_function);  

I'll appreciate if anyone could help me with it.

redirect from right to left into code block

Posted: 24 Oct 2021 09:48 AM PDT

Consider this scenario:

diff file.txt <( cat file.txt | grep -v '^\s*#'| sed '/^$/d' )  

this is an example of redirect from right to left, in which you process a file and redirect the result as input to diff. Similar use case has been proposed here, which also works fine.

However, attempt to redirect result of file processing to a code block in a similar fashion fails:

  while read I; do      …    done <( cat $FIL | <do_something_here> )  

Syntax error: "(" unexpected

Or, if you try this:

done < <( cat $FIL | <do_something_here> )  

Syntax error: redirection unexpected

How do you redirect output of some process to code block as input?

Failed to start User Manager for UID 126 - Ubuntu 21.04

Posted: 24 Oct 2021 09:18 AM PDT

It started to give an error when downloading files from the internet, it said something like: Does not have permission to save the file.

now is given me this error: [FAILED] Failed to start User Manager for UID 126

Does anyone know what can be done?

thanks in advance!

Crackling sound on 3.5 jack whenever I had a few seconds without playing sounds

Posted: 24 Oct 2021 09:10 AM PDT

Symptoms


Whenever I plug an audio jack into my PC a loud crackling can be heard in the headphones (tried 2 different pairs), it also happens whenever I play a sound if I didn't already have another audio playing in the last few seconds.

It is as if an audio service or card were putting itself to sleep after a few dozen seconds of inactivity and resuming it would cause a single crackling noise then the audio is clean again. A similar but much less agressive sound is heard a few seconds after an audio is done playing.

The crackling sound is much louder at its first instance (after boot) than any other time, it also happens whenever I plug in headphones or when the pc turns off.

System


I use a clean install of Parrot OS 5.0 (LTS) (debian based) on a stock HP ENVY PHOENIX 860-080nz 1.04(except for the storage), the issue was there from day one.

Here is the output of cat /proc/asound/cards

 0 [PCH            ]: HDA-Intel - HDA Intel PCH                        HDA Intel PCH at 0xdf320000 irq 129   1 [NVidia         ]: HDA-Intel - HDA NVidia                        HDA NVidia at 0xdf080000 irq 17   2 [AUDIO          ]: USB-Audio - USB  AUDIO                        USB  AUDIO at usb-0000:00:14.0-7, full speed  

Devices 0 and 1 use the snd_hda_intel driver which is native to the kernel, I didn't touch this.

Here is cropped output of lspci -v

01:00.1 Audio device: NVIDIA Corporation GM200 High Definition Audio (rev a1)          Subsystem: Hewlett-Packard Company GM200 High Definition Audio          Flags: bus master, fast devsel, latency 0, IRQ 17          Memory at df080000 (32-bit, non-prefetchable) [size=16K]          Capabilities: <access denied>          Kernel driver in use: snd_hda_intel          Kernel modules: snd_hda_intel  [...]  00:1f.3 Audio device: Intel Corporation 100 Series/C230 Series Chipset Family HD Audio Controller (rev 31)          DeviceName: Onboard Audio          Subsystem: Hewlett-Packard Company 100 Series/C230 Series Chipset Family HD Audio Controller          Flags: bus master, fast devsel, latency 32, IRQ 129          Memory at df320000 (64-bit, non-prefetchable) [size=16K]          Memory at df300000 (64-bit, non-prefetchable) [size=64K]          Capabilities: <access denied>          Kernel driver in use: snd_hda_intel          Kernel modules: snd_hda_intel  

Other tests I did


USB speakers work perfectly fine.

This happens whether I am in headless mode or not (I suspected it might be KDE as the first crackling at boot comes during the KDE splash logo)

I dual boot with windows and have no such issues on the Windows side so I'm certain it's no hardware issue.

supervise: logging all services to main process

Posted: 24 Oct 2021 07:53 AM PDT

I am using supervisord for running services inside Docker container. I want all services to log to the main output (so that I can see it when running with docker-compose), which I do by including the following in each service's section (I found this somewhere, but it is trick which does the job; there is CMD ["/usr/bin/supervisord"] in the Dockerfile of course, so I know what is PID 1):

[program:foo]  command=...  user=...  directory=...    stdout_logfile=/proc/1/fd/1  stderr_logfile=/proc/1/fd/1  stdout_logfile_maxbytes=0  stderr_logfile_maxbytes=0  

It makes the configuration file unconveniently long and repetitive. Is there a way to specify this in a more compact manner, for all services at once?

Better yet, is there an easy way to make all services log to the supervisor standard output, and additionally prepending each line with service name?

Trying to learn how web servers work [closed]

Posted: 24 Oct 2021 08:03 AM PDT

I'm trying to go in depth on how web servers work how to configure them how to sercurely protect them etc I was just wondering if anyone could give me some good recources that I can learn from my prefernce is the hands on approach I'd like to actually get in there and actually do everything myself

Draw a rectangle with imagemagick

Posted: 24 Oct 2021 07:49 AM PDT

How can I draw a simple rectangle. Docu adds a black point which I don't want.

less a file with JSON rows - how to highlight/colorize the rows?

Posted: 24 Oct 2021 09:34 AM PDT

I have log files with json rows inside - less displays it as just plain text
Can I colorize the output with less abilities?
As well as I didn't find any less-compatible third party tool with json highlighting
Example of such file

{"date":"2021-10-21 16:09:54", "perf":{"action":"getTimelineByClient", "time":46.2}}  {"date":"2021-10-22 16:09:54", "perf":{"action":"getTimelineByClient", "time":46.2}}  {"date":"2021-10-23 16:09:54", "perf":{"action":"getTimelineByClient", "time":46.2}}  

Libparted not found parrot os installation error

Posted: 24 Oct 2021 06:40 AM PDT

I have a usb with parrot os on it. I have used it previously to install parrot on a few devices. I have a laptop with a faulty hard drive (gives SMART error ). Tried to use it to install parrot on an external drive but the installer says "Libparted not found" and closes it self. Any help?

Configuring the firewall with iptables

Posted: 24 Oct 2021 08:56 AM PDT

I have an instance of SSH running port 2233 and a Cowrie honeypot on port 2222.

SSH needs to stay that way but Cowrie needs to be forwarded to port 22.

Port 2222 (running Cowrie) shouldn't be visible from the outside world. Internal (local) traffic should run as it is. Every other incoming/outgoing traffic must be blocked.

I have to configure it using iptables only. I've tried reading man pages for iptables & a bunch of blog posts for the last 2 days. I'm tired and would really appreciate any help...

ifdown: interface enp0s3 not configured. RTNETLINK answers: File exists. ifup: failed to bring up enp0s3

Posted: 24 Oct 2021 06:31 AM PDT

I have a virtual box (6.1) with ubuntu minimal. in the settings of the virtual machine in the network section, "Bridged Adapter" is selected.

root@ubuntu:/home/mista# dmesg -T|head -1  [Sun Oct 24 10:56:10 2021] Linux version 5.4.0-89-generic (buildd@lgw01-amd64-044) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 (Ubuntu 5.4.0-89.100-generic 5.4.143)    root@ubuntu:/home/mista# ip a        1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000          link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00          inet 127.0.0.1/8 scope host lo             valid_lft forever preferred_lft forever          inet6 ::1/128 scope host              valid_lft forever preferred_lft forever      2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000          link/ether 08:00:27:1e:5b:6d brd ff:ff:ff:ff:ff:ff          inet 192.168.88.236/24 brd 192.168.88.255 scope global dynamic enp0s3             valid_lft 473sec preferred_lft 473sec          inet6 fe80::a00:27ff:fe1e:5b6d/64 scope link              valid_lft forever preferred_lft forever    root@ubuntu:/home/mista# cat /etc/network/interfaces  # interfaces(5) file used by ifup(8) and ifdown(8)  # Include files from /etc/network/interfaces.d:  source-directory /etc/network/interfaces.d    auto lo  iface lo inet loopback    auto enp0s3  iface enp0s3 inet static  address 192.168.88.236  netmask 255.255.255.0  gateway 192.168.88.1    root@ubuntu:/home/mista# ifdown enp0s3  ifdown: interface enp0s3 not configured    root@ubuntu:/home/mista# ifup enp0s3  RTNETLINK answers: File exists  ifup: failed to bring up enp0s3    root@ubuntu:/home/mista# systemctl status networking    ● networking.service - Raise network interfaces       Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)       Active: failed (Result: exit-code) since Sun 2021-10-24 11:24:35 MSK; 1min 39s ago         Docs: man:interfaces(5)      Process: 826 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)     Main PID: 826 (code=exited, status=1/FAILURE)    Oct 24 11:24:35 ubuntu systemd[1]: Starting Raise network interfaces...  Oct 24 11:24:35 ubuntu ifup[844]: RTNETLINK answers: File exists  Oct 24 11:24:35 ubuntu ifup[826]: ifup: failed to bring up enp0s3  Oct 24 11:24:35 ubuntu systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE  Oct 24 11:24:35 ubuntu systemd[1]: networking.service: Failed with result 'exit-code'.  Oct 24 11:24:35 ubuntu systemd[1]: Failed to start Raise network interfaces.      root@ubuntu:/home/mista# cat /run/network/ifstate  lo=lo  

I tried to add the string "enp0s3=enp0s3" to /run/network/ifstate but it doesn't work. But /run - it's a virtual file system and the string with enp0s3 will be delete after reload daemons or reboot the server. Some people say that all configured interfaces should be displayed in /run/network/ifstate. But why, then, the enp0s3 interface is not displayed in the /run/network/ifstate if it is registered in the config ?

And may be I have some mistake in config file?

after reboot, the address 192.168.88.236/24 rises, but these commands do not work:

ifup enp0s3  ifdown enp0s3  

I don't understand why errors are coming out:

root@ubuntu:/home/mista# ifdown enp0s3  ifdown: interface enp0s3 not configured    root@ubuntu:/home/mista# ifup enp0s3  RTNETLINK answers: File exists  ifup: failed to bring up enp0s3  

Where ifup and ifdown can get the config to work with the interface except for the file /etc/network/interfaces?

The file /etc/networks is empty.

How to move every file in a folder to a subdirectory of the same name?

Posted: 24 Oct 2021 09:26 AM PDT

Say I have a bunch of files in a directory

filename-1.ext1  filename-1.ext2  filename-1.ext3  filename-2.ext1  filename-2.ext2  filename-2.ext3  filename-3.ext1  filename-3.ext2  filename-3.ext3  

I then want to create subdirectories in the same directory of the same name as the files (filename but no ext) and move them in like this

filename-1  ├──filename-1.ext1  ├──filename-1.ext2  └──filename-1.ext3  filename-2  ├──filename-2.ext1  ├──filename-2.ext2  └──filename-2.ext3  filename-3  ├──filename-3.ext1  ├──filename-3.ext2  └──filename-3.ext3  

What would be the most efficient way to achieve this?

Edit: ext1, ext2, ext3 are just to indicate three distinct filenames, like .foo, .bar, .top, .coffee etc. Not that the filenames are similar.

Why sudo apt install /path/*.deb produces permisson denied whereas sudo dpkg -i /path/*.deb works fine?

Posted: 24 Oct 2021 07:01 AM PDT

I was wondering for a long time why sudo apt fails to install local deb from some folders with error:

Failed to fetch a file... Permission denied   

Recently I've tried sudo dpkg -i same path and it worked. The path is on USB mounted with udisks, so it is inside a /media/user folder and as of now my guess it is due to ACL on that folder (drwxr-x---+). But why a command with sudo gets permission denied? Why then other command on same files works fine?

I would use dpkg but it does not process pre-dependencies in proper order as opposed to apt.

Is there any way to skip fetching part for apt? Before fetching, near start of output apt gives Note selecting abc instead of abc.20-2-a.deb. Is there a way to make apt process particular deb files, not to try to locate others?

P.S. I'm aware of other ways to install local debs, e.g. adding local repository or using non-preinstalled apt-offline from How to install packages without internet , but I'd like to keep things simple (plus I suspect local repository way could face same permission denied issue).

Added:

permissions inc. ACL:

mint@mint:~$ ls -la /media/mint/rd  total 0  drwxrwxrwt  4 root root 80 Oct 24 03:23 .  drwxr-xrw-+ 4 root root 80 Oct 24 03:22 ..  drwxrwxrwx  2 mint mint 80 Oct 12 23:01 ffmpeg  drwxrwxrwx  2 mint mint 60 Oct 11 17:53 mpv    ACL:  mint@mint:~$ getfacl /media/mint/  getfacl: Removing leading '/' from absolute path names  # file: media/mint/  # owner: root  # group: root  user::rwx  user:mint:r-x  group::---  mask::r-x  other::rw-  

apt / apt-get output:

mint@mint:~$ sudo apt install -d /media/mint/rd/ffmpeg/*.deb  Reading package lists... Done  Building dependency tree         Reading state information... Done  Note, selecting 'ffmpeg' instead of '/media/mint/rd/ffmpeg/ffmpeg_7%3a4.2.4-1ubuntu0.1_amd64.deb'  Note, selecting 'libavresample4' instead of '/media/mint/rd/ffmpeg/libavresample4_7%3a4.2.4-1ubuntu0.1_amd64.deb'  Suggested packages:    ffmpeg-doc  The following NEW packages will be installed:    ffmpeg libavresample4  0 upgraded, 2 newly installed, 0 to remove and 71 not upgraded.  Need to get 1507 kB of archives.  After this operation, 2275 kB of additional disk space will be used.  Ign:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1  Ign:2 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1  Ign:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1  Ign:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1  Get:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1 [54.2 kB]  Err:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1    File not found - /media/mint/rd/ffmpeg/libavresample4_70x0.07ffe00000006p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  Get:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1 [1453 kB]  Err:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1    File not found - /media/mint/rd/ffmpeg/ffmpeg_70x0.07ffe00000002p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  E: Failed to fetch file:/media/mint/rd/ffmpeg/libavresample4_7%3a4.2.4-1ubuntu0.1_amd64.deb  File not found - /media/mint/rd/ffmpeg/libavresample4_70x0.07ffe00000006p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  E: Failed to fetch file:/media/mint/rd/ffmpeg/ffmpeg_7%3a4.2.4-1ubuntu0.1_amd64.deb  File not found - /media/mint/rd/ffmpeg/ffmpeg_70x0.07ffe00000002p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  E: Some files failed to download  mint@mint:~$ sudo apt-get install -d /media/mint/rd/ffmpeg/*.deb  Reading package lists... Done  Building dependency tree         Reading state information... Done  Note, selecting 'ffmpeg' instead of '/media/mint/rd/ffmpeg/ffmpeg_7%3a4.2.4-1ubuntu0.1_amd64.deb'  Note, selecting 'libavresample4' instead of '/media/mint/rd/ffmpeg/libavresample4_7%3a4.2.4-1ubuntu0.1_amd64.deb'  Suggested packages:    ffmpeg-doc  The following NEW packages will be installed:    ffmpeg libavresample4  0 upgraded, 2 newly installed, 0 to remove and 71 not upgraded.  Need to get 1507 kB of archives.  After this operation, 2275 kB of additional disk space will be used.  Ign:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1  Ign:2 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1  Ign:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1  Ign:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1  Get:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1 [54.2 kB]  Err:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libavresample4 amd64 7:4.2.4-1ubuntu0.1    File not found - /media/mint/rd/ffmpeg/libavresample4_70x0.07fff00000006p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  Get:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1 [1453 kB]  Err:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 ffmpeg amd64 7:4.2.4-1ubuntu0.1    File not found - /media/mint/rd/ffmpeg/ffmpeg_70x0.07fff00000002p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  E: Failed to fetch file:/media/mint/rd/ffmpeg/libavresample4_7%3a4.2.4-1ubuntu0.1_amd64.deb  File not found - /media/mint/rd/ffmpeg/libavresample4_70x0.07fff00000006p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  E: Failed to fetch file:/media/mint/rd/ffmpeg/ffmpeg_7%3a4.2.4-1ubuntu0.1_amd64.deb  File not found - /media/mint/rd/ffmpeg/ffmpeg_70x0.07fff00000002p-10224.2.4-1ubuntu0.1_amd64.deb (13: Permission denied)  E: Some files failed to download  

print lines where each word contains two same characters in Linux

Posted: 24 Oct 2021 09:22 AM PDT

I have input like this

LTCYMM SVNNDA DTVEV QLOPGO CUPUR  MMWVJM LIVLI WBSVD UQCMW HBMDA HVVFY BWYSS  NOGWOS JIKKDI GCIQAD MXJNWE SMVFCB GIZVPA GZOHZR WJBMZS  KKPQBP BKDKRU ZTPDPL ZRLUEL HRZZKO KXSKCU YZQTBT RISNKS  VYQQC BFAWI NSZDV HKPGI KVJOC COPPS  JGU YLN MXW ACR BZA HOP  TMCVPT HBNGIH IQYGCI DTQPON WXANKG GMIYZS  CWVT BUBA NSGR MUPO LDNS  

i am trying to print lines where each word contains at leats two same characters, useing grep command The longest line contains 8 words ، I think I can solve it like that ،but i feel that is the wrong way ,

grep '^.*\([A-Z]\)[^ ]*\1[^ ]* [^ ]*\([A-Z]\)[^ ]*\2[^ ]*   [^ ]*\([A-Z]\)[^ ]*\3[^ ]* [^ ]*\([A-Z]\)[^ ]*\4[^ ]* [^ ]*\([A-Z]\)[^ ]*\5[^ ]* [^ ]*\([A-Z]\)[^ ]*\6[^ ]* [^ ]*\([A-Z]\)[^ ]*\7[^ ]* [^ ]*\([A-Z]\)[^ ]*\8[^ ]*$/| .... for 7 words | for 6 ...  

expected output

 LTCYMM SVNNDA DTVEV QLOPGO CUPUR   KKPQBP BKDKRU ZTPDPL ZRLUEL HRZZKO KXSKCU YZQTBT RISNKS  

How do I get faxes to a folder instead of having to print them with an HP printer?

Posted: 24 Oct 2021 09:31 AM PDT

I've got an HP Color LaserJet Pro MFP M479fdn which is capable of receiving faxes and save them in a folder. Only when I look at the interface, it tells me I have to enter a "shared folder".

Here is the concerned page:

Fax Setup

Is there a way to make this work with just standard Linux folders? Or is it necessary for me to setup Samba to get it working? I would prefer to avoid samba if at all possible.


Update:

As answered below, there isn't really another solution. The fact is that I already had samba installed so all I had to do is add one entry like so:

[fax]                                                                                 comment = Faxes on Monster                                                        path = /home/fax                                                                  read only = no                                                                    browsable = yes                                                               

create the user:

sudo adduser --system --ingroup sambashare fax  sudo mkdir /home/fax/folder  sudo chown fax:sambashare /home/fax/folder  sudo passwd fax  

and restart the service:

sudo systemctl restart smbd  

Then I could use the following share folder in my HP settings:

\\fax\folder  

which was accepted. The next page asks for the user and password, I used "fax" and the password I entered when I ran passwd.

I'm not 100% sure that it works at this point, I need to receive a fax...

Part of this setup is based on the Ubuntu install and configure samba page.

Kernel panic while install OpenBSD

Posted: 24 Oct 2021 06:51 AM PDT

Kernel panic while install OpenBSD.


I tried installing the system but this is the error message that I have got:

Kernel panic.

Steps I tried:

  1. Reinstalling on the same ISO file.
  2. I have tried by reinstalling the ISO file and see if that fix the issue.

Thanks Jonathan Steadman.

The helpful guide I followed: https://www.openbsdhandbook.com/installation/

hard drive read throughput terrible after running badblocks, recoverable?

Posted: 24 Oct 2021 08:32 AM PDT

I have a collection of new drives, a friend recommended I run badblocks on the new drives before using them. I ran badblocks on some of the new drives before imaging them badblocks -v -s -w -b 4096 -o ./sda.log /dev/sda, other drives I imagined new without badblocks. ps I also ran conveyance smart tests on the badblocks drives, passed.

For the drives that I ran badblocks on, read throughput after imaging is very low dd if=/dev/sda bs=4096 of=/dev/null count=1M with caches dropped average's 71.1MB/s. For the drives that were just burned with a disk image, the average read rate is 195MB/s.

Did I "break" these drives by running bad blocks? Can I recover/reset them?

Smart shows a

  • high spin-up time for the badblocks'd ~3000 (0 for new drives)
  • Zero read error and zero sector relocation on all drives.
  • self-test's pass on all drives
  • otherwise nearly identical smartctl -a reports

Reformatting text using sed or awk

Posted: 24 Oct 2021 07:56 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 :

Name    Date          Time          Mxam     Mxterm  Maxus   Date:su,mo    Time:12,3:00  mxam:20  Mxterm:10  Feros   Time:12,3:00  Mxterm:19  Michel  Mxterm:16         

Desired output

Name    Date           Time              Mxam     Mxterm  Maxus   Date:su,mo     Time:12,3:00      mxam:20  Mxterm:10  Feros                  Time:12,3:00               Mxterm:19  Michel                                            Mxterm:16  

Why two bridged veth cannot ping each other?

Posted: 24 Oct 2021 09:30 AM PDT

I need to set up a network environment where two veth interfaces is attached to one bridge and they need to be able to communicate with each other.

So I execute the following commands in a clean ubuntu shell:

# Create Two veth and attach them to the bridge  sudo ip link add veth0 type veth peer name veth0p  sudo ip link add veth1 type veth peer name veth1p  sudo brctl addbr br0  sudo brctl addif br0 veth0p  sudo brctl addif br0 veth1p    # Set links up  sudo ip link set veth0 up  sudo ip link set veth1 up  sudo ip link set veth0p up  sudo ip link set veth1p up  sudo ip link set br0 up    # Give each veth an IP address  sudo ip addr add 10.0.0.1/24 dev veth0  sudo ip addr add 10.0.0.2/24 dev veth1    # Try to ping one from the other  ping 10.0.0.1 -I veth1  

The ping does not work. Could anyone help me on this? What should I do to make veth0 and veth2 being able to ping each other?

The output of the ip r s is:

default via 192.168.0.1 dev ens160 proto dhcp src 192.168.0.119 metric 100   10.0.0.0/24 dev veth0 proto kernel scope link src 10.0.0.1   10.0.0.0/24 dev veth1 proto kernel scope link src 10.0.0.2   192.168.0.0/24 dev ens160 proto kernel scope link src 192.168.0.119   192.168.0.1 dev ens160 proto dhcp scope link src 192.168.0.119 metric 100   

The purpose of this is to put those two veth interfaces into a VXLAN overlay network later. But for development purpose, I want to test the bridge and the two interfaces without the VXLAN been set up at this point. (But even though there is no VXLAN set up, they should be able to ping each other as long as they are on the same bridge right?)

Thank you!

ArchLinux "Failed to pair: org.bluez.Error.AlreadyExists"

Posted: 24 Oct 2021 07:07 AM PDT

I attempted to connect to a device doing:

bluetoothctl  power on  agent on  default-agent  scan on    trust [device id]  pair [device id]  

Which gave me the error: Failed to pair: org.bluez.Error.AlreadyExists

I wasn't able to find any other issues online with this error.

I then tried doing:

pulseaudio -k  pulseaudio --start  

which failed, and I got the same error. I also tried rebooting. If you need anything else specified, please ask.

How to automatically detect and write to usb with variable spaces in its name

Posted: 24 Oct 2021 10:02 AM PDT

I am doing the second BASH exercise from TLDP Bash-Scripting Guide, and I have most of it figured out up until the part when it comes time to copy the compressed files to an inserted USB.

Home Directory Listing

Perform a recursive directory listing on the user's home directory and save the information to a file. Compress the file, have the script prompt the user to insert a USB flash drive, then press ENTER. Finally, save the file to the flash drive after making certain the flash drive has properly mounted by parsing the output of df. Note that the flash drive must be unmounted before it is removed.

As I progress with the script it is becoming less ..elegant, and was wondering if there was a better way to do this. I know creating files is likely not the most efficient way to do the comparisons, but have not got the shell expansions figured yet, and intend to change those once I get it working.

The problem specifically is, to ensure that the usb is mounted and that I am writing to the USB and nowhere else. I am comparing the last line of df after the USB is plugged in with the last line of df from the diff between df before USB is plugged in and df after USB is plugged in, and looping until they match. Unfortunately, the diff result starts with a >, but I intend to use sed to get rid of that. The real problem is the path to where my usb is mounted is:

/media/flerb/"Title of USB with spaces"

To make this portable for USBs that may have different names is my best bet from here to do something with awk and field separators? And as a follow-up, I know this is pretty inelegant, and wonder if there is a cleaner way to go about this...especially because this is the second exercise and still in EASY.

The output from the df tails is:

/dev/sdb1                     15611904  8120352   7491552  53% /media/flerb/CENTOS 7 X8  > /dev/sdb1                     15611904  8120352   7491552  53% /media/flerb/CENTOS 7 X8  

The script so far

 1 #!/bin/bash    2     3 if [ "$UID" -eq 0 ] ; then    4         echo "Don't run this as root"    5         exit 1    6 fi    7     8 #Create a backup file with the date as title in a backup directory    9 BACKUP_DIR="$HOME/backup"   10 DATE_OF_COPY=$(date --rfc-3339=date)   11 BACKUP_FILE="$BACKUP_DIR/$DATE_OF_COPY"   12    13 [ -d "$BACKUP_DIR" ] || mkdir -m 700 "$BACKUP_DIR"   14    15 #find all files recursively in $HOME directory   16 find -P $HOME >> "$BACKUP_FILE"   17    18 #use lzma to compress   19 xz -zk --format=auto --check=sha256 --threads=0 "$BACKUP_FILE"   20    21 #making files to use in operations   22 BEFORE="$BACKUP_DIR"/before_usb.txt   23 AFTER="$BACKUP_DIR"/after_usb.txt   24 DIFFERENCE="$BACKUP_DIR"/difference.txt   25    26 df > "$BEFORE"   27 read -p 'Enter USB and press any button' ok   28 sleep 2   29 df > "$AFTER"   30 diff "$BEFORE" "$AFTER" > "$DIFFERENCE"   31 sleep 2   32 echo   33    34 TAIL_AFTER=$(tail -n 1 "$AFTER")   35 TAIL_DIFF=$(tail -n 1 "$DIFFERENCE")   36    37 until [ "$TAIL_AFTER" == "$TAIL_DIFF" ] ;   38 do   39         echo "Not yet"   40         df > "$AFTER"   41         TAIL_AFTER=$(tail -n 1 "$AFTER")   42         diff "$BEFORE" "$AFTER" > "$DIFFERENCE"   43         TAIL_DIFF=$(tail -n 1 "$DIFFERENCE")   44         echo "$TAIL_AFTER"   45         echo "$TAIL_DIFF"   46         sleep 1   47    48 done   49 exit $?  

Grub2 boot from USB3 PCIe card

Posted: 24 Oct 2021 07:33 AM PDT

I have grub2 installed on my PC's internal hard drive and I am trying to boot a debian installation on a USB key. The PC doesn't have any USB 3 ports so I have added a USB 3 PCIe card. I know that most PCIe USB3 cards don't have boot ROMs, so my plan was to load grub2 from the hard drive and then boot into the USB key.

When the USB key is plugged into a USB 2 port everything works fine in the setup. When I try to instead plug into the USB3 port on the PCIe card, the following error appears:

Blockquote error: no such device: UUID of drive here

After that grub goes into the rescue mode and ls only shows (hd0), (hd0,msdos1), and (hd0,msdos2). So it's as if grub can't "see" the usb key.

I've added insmod for usb, usbms, xhci, echi, uhci to /boot/grub/grub.cfg . I know the USB 3 port works from linux because when I run from a distro on the hard drive I am able to mount from usb keys in the port. Is there any way to get grub2 to support the PCIe USB ports?

Bonding wired and wireless while using Network Manager

Posted: 24 Oct 2021 09:59 AM PDT

I'm running Linux Mint 17.3 on my laptop. When docked, I'm connected via Ethernet, but when I undock, I'd like not to break my ssh sessions, ongoing downloads, etc., and to use the same IP address on the Wi-Fi adapter, so that still appears the same to other machines on my network.

Bonding in mode 1, active backup, sounds exactly like what I want. I've found a number of resources online about how to set it up, but network configuration seems to vary quite a bit between distributions and even between different versions of each distribution, so that the steps for this vary quite a bit.

What's more, most of the instructions I've found rely on static configuration, like hardcoding network addresses and even WPA passwords into /etc/network/interfaces. I take my laptop to other networks, so I rely on Network Manager to store network configuration.

By googling "bond eth0 wlan0", I found a sample /etc/networking/interfaces file that more or less works, but I apparently have to disable Network Manager to keep it from doing weird things with my routing table. And while the bond is active, I can't seem to use the Network Manager applet to change Wi-Fi networks.

Network Manager 0.9.8 supports bonded interfaces, but only for Ethernet and InfiniBand connections, not for Wi-Fi.

Is there a way to bond Ethernet and Wi-Fi connections that's compatible with Network Manager?

Errno 5 Input/output error when running yum check-update

Posted: 24 Oct 2021 08:02 AM PDT

I tried to update a server over SSH, but when I ran yum check-update I got an error:

[error 5] Input/output error

I think this means the RPM libraries may be damaged or corrupt, but I'm not sure how to resolve this.

Bluetoothctl: No default controller available, despite being unblocked

Posted: 24 Oct 2021 07:08 AM PDT

I'm having issues connecting my Logitech K810 Bluetooth keyboard in Debian Jessie with BlueZ version 5.23-1, kernel 3.16.0-4.

The keyboard works fine most of the time but sometimes it doesn't work at all and bluetoothctl gives me the error that the controller is unavailable.

When this occurs, hciconfig still recognizes the device and I get this output:

# hciconfig hci0 up   # hciconfig  hci0:   Type: BR/EDR  Bus: USB      BD Address: 40:2C:F4:68:02:CA  ACL MTU: 1021:8  SCO MTU: 64:1      UP RUNNING PSCAN       RX bytes:21820 acl:1132 sco:0 events:68 errors:0      TX bytes:1182 acl:11 sco:0 commands:53 errors:0  

But no devices are shown in the bluetoothctl prompt and it gives me this output:

[bluetooth]# power on  No default controller available  [bluetooth]# scan on  No default controller available  

Rebooting or sometimes suspending/resuming fixes the issue: bluetoothctl will again recognize both the controller and the keyboard which works again.

Bluetooth is consistently hard and soft unblocked according to rfkill.

The relevant output from lspci -v, I guess would be this:

03:00.0 Network controller: Intel Corporation Centrino Wireless-N 1000 [Condor Peak]          Subsystem: Intel Corporation Centrino Wireless-N 1000 BGN          Flags: bus master, fast devsel, latency 0, IRQ 43          Memory at f0400000 (64-bit, non-prefetchable) [size=8K]          Capabilities: <access denied>          Kernel driver in use: iwlwifi  

I didn't have this problem with the same hardware in Debian Wheezy.

What could it be the bluetooth controller to be unavailable at times?

using _< instead of < for stdin using bash

Posted: 24 Oct 2021 09:50 AM PDT

What is the difference between using _< and < for stdin when using process substitution. This is done using bash.

Example:

read bytes _< <(du -bcm random_iso.iso | tail -1); echo $bytes  

Customize wingpanel under Elementary OS

Posted: 24 Oct 2021 09:04 AM PDT

Recently I have installed Elementary OS luna, which is based on Ubuntu. I want to customize the wingpanel to display the menu toolbar of the selected application.

This is my wingpanel: what I got

But I need it to look like this: what I Want

The File, Edit, Selection and other menus, and the Close, maximize and minimize icons are on the wingpanel.

How to test whether a file uses CRLF or LF without modifying it?

Posted: 24 Oct 2021 09:57 AM PDT

I need to periodically run a command that ensures that some text files are kept in Linux mode. Unfortunately dos2unix always modifies the file, which would mess file's and folder's timestamps and cause unnecessary writes.

The script I write is in Bash, so I'd prefer answers based on Bash.

1 comment:

  1. E-Techbytes: Recent Questions - Unix And Linux Stack Exchange >>>>> Download Now

    >>>>> Download Full

    E-Techbytes: Recent Questions - Unix And Linux Stack Exchange >>>>> Download LINK

    >>>>> Download Now

    E-Techbytes: Recent Questions - Unix And Linux Stack Exchange >>>>> Download Full

    >>>>> Download LINK T1

    ReplyDelete