Saturday, July 3, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Script runs from standard crontab but not root crontab

Posted: 03 Jul 2021 11:53 AM PDT

I have a script that starts up a program of mine. I want it to run at boot. It works fine when I put it in crontab -e, but when I put it in sudo crontab -e nothing happens, not even a log file is produced. I wonder what could be the reason for it? I need root access for accessing the serial port in a new version of that program.

The crontab command is:

@reboot sh ~/project/tensorrt_demos/launcher2.sh >> ~/project/tensorrt_demos/smart_bike.log 2>&1  

Some characters get lost when pasting large amounts of text into serial console

Posted: 03 Jul 2021 11:23 AM PDT

When pasting large amounts of text into a serial console like screen or minicom, some characters get lost and are not being transmitted.

Reduce high power consumption of Intel Wifi 6 AX201

Posted: 03 Jul 2021 10:51 AM PDT

According to $ powertop, the WiFi card (Intel Wifi 6 AX201) in my Thinkpad X1 Carbon Gen9 (running Ubuntu 21.04) is often drawing between 4 and 5W in battery mode, thereby reducing my laptop's battery life by several hours. This happens while my laptop is connected to a wifi network and even when there's little to no traffic occurring on the wifi interface.

I find this incredible, given that I've been using Intel Wifi cards in other laptops over the years and none of them have drawn that much power.

Is there any way for me to reduce the wifi card's power consumption? The Intel docs mention different power modes (max performance/medium power saving/max power saving) and I'm wondering how to switch between those.

Some diagnostic info:

$ lspci | grep -i "wi-fi"                                                                                           130 ↵  00:14.3 Network controller: Intel Corporation Wi-Fi 6 AX201 (rev 20)  
cat /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf  [connection]  # Values are 0 (use default), 1 (ignore/don't touch), 2 (disable) or 3 (enable).  wifi.powersave = 3  

(Accordingly, iwconfig shows "Power Management:on" for the wifi interface.)

ThinkWiki mentions there being a file /sys/bus/pci/devices/0000:00:14.3/power_level but the file doesn't exist on my system. The only thing I've found is:

$ cat /sys/bus/pci/devices/0000:00:14.3/power_state  D0  

(Not sure what this means)

At the same time, iwpriv also doesn't show any driver-specific parameters that I could set:

$ iwpriv wlp0s20f3                                                    wlp0s20f3  no private ioctls.  

How do you undo a line undo in Vim?

Posted: 03 Jul 2021 09:01 AM PDT

The u key undos last change and ctrl r redos it, but the U letter undos changes on a line, and ctrl r doesn't redo it and there is no such thing as ctrl R line redo key? Am I not searching for it correctly or it doesnt exist?

Pipe break error when reading piped program output

Posted: 03 Jul 2021 09:36 AM PDT

I'm doing something along these lines:

declare -Ft handle_format_output &>/dev/null && exit 1   # test if this function name is already present in this scope  handle_format_output() {      case $1 in      domain) ./scripts/idn_to_punycode.pl >>"${2}_${1}.txt" ;;      ipv4)          # read doesn't bother w/ pipe input as its undefined: guessing it's leading to pipe breaks          # therefore open stdin as a separate file and read from it to close the previous pipe          while IFS= read -r line <&3; do              case $line in              */*) printf "%s\n" "$line" >>"${2}_${1}_cidr.txt" ;; # cidr block              *-*) ipcalc "$line" >>"${2}_${1}_cidr.txt" ;;        # deaggregate ip range              *) printf "%s\n" "$line" >>"${2}_${1}.txt" ;;        # ip address              esac          done 3< /dev/stdin          ;;      ipv6) cat -s >>"${2}_${1}.txt" ;;      esac  }    ...  |    mawk '!seen[$0]++' | # filter duplicates and blank lines    handle_format_output "$format" "$color"  

Where the input is linear text that's either a web domain, IPv4 address, IPv4 CIDR block, or IPv6 address. The format is either "domain," "ipv4," or "ipv6." The color is either "white" or "black."

This error keeps being thrown no matter what I'm trying:

mawk: write failure (Broken pipe)  mawk: close failed on file /dev/stdout (Broken pipe)  Error: Process completed with exit code 2.  

What am I doing wrong?

Detect if a script is being run via shebang or was specified as a command line argument

Posted: 03 Jul 2021 08:40 AM PDT

In the Pyenv project, we've had a peculiar problem.

We are substituting python (and python*) with our Bash scripts ("shims") that select a Python executable to run at runtime.

Now, some users wish to use a special selection logic when a Python script is run as path/to/script.py. The problem is, this logic should NOT apply if the script is instead run as <python> path/to/script.py!

Is there a way to reliably distinguish these two cases?

I wasn't able to find anything: depending on the way command line arguments are formulated in the 2nd case, the exact same command line could be executed in both cases:
(the Bash script given is not a real shim, just a demonstration example to showcase what our logic sees and does)

$ cat python3   #!/bin/bash  echo "'$0'"  for a in "$@"; do    echo "'$a'"  done  # need to do the detection here  exec python3 "$@"    $ cat t.py   #!/home/vmuser/python3  import sys  print(sys.argv)    $ $PWD/t.py  '/home/vmuser/python3'   '/home/vmuser/t.py'  ['/home/vmuser/t.py']    $ $PWD/python3 $PWD/t.py   '/home/vmuser/python3'  '/home/vmuser/t.py'  ['/home/vmuser/t.py']  

Since shebang is a Linux kernel feature -- maybe it sets some indicator that this mechanism has been used?


We've considered requiring users to use a special shebang in their Python scripts that they wish to apply the special logic to, but that idea proved unpopular because it makes those scripts unportable.

In GNU screen, how to read from stdin and save into a register?

Posted: 03 Jul 2021 11:28 AM PDT

I'm using GNU screen and I want to save input from stdin into a register to slowpaste it later. I tried a workaround with a temp file (which I can read into a register with readreg afterwards) and to use cat:

:eval "exec | sh -c 'cat >/tmp/screentempfile'"  

However, if I press CTRLD to send EOF to cat, it doesn't arrive.

how do I shrink a partition, right after shrinking its filesystem with resize2fs?

Posted: 03 Jul 2021 10:06 AM PDT

This is what've done to shrink /home partition filesystem:

e2fsck /dev/sda1    resize2fs /dev/sda1 150G  

As of now, if I run df it is going to show me that the partition has shrunk from 210G to 150G (which is not true).

Since I've only reduced filesystem size, how can I shrink the partition size using fdisk or parted?

Writing a zsh script that goes in order

Posted: 03 Jul 2021 10:35 AM PDT

I am using Big Sur and I am trying to write a script that will make a package run (the package is XSPEC, a spectral fitting package from NASA), and then run commands run in that package. I start with XSPEC to open the package, and then I want to run data 1:1 /Users/me/Desktop/Drive/my\ data/spectrum2.pha My issue is that if I just put the two lines spaced with an enter, the second line doesn't run, because I assume that the first line doesn't terminate until I quit out of the package. Whenever XSPEC is done starting up, it prints XSPEC version: 12.11.1 Build Date/Time: Thu Jul 1 04:09:17 2021 XSPEC12> (is prints that in three separate lines). Is there a way to make an if statement that will go to the next step once the previous lines are printed?

Linux filesystem only readable, not writable via SMB

Posted: 03 Jul 2021 12:06 PM PDT

I can typically access, open, and edit all the files inside my Linux machine that is connected via ethernet to my router simply by typing in ssh user@192.168.0.10 into my macOS terminal. However, instead of purely interfacing through the terminal, I wanted to mount the entire filesystem of my Linux machine so that I could edit and freely transfer files to and from my Mac to the Linux machine.

macOS supports file sharing via SMB, so I decided to install Samba on my remote machine:

sudo apt-get install samba  

Then, I added the user user and a password to access the file share:

smbpasswd -a user  

After this, I edited my Samba config file to contain the following:

[Volumes]     path = /volumes     writable = yes     write list = user     force create mode = 0777     force directory mode = 0777     public=yes  

Finally, I restarted the Samba service:

sudo service smbd restart  

I was able to mount Volumes in the Finder using the username user and the password that I had set earlier. I am also able to read everything inside /volumes. However, I completely unable to modify any files or transfer anything into any folder in /volumes.

How do I actually make the folder writeable, instead of just readable? I added on lines such as writable = yes, write list = user, and force directory mode = 0777 to my Samba configuration as shown above, but it didn't seem to have helped at all.

The output of ls -l on /volumes gives me the following:

ls -l /volumes  
total 248  drwxr-xr-x 9 root root 131072 Jul  3 01:06 bridge1  drwxr-xr-x 2 root root 102400 Jun 13 20:30 bridge2  

sorting on files and joining

Posted: 03 Jul 2021 10:03 AM PDT

I have two files. I want to sort the file and join on the first column. For example:

First file:

100.   ttt  200.   616te  300.   7a27         7373qq  

second file:

100.   ttt  200.   yoga  300.   7a27         8371gd  

In order to join the two files I do the following:

join <(sort first_file.txt) <(sort second_file.txt) >joined.txt  

I want the resulting output to be:

  100.   ttt.      ttt  200.   616te.    yoga  300.   7a27.     7a27         7373qq.   8371gd  

And then I want to see the lines where column 2 and column 3 are different. For that I do:

awk '$2!=$3 {print $1, $2, $3}' joined.txt >different.txt  

As you can see some of the values in the first two files are null. And therefore, when I use join I get the following error for example:

join: /dev/fd/63:26456: is not sorted: 100  7373qq  join: /dev/fd/62:23295: is not sorted: 100  8371gd  

How can I take care of this? Insights will be appreciated.

How to set "character tx delay" in GNU screen? (Like in minicom)

Posted: 03 Jul 2021 10:34 AM PDT

Minicom has this useful setting called "character tx delay":

minicom screenshot

Is there a setting like this for GNU screen, too?

How to remove a Linux Distro from mulit-boot

Posted: 03 Jul 2021 08:13 AM PDT

I have on my PC isntalled Windows 10, Ubuntu, Linux Mint, Fedora, Zorin OS and Elementary OS. I want to delete a few of them. Is it as simple as deleting the partitions? The only problem is that I cant backup my Drive because it's 1TB. Also, if I delete the first (default) OS, will this affect the other distros? Thanks in advance!

Edit: The distros I want to delete are Ubuntu, Fedora and Zorin OS

The output of sudo fdisk -l /dev/sda

Units: sectors of 1 * 512 = 512 bytes  Sector size (logical/physical): 512 bytes / 4096 bytes  I/O size (minimum/optimal): 4096 bytes / 4096 bytes  Disklabel type: dos  Disk identifier: 0xa8ade033  

but it also says

Partition table entries are not in disk order.  

Bridge Network Virtualbox is not working

Posted: 03 Jul 2021 08:02 AM PDT

I installed virtualbox on my windows 10 and I run Kali Linux. When I first install it I set bridge adapter instead of NAT and it is working perfectly until I turn off my pc.

After that it is still on bridge network but there is no internet inside the virtualbox (Kali linux). I tried to reinstall it yesterday and it worked again. Today I woke up started the virtual box and I have the same issue.

I use bridge adapter, Intel(R) Wireless-AC 9560 160MHz. NAT is working perfectly but I don't need it.

Soundconverter error encoding to mp3

Posted: 03 Jul 2021 11:11 AM PDT

I am running Ubuntu 20.04 on a Lenovo Thinkpad X1 Tablet. A few years ago I wrote a bash script using soundconverter to transcode some of my music to mp3 files when I need to use a player that only has mp3 capability (like my car and my swimming player). I tried to use my script recently and got the following error

faac gstreamer element not found  

I did some research and found that the faac plugin in not included in the Ubuntu 20.04 package gstreamer1.0-plugins-bad nor -ugly. But I also found that there is a lame (mp3 library) gstreamer plugin which is installed. Additionally I found that running soundconverter in gui mode could transcode to mp3 without problem. So I have three possible solutions but don't know how to pursue any of therm

  1. If soundconverter can transcode to mp3 in gui, I am guessing there is some option that will enable this in batch mode. Does anyone know how?

  2. Is there a way to ask soundconverter to use gstreamer's lame plugin rather then the faac plugin to transcode to mp3?

  3. Does anyone know how to install the gstreamer faac plugin on Ubuntu 20.04?

Manjaro installation stuck on "Reached target graphical interface"

Posted: 03 Jul 2021 10:40 AM PDT

I just purchased a new PC with Windows 10 installed on it. The PC has two SSD cards, one for the Windows and one empty which I want to install Manjaro-Linux on. And load it all with the Dual Boot.

To install Manjaro I'm using a USB. I used Rufus to do so.

I guess the error is due to the GPU. I'm using the RTX 3060ti and for CPU I use i7 10700F. I wrote those in case the problem has to do with either of them...

I must mention that the installation of the Manjaro did work on my previous PC. On my previous PC, I divided my HDD into half and installed Manjaro on the empty half.

Cannot pair/connect to my headphones : Failure: Module initialization failed

Posted: 03 Jul 2021 11:52 AM PDT

I'm using linux kernel v4.4.0-148 and bluez v5.36.

I cannot pair nor connect to my bluetooth headphones Muse "M-260 BT" with bluetoothctl :

$ bluetoothctl  [NEW] Controller 34:E6:AD:A1:9B:8A seb-C70D-B-311 [default]  [bluetooth]# power on  [CHG] Controller 34:E6:AD:A1:9B:8A Class: 0x00010c  Changing power on succeeded  [CHG] Controller 34:E6:AD:A1:9B:8A Powered: yes  [bluetooth]# scan on  Discovery started  [CHG] Controller 34:E6:AD:A1:9B:8A Discovering: yes  [NEW] Device 00:13:09:01:19:61 M-260 BT  [bluetooth]# scan off  [CHG] Device 00:13:09:01:19:61 RSSI is nil  [CHG] Controller 34:E6:AD:A1:9B:8A Discovering: no  Discovery stopped  [bluetooth]# pair 00:13:09:01:19:61   Attempting to pair with 00:13:09:01:19:61  [CHG] Device 00:13:09:01:19:61 Connected: yes  [CHG] Device 00:13:09:01:19:61 Connected: no  [CHG] Device 00:13:09:01:19:61 UUIDs: 00001108-0000-1000-8000-00805f9b34fb  [CHG] Device 00:13:09:01:19:61 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb  [CHG] Device 00:13:09:01:19:61 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb  [CHG] Device 00:13:09:01:19:61 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb  [CHG] Device 00:13:09:01:19:61 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb  [CHG] Device 00:13:09:01:19:61 Paired: yes  Pairing successful  [CHG] Device 00:13:09:01:19:61 Connected: no  [bluetooth]# paired-devices   Device 00:13:09:01:19:61 M-260 BT  [bluetooth]# connect 00:13:09:01:19:61   Attempting to connect to 00:13:09:01:19:61  Failed to connect: org.bluez.Error.Failed  [bluetooth]# quit  [DEL] Controller 34:E6:AD:A1:9B:8A seb-C70D-B-311 [default]  

The bluetooth service is running :

$ sudo initctl status bluetooth   bluetooth start/spawned, process 1628  

But the syslog says bluetoothd[1628]: a2dp-sink profile connect failed for 00:13:09:01:19:61: Protocol not available although the pulseaudio-module-bluetooth package is already installed :

$ grep bluetoothd /var/log/syslog | tail -5  Jun 30 17:25:31 seb-C70D-B-311 bluetoothd[1628]: Failed to obtain handles for "Service Changed" characteristic  Jun 30 17:53:44 seb-C70D-B-311 bluetoothd[1628]: a2dp-sink profile connect failed for 00:13:09:01:19:61: Protocol not available  Jun 30 17:53:52 seb-C70D-B-311 bluetoothd[1628]: a2dp-sink profile connect failed for 00:13:09:01:19:61: Protocol not available  Jun 30 18:01:57 seb-C70D-B-311 bluetoothd[1628]: Failed to confirm name for hci0: Failed (0x03)  Jun 30 18:08:20 seb-C70D-B-311 bluetoothd[1628]: a2dp-sink profile connect failed for 00:13:09:01:19:61: Protocol not available  $ dpkg -l pulseaudio-module-bluetooth  Desired=Unknown/Install/Remove/Purge/Hold  | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend  |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)  ||/ Name                            Version              Architecture         Description  +++-===============================-====================-====================-===================================================================  ii  pulseaudio-module-bluetooth     1:4.0-0ubuntu11      amd64                Bluetooth module for PulseAudio sound server  

EDIT0 : Noticed the module-bluetooth-discover was not loaded, so I tried to load it but it fails :

$ pactl list modules short | grep module-bluetooth-discover  $ pactl load-module module-bluetooth-discover  Failure: Module initialization failed  

Can you help me ?

Why isn't `route` accepting target argument with CIDR format?

Posted: 03 Jul 2021 08:53 AM PDT

I noticed these 2 command formats give different results:

$ sudo route -v add -net <IP> netmask 255.255.255.255 gw <gateway>  # succeeds without outputting text    $ sudo route -v add -net <IP>/32 gw <gateway>  SIOCADDRT: Invalid argument  

The man file for route clearly says CIDR format should work:

route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw]...

[...]

target: the destination network or host. You can provide IP addresses in dotted decimal or host/network names.

So what am I missing?

Note: also, the verbose option seems to be useless on this command.

NTP Server - sync from local system clock

Posted: 03 Jul 2021 11:05 AM PDT

I need to create device (currently Raspberry Pi 3 based) which states as NTP Server, it has no connection to Internet and NTP should read actual time from local system clock (this clock is set from application). My /etc/ntp.conf is:

restrict default kod nomodify notrap nopeer noquery  restrict -6 default kod nomodify notrap nopeer noquery    restrict 127.0.0.1  restrict -6 ::1  restrict ::1    server  127.127.1.0 # local clock  fudge   127.127.1.0 stratum 1    driftfile /var/lib/ntp/ntp.drift  logfile /var/log/ntp.log  

When testing connection (after service ntp restart) with ntpdate -du localhost command I get this output:

transmit(::1)  receive(::1)  transmit(127.0.0.1)  receive(127.0.0.1)  transmit(::1)  receive(::1)  transmit(127.0.0.1)  receive(127.0.0.1)  transmit(::1)  receive(::1)  transmit(127.0.0.1)  receive(127.0.0.1)  transmit(::1)  receive(::1)  transmit(127.0.0.1)  receive(127.0.0.1)  ::1: Server dropped: strata too high  127.0.0.1: Server dropped: strata too high  server ::1, port 123  stratum 16, precision -20, leap 11, trust 000  refid [::1], delay 0.02573, dispersion 0.00000  transmitted 4, in filter 4  reference time:    00000000.00000000  Thu, Feb  7 2036  6:28:16.000  originate timestamp: ddbf0da9.473a860b  Tue, Nov 21 2017 20:40:09.278  transmit timestamp:  ddbf0da9.47320583  Tue, Nov 21 2017 20:40:09.278  filter delay:  0.02579  0.02573  0.02574  0.02573           0.00000  0.00000  0.00000  0.00000  filter offset: 0.000018 -0.00001 -0.00000 -0.00001           0.000000 0.000000 0.000000 0.000000  delay 0.02573, dispersion 0.00000  offset -0.000011    server 127.0.0.1, port 123  stratum 16, precision -20, leap 11, trust 000  refid [127.0.0.1], delay 0.02570, dispersion 0.00000  transmitted 4, in filter 4  reference time:    00000000.00000000  Thu, Feb  7 2036  6:28:16.000  originate timestamp: ddbf0da9.7a812105  Tue, Nov 21 2017 20:40:09.478  transmit timestamp:  ddbf0da9.7a7990a1  Tue, Nov 21 2017 20:40:09.478  filter delay:  0.02571  0.02570  0.02570  0.02570           0.00000  0.00000  0.00000  0.00000  filter offset: -0.00000 -0.00001 -0.00001 -0.00001           0.000000 0.000000 0.000000 0.000000  delay 0.02570, dispersion 0.00000  offset -0.000013    21 Nov 20:40:09 ntpdate[1181]: no server suitable for synchronization found  

What am I doing wrong? Why ntp does not get time from system clock?

Vega 56 drivers, missing firmware

Posted: 03 Jul 2021 08:06 AM PDT

In void linux kernel 4.13.3_1 I'm having trouble getting the amdgpu drivers to work.

Relevant output from dmesg:

[    0.944960] [drm] amdgpu kernel modesetting enabled.  [    0.945421] [drm] initializing kernel modesetting (VEGA10 0x1002:0x687F 0x1002:0x6B76 0xC3).  [    0.945426] [drm] register mmio base: 0xED400000  [    0.945426] [drm] register mmio size: 524288  [    0.945450] amdgpu 0000:44:00.0: Direct firmware load for amdgpu/vega10_gpu_info.bin failed with error -2  [    0.945450] amdgpu 0000:44:00.0: Falling back to user helper  [    1.951031] tsc: Refined TSC clocksource calibration: 3393.622 MHz  [    1.951217] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x30eac5b3ab4, max_idle_ns: 440795272524 ns  [    2.959338] clocksource: Switched to clocksource tsc  [   62.431041] amdgpu 0000:44:00.0: Failed to load gpu_info firmware "amdgpu/vega10_gpu_info.bin"  [   62.431110] amdgpu 0000:44:00.0: Fatal error during GPU init  [   62.431170] [drm] amdgpu: finishing device.  [   62.431170] [TTM] Memory type 2 has not been initialized  [   62.431668] amdgpu: probe of 0000:44:00.0 failed with error -11  

I'm building without initramfs. I cannot find the the amdgpu folder below /lib/modules, but it might be because they are included in the kernel.

Some kernel settings:

CONFIG_DRM_AMDGPU=y  CONFIG_DRM_AMDGPU_SI=y  CONFIG_DRM_AMDGPU_CIK=y  CONFIG_DRM_AMDGPU_USERPTR=y  CONFIG_DRM_AMDGPU_GART_DEBUGFS=y  

Have checked "Include in-kernel firmware blobs in kernel binary".

I have linux-firmware installed from xbps.

Edit: I have amdgpu.exp_hw_support=1 added to the kernel parameters.

How to set i3 to be the default window manager?

Posted: 03 Jul 2021 12:06 PM PDT

In the Kali login, I have to select i3 in the menu in order to use i3 instead of gnome. How to set i3 as the default window manager (no need of selection?

enter image description here

Install Samba 4.4 on Centos 6

Posted: 03 Jul 2021 10:02 AM PDT

I am running Centos 6.8 and would like to install a higher version of Samba. I am already running Samba, but I think I need some of the newer features (like Spotlight support).

Normally I try to install software via yum, and, if possible I would like to do the same for Samba.

  • is there a Yum Repo I can use to do this?
  • if not, would installing from RPM or Source still use my existing configuration?

I am aware of Samba+, but it's very expensive for my own needs.

mount: wrong fs type, bad option, bad superblock

Posted: 03 Jul 2021 11:04 AM PDT

I added a new hard drive (/dev/sdb) to Ubuntu Server 16, ran parted /dev/sdb mklabel gpt and sudo parted /dev/sdb mkpart primary ext4 0G 1074GB. All went fine. Then I tried to mount the drive

mkdir /mnt/storage2  mount /dev/sdb1 /mnt/storage2  

It resulted in

mount: wrong fs type, bad option, bad superblock on /dev/sdb1,         missing codepage or helper program, or other error           In some cases useful info is found in syslog - try         dmesg | tail or so.  

I tried mount -t ext4 /dev/sdb1 /mnt/storage2 with identical outcome. I've done this stuff many times before and have never ran into anything like this. I've already read this mount: wrong fs type, bad option, bad superblock on /dev/sdb on CentOS 6.0 to no avail.

fdisk output regarding the drive

Disk /dev/sdb: 1000 GiB, 1073741824000 bytes, 2097152000 sectors  Units: sectors of 1 * 512 = 512 bytes  Sector size (logical/physical): 512 bytes / 4096 bytes  I/O size (minimum/optimal): 4096 bytes / 4096 bytes  Disklabel type: gpt  Disk identifier: 0E136427-03AF-48E2-B56B-A467E991629F    Device     Start        End    Sectors  Size Type  /dev/sdb1   2048 2097149951 2097147904 1000G Linux filesystem   

Garbage characters when using serial connection over SSH connection with minicom/screen

Posted: 03 Jul 2021 10:52 AM PDT

I have a serial connection made with /dev/ttyUSB0 locally from my laptop to a cisco lab router and using minicom/putty/screen all work fine locally (hardware control: on, software control: off, 9600 8N1).

When I'm at work I SSH into my laptop at home, which works fine, but when I use minicom/screen to use the lab router I get garbage characters. I tried SSHing at home from another machine and it worked fine initially, but then later it started having garbage characters.

Since this is only happening over an SSH connection, what could be causing this? Any setting changes that could fix this?

How to get the last occurrence of lines between two patterns from a file?

Posted: 03 Jul 2021 10:34 AM PDT

I have a log file which reports on the output of a process, I'd like to extract all lines from between the last occurrence of two patterns.

The patterns will be along the lines of;

Summary process started at <datestring>  

and

Summary process finished at <datestring> with return code <num>  

There will be several instances of these patterns throughout the file, along with a lot of other information. I'd like to print the only the last occurrence.

I know that I can use:

sed -n '/StartPattern/,/EndPattern/p' FileName  

To get lines between the patterns, but not sure how to get the last instance. Sed or awk solutions would be fine.

Edit: I've not been clear at all about the behaviour that I want when multiple StartPatterns appear with no EndPattern, or if there's no EndPattern before the end of file, after detecting a StartPattern

For multiple StartPatterns with missing EndPattern, I'd only like lines from the last StartPattern to the EndPattern.

For a StartPattern which reaches the EOF without an EndPattern, I'd like everything up to the EOF, followed by inputting a string to warn that EOF was reached.

vsftpd won't start: "systemd[1]: vsftpd.service: main process exited, code=exited, status=2/INVALIDARGUMENT"

Posted: 03 Jul 2021 10:32 AM PDT

I have Rapsberry Pi B+ with Arch Linux installation. uname reports version:

[computer@computer001 ~]$ uname -a  Linux computer001 3.18.3-3-ARCH #1 PREEMPT Mon Jan 26 20:10:28 MST 2015 armv6l GNU/Linux  

I've installed ftp server via pacman -S vsftpd and installation has passed without any errors. Then I tried to configure it, which resulted in following vsftpd.conf:

anonymous_enable=NO  local_enable=YES  write_enable=YES  #local_umask=022  anon_upload_enable=NO  anon_mkdir_write_enable=NO  dirmessage_enable=YES  xferlog_enable=YES  connect_from_port_20=YES  chown_uploads=YES  chown_username=computer  #xferlog_file=/var/log/vsftpd.log  #xferlog_std_format=YES  #idle_session_timeout=600  #data_connection_timeout=120  #nopriv_user=ftpsecure  #async_abor_enable=YES  #ascii_upload_enable=YES  #ascii_download_enable=YES  ftpd_banner=Welcome to personal ftp service.  #deny_email_enable=YES  #banned_email_file=/etc/vsftpd.banned_emails  #chroot_local_user=YES  #chroot_list_enable=YES  #chroot_list_file=/etc/vsftpd.chroot_list  ls_recurse_enable=YES  listen=YES  #listen_ipv6=YES  

Now, when I try to restart vsftpd, I get:

[computer@computer001 etc]$ sudo systemctl restart vsftpd.service && systemctl status -l vsftpd.service  * vsftpd.service - vsftpd daemon     Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)     Active: failed (Result: exit-code) since Thu 1970-01-01 06:32:24 UTC; 112ms ago    Process: 350 ExecStart=/usr/bin/vsftpd (code=exited, status=2)   Main PID: 350 (code=exited, status=2)  

Here is also output of sudo journalctl | grep -i vsftp:

Jan 01 06:32:24 computer001001 sudo[347]: computer001 : TTY=pts/0 ; PWD=/etc ; USER=root ; COMMAND=/usr/bin/systemctl restart vsftpd.service  Jan 01 06:32:24 computer001001 systemd[1]: Starting vsftpd daemon...  Jan 01 06:32:24 computer001001 systemd[1]: Started vsftpd daemon.  Jan 01 06:32:24 computer001001 systemd[1]: vsftpd.service: main process exited, code=exited, status=2/INVALIDARGUMENT  Jan 01 06:32:24 computer001001 systemd[1]: Unit vsftpd.service entered failed state.  Jan 01 06:32:24 computer001001 systemd[1]: vsftpd.service failed.  

Here is unit script /usr/lib/systemd/system/vsftpd.service:

[Unit]  Description=vsftpd daemon  After=network.target    [Service]  ExecStart=/usr/bin/vsftpd  ExecReload=/bin/kill -HUP $MAINPID  KillMode=process    [Install]  WantedBy=multi-user.target  

If I run sudo /usr/bin/vsftpd, I get following error:

500 OOPS: config file not owned by correct user, or not a file  

I have corrected file permissions for /etc/vsftpd.conf via sudo chown root:root /etc/vsftpd.conf and now manually server gets started. I am also aware date/time is not correct, I haven't setup it yet.What am I missing?

How is it possible to sort ps command's CPU field?

Posted: 03 Jul 2021 09:38 AM PDT

I'm trying to make a small command that will find the processes that use the most CPU power.

Firstly, I use ps aux > file.txt and then cut -c 16-20 file.txt | sort -n | tail -5.

The result I get is this:

1.0   2.7  8.  14.5  14.5   

So my question is how can I have both the %CPU usage and the other fields outputted together?

Is it possible to create a directory and file inside /proc/sys?

Posted: 03 Jul 2021 09:45 AM PDT

I am running CentOS 6.2 and I need to create a subdirectory named "crypto" inside /proc/sys. Inside /proc/sys/crypto, I need to create a file named test which contains the value "1".

No comments:

Post a Comment