Monday, October 11, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Cannot Schedule Volume Change with Cron (tried direct in cron, python, etc...)

Posted: 11 Oct 2021 10:01 AM PDT

I posted this in Raspberry Pi, but was told that it was better suited in a general linux or programming area. So I figured I'd ask here now...

I am putting together a kiosk that should play video. I'm using a NUC with Raspberry Pi Desktop. Everything works but automating the audio with Cron. I work in a school and blasting sound during the day would kind of suck, so I want it to change based on the time of the day.

When run from terminal the following code works:

/usr/bin/amixer set Master 16384  

and

amixer sset 'Master' 16384  

So, I put it into Cron:

15 09 * * * /usr/bin/amixer set Master 16384  

and

43 09 * * * amixer sset 'Master' 16384  

Nothing. Fine. So I make a really simple python script to run (yes, I realize I put it in a system folder, I was planning on moving it, it just kind of ended up there.)

#!/usr/bin/env python3    from subprocess import call  call(["/usr/bin/amixer", "set", "Master", "65536"])  

I make it executable:

chmod +x /etc/python/sound100.py  

Then I call it from the terminal with both:

/etc/python/sound100.py  

and

/usr/bin/python3 /etc/python/sound100.py  

Again, it works. Yay. Into Cron it goes. Neither:

11 10 * * * python3 /etc/python/sound100.py  

nor

11 10 * * * /usr/bin/python3 /etc/python/sound100.py  

Not even

11 10 * * * /etc/python/sound100.py  

Nothing works.

So begins the actual troubleshooting. I check the syslog. Everything runs, but I learn that when I run it as a sudo command it says that the maximum volume is 83 when run as a sudoer. So that means I can't run it as from sudo crontab -e, but I start running it from the user's cron.

Still nothing. So I try running it as a sudoer but with the user beforehand. Nothing again.

Please help me. I just want to adjust the volume automatically without logging into ssh for every NUC we're putting up three times a day until I quit or retire.

Thank you!

rollback pipewire to PulseAudio

Posted: 11 Oct 2021 09:34 AM PDT

My bluetooth headphones are lagging video and stuttering.

I have recently switched to pipewire and find the documentation too advanced to navigate.There are so many layers of configuration and the service has not been adopted for long enough to grow a good body of support.

So I want to rollback to Pulse which has more developed documentation and support.

I'm on Arch and find when I try to remove pipewire I find it has many dependents whose integration I don't understand well enough to confidently address.

 # pacman -R pipewire   checking dependencies...   error: failed to prepare transaction (could not satisfy dependencies)   :: removing pipewire breaks dependency 'pipewire' required by helvum   :: removing pipewire breaks dependency 'pipewire' required by obs-studio   :: removing pipewire breaks dependency 'pipewire' required by pipewire-media-session   :: removing pipewire breaks dependency 'libpipewire-0.3.so=0-64' required by pipewire-media-session   :: removing pipewire breaks dependency 'libpipewire-0.3.so=0-64' required by pipewire-pulse     

How can I remove or disable pipewire and return to pulse?

Or maybe someone has a suggestion for approaching the bluetooth problem.

Upgrade from ubuntu 16.04

Posted: 11 Oct 2021 09:29 AM PDT

I got access to a computer using Ubuntu 16.04. Since it is out of support, I am in need to upgrade it to, say, 20.x.

To do this, I am prompted to execute sudo apt-get update before. But this gives the following error messages:

Reading package lists... Done  W: The repository 'http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Ubuntu_16.04  Release' does not have a Release file.  N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.  N: See apt-secure(8) manpage for repository creation and user configuration details.  W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/ InRelease: The following signatures were invalid: KEYEXPIRED 1602869253  KEYEXPIRED 1602869253  KEYEXPIRED 1602869253  W: Failed to fetch https://cloud.r-project.org/bin/linux/ubuntu/xenial-cran35/InRelease  The following signatures were invalid: KEYEXPIRED 1602869253  KEYEXPIRED 1602869253  KEYEXPIRED 1602869253  E: Failed to fetch http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Ubuntu_16.04/Packages  404  Not Found [IP: 195.135.221.134 80]  W: Some index files failed to download. They have been ignored, or old ones used instead.  

I assume that some have-a-look-see-URL became invalid. (especially probably http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Ubuntu_16.04/Packages) What is / are the correct URL(s) and how to teach them to apt-get?

Until now, I have not saved important data / programs on the HDD, therefore backups are not relevant.

In OpenBSD, what is a service?

Posted: 11 Oct 2021 09:08 AM PDT

I am trying to understand some fundamentals that I had some misunderstandings on, and in looking at OpenBSD I find that I'm not clear what a service is. (Note that I am not referring to web services, such as listed in /etc/services).

In rcctl(08):

NAME
    rcctl — configure and control daemons and services

DESCRIPTION
    The rcctl utility can enable or disable a base system service or a base system or package daemon...

In rc.conf(8):

...
DESCRIPTION
...
    Base system service configuration variables control features available by default that are not implemented as daemons. They can be set to either YES or NO. When set to YES, they have the following effects:
...

From /etc/rc.conf:

...  # services related to RPC, NFS, and YP  amd_flags=NO            # also see amd_master below  lockd_flags=NO  mountd_flags=NO  nfsd_flags=NO  portmap_flags=NO        # note: inetd(8) rpc services need portmap too  statd_flags=NO  ypbind_flags=NO  ypldap_flags=NO  ypserv_flags=NO    # set the following to "YES" to turn them on  pf=YES                  # Packet filter / NAT  ipsec=NO                # IPsec  check_quotas=YES        # NO may be desirable in some YP environments  accounting=NO           # process accounting (using /var/account/acct)    # Multicast routing configuration  # Please look at netstart(8) for a detailed description if you change these  multicast=NO            # Reject IPv4 multicast packets by default    # miscellaneous other flags  amd_master=/etc/amd/master      # AMD 'master' map  library_aslr=YES                # set to NO to disable library randomization  savecore_flags=                 # "-z" to compress  spamd_black=NO                  # set to YES to run spamd without greylisting  shlib_dirs=                     # extra directories for ldconfig, separated                                  # by space  ...  

So when OpenBSD is referring to a service in this context, what is it?

jq - set a value to another value conditionally

Posted: 11 Oct 2021 10:03 AM PDT

I need to set the value of a field in a json doc to one of three values using jq, depending on which exists. Notionally this looks like: set X to (if A exists, else if B exists, else if C exists, else "").

An example json doc I have looks like this:

{    "name": "0230",    "publish_date": "2007-08-18",    "abc_severity": "",    "def_severity": "medium",    "ghi_severity": "negligible"  }  

I would like to create a field Severity and set it's value to the value of abc_severity not null or empty. if it is null or empty I would like to set it to def_severity, and if that's null or empty I would like to set it to ghi_severity. If all three are null or empty is may be created with an empty value "". So the output in this case would be:

{    "name": "0230",    "publish_date": "2007-08-18",    "abc_severity": "",    "def_severity": "medium",    "ghi_severity": "negligible",    "Severity": "medium"  }  

The following is the closest I seem to be able to get:

'. | if .abc_severity? then .Severity=.abc_severity else if .def_severity? then .Severity=.def_severity else if .ghi_severity? then .Severity=.ghi_severity else .Severity="" end end end'

But the value of Severity is always "" even if one or more of the other values exist. I'm sure I'm overlooking something simple here, I just can't seem to get it.

Two monitors with same resolution but very different DPI

Posted: 11 Oct 2021 08:50 AM PDT

I am using Manjaro on a Lenovo P51. The internal monitor is 1080p and so is the external. However, the internal is 144 dpi and the external 70 dpi. I run KDE and global scaling is set to 150% which makes the icons, etc. a pleasing size for me. The NVIDIA GPU uses nouveau

➜  ~ lspci -k | grep -B 2 nouveau  01:00.0 3D controller: NVIDIA Corporation GM107GLM [Quadro M1200 Mobile] (rev a2)          Subsystem: Lenovo Device 224d          Kernel driver in use: nouveau  

and the Intel GPU uses i915

➜  ~ lspci -k | grep -B 2 i915   00:02.0 VGA compatible controller: Intel Corporation HD Graphics 630 (rev 04)          Subsystem: Lenovo Device 224d          Kernel driver in use: i915  

The Optimus setup is this:

➜  ~ xrandr --listproviders   Providers: number : 2  Provider 0: id: 0x43 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 1 associated providers: 1 name:modesetting  Provider 1: id: 0x80f cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 3 associated providers: 1 name:modesetting  

I have looked at a great number of answers and recommendations, but when I include --scale 2x2 the frame buffer grows, but the external monitor only displays the upper left quarter.

How can one get the scaling on the external monitor in this case?

How to install anaconda python on debian 11 without breaking debian?

Posted: 11 Oct 2021 08:23 AM PDT

I want to install anaconda from anaconda's website. They have provided an easy way to install on Linux via a shell script: https://docs.anaconda.com/anaconda/install/linux/

But I'm not sure if it would go against the "don't break debian" rules and I fear if I break my debian :( again , Would you please guide me on installing anaconda without breaking debian in next update/uprade. Thank you

Adding a virtual monitor to xrdp to allow dual monitors

Posted: 11 Oct 2021 07:45 AM PDT

I have two Linux systems (Server, and client). I am using Remmina on my client to remotely connect to the server which has xrdp (Session: xorg). The server is not connected to any monitor. Everything is working perfectly.

I am planning to use my second monitor (on the client-side) since Remmina now is supporting multi-monitors. I would like to use two monitors. Is that possible? How can I do this?

Using find + grep + awk in combination

Posted: 11 Oct 2021 07:51 AM PDT

I'd need to filter through a list files (output of top command) for some info:

  • Firstly I need to list files with a find
  • Then, I need to grep for lines with a pattern
  • Finally, I need to pickup one column I'm interested into.

Seems I'm unable to bind the find with both grep and awk:

My first attempt:

find . -name "high-cpu.out" -exec grep "jboss" | awk '{ print $5 }' {} \;    find: missing argument to `-exec'  awk: fatal: cannot open file `{}' for reading (No such file or directory)  

Second attempt:

find . -name "high-cpu.out" -exec grep "jboss" {} \ | awk '{ print $5 }';    find: missing argument to `-exec'  

Any help? Thanks

Closing the lid wakes laptop from sleep

Posted: 11 Oct 2021 07:25 AM PDT

Plugging the power cable in or removing it does the same. Expected behaviour would be that only opening the lid or pressing a key wakes it up. I disabled everything in /proc/acpi/wakeup, no change. Now I'm confused about ACPI and unsure what to look for in the logs. Machine is a Lenovo T14 running Arch with Gnome. Any ideas where to go from here?

How to extract out elapsedTime attribute values from file

Posted: 11 Oct 2021 09:14 AM PDT

I wish to extracted out elapsedTime attribute values from the file.

Records look

{"realm":"/test","transactionId":"9e26c614","elapsedTime":17,"elapsedTimeUnits":"MILLISECONDS","_id":"9e26c6asdasd"}  

The file I am having is in gb's and I want to get the values greater than 10000.

I tried to grep but due to colon grep is not working.

grep -wo --color 'elapsedTime' fileName -> this just prints attribute names  grep -w  --color "elapsedTime" fileName -> this just highlights the attribute.   

Detecting if a specific route/tunnel is used when reaching a website

Posted: 11 Oct 2021 09:46 AM PDT

I need a way to detect if I'm visiting a website through a specific kernel route set by a VPN.

The reason being: sometimes I forget my company's VPN on and I navigate to porn sites. I need to detect if the porn website's ip (let's assume 181.123.123.123, it has a fixed ip or a CIDR) is being resolved through my company's VPN tunnel (as I see it in ip route show, multiple tun0 tunnels are present).

Any easy way to do this?

Struggling with understanding redirection in pipes and subshells: Code explanation would be highly appreciated

Posted: 11 Oct 2021 09:55 AM PDT

Please consider the following log from a terminal session (Debian Buster, Bash 5.0):

root@cerberus ~/scripts # rm -f result  root@cerberus ~/scripts # { { echo test; } | cat > result; }  root@cerberus ~/scripts # cat result  test  root@cerberus ~/scripts #  

Nothing special here, this is the expected behavior, and I understand it.

But I do not understand the behavior in the following case:

root@cerberus ~/scripts # rm -f result  root@cerberus ~/scripts # { { echo test >&3; } | cat > result; } 3>&1  test  root@cerberus ~/scripts # cat result  root@cerberus ~/scripts #  

To be precise, I believe that I understand why "test" is output when executing the second line, but I don't understand why nothing goes into the result file. My understanding of what happens is the following:

  1. At first, fd 3 is set up as a duplicate of stdout. I am sure that this happens before the pipe is executed, because otherwise none of the commands in the pipe would have access to fd 3 at all, which would cause a "bad descriptor" error message.

  2. A pipeline is not a simple command, so a subshell is spawn to execute it. The subshell inherits the parent shell's execution environment, including file descriptors and redirections. [1]

  3. Each of the commands in the pipeline also is executed in its own subshell [2], again inheriting the execution environment and the file descriptors. echo's output is redirected to fd 3, which in turn had been duplicated from stdout before, which in summary leads echo's output to appear on stdout (output goes to fd 3, which goes to fd 1, which is stdout).

  4. But I don't get why echo's output doesn't make it into the result file. From the bash manual (emphasis mine):

The output of each command in the pipeline is connected via a pipe to the input of the next command. That is, each command reads the previous command's output. This connection is performed before any redirections specified by the command.

I am understanding this in the sense that echo's output should be connected to cat's input before the redirection >&3 is set up or applied, respectively. But if that would be true, the result file would exist (and contain "test") after the command has been executed. Therefore my understanding is obviously wrong.

Could somebody please explain what I am missing?

Update, based on A.B's excellent answer below, with further explanations

A.B already has provided the answer below. However, I needed some time to understand it. Therefore I'll explain some passages so that they can be understood more easily.

  1. Last part of the line: 3>&1 is done first: fd 1 pointing to the terminal output is duplicated to fd 3. This means that fd 1 and fd 3 now both point to the terminal output. They are identical and can be used interchangeably.

  2. Before forking, a pipe is created, typically using the pipe(2) system call, on next available fds: let's say fd 4 and fd 5. The preparation process then forks into future echo and future cat, performing the following steps:

    a) The preparation process for echo works like that:

    fd 5 is duplicated to fd 1 (overwriting where fd 1 pointed to: the terminal output). That means that fd 1 is now identical to fd 5, and that they can be used interchangeably. Specifically, fd 1 does not point to the terminal output any more, but points to the writing end of the pipe.

    At this stage (but see below), the output of echo would go to the writing end of the pipe, because echo writes to fd 1, which points to that writing end.

    Because we don't need two file descriptors for the same thing, and because echo writes to fd 1 anyway, fd 5 gets closed now.

    Then echo is executed.

    b) Likewise, the preparation process for cat duplicates fd 4 to fd 0, meaning that fd 0 no longer points to the terminal input, but points to the receiving side of the pipe. At this stage, the input for cat would come from the receiving side of the pipe, because cat reads from fd 0, and fd 0 is connected to that receiving side. Because we don't need two file descriptors for the same thing, and because cat reads from fd 0 anyway, fd 4 gets closed now. Then cat is executed.

    While this all happens, fd 3 is inherited everywhere.

  3. >&3 does the opposite of bullet 1: It duplicates fd 3 to fd 1. fd 3 had been created so that it points to the terminal output, and is inherited by the subshell which executes the pipe and the further subshells which execute the individual pipe commands.

    In step 2a), fd 1 had been pointed to the writing side of the pipe. But now, the redirection >&3 overwrites fd 1 again and makes it equal to fd 3, which in turn (still) points to the terminal output. This means that fd 1 no longer points to the writing side of the pipe, but to the terminal output instead. This is the reason why "test" appears on the terminal when the pipe is executed (remember that echo always writes to fd 1, regardless of where fd 1 points to).

    Plus, when fd 1 gets "overwritten" by the redirection, its old version gets closed (because the underlying system call dup2(2) does that). Since its old version was pointing to the writing end of the pipe, that writing end is now closed.

    Because of this, the receiving end, and thus, cat, won't receive any data. They immediately get an EOF notification instead. This is the reason why cat does not receive anything and why consequently the result file remains empty, or is truncated.

    [ Side note: I should have closed fd 3 after the redirection (that is, we should have written >&3 3>&- instead of >&3), because echo -as mentioned above- writes to fd 1 and does not know anything about fd 3 at all. However, that part was missing in my example, and I'd like to leave it that way to not distract from the actual problem). ]

Use file marker with entr

Posted: 11 Oct 2021 08:08 AM PDT

I've the following code on myscript.sh for the purpose of execute function on a file with .md extension when this file is modified:

function my_function(){      echo "I\'ve just seen $1"    }  typeset -fx my_function    find . -name "*.md"  |       entr -r -s "my_function $0"  

entr documentation: * [...] the name of the first file to trigger an event can be read from $0.*

I expect when I change README.md that output will be: "I've just seen README.md"

In reality when i launch the script and change README.md, following output appears:

bash myscript.sh  # output: I've just seen myscript.sh  

Please, why ?

Cannot open qbittorent via terminal by typing in the name

Posted: 11 Oct 2021 07:23 AM PDT

Whenever I try to open any application via terminal. For Example; If I try qbittorent;

$ qbittorent    Command 'qbittorent' not found, did you mean:      command 'qbittorrent' from deb qbittorrent (4.1.7-1ubuntu3)    Try: sudo apt install <deb name>  

I already have qbittorent installed. Does anyone know how to open it?

edit:

Output of: $ echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin  

Output of: dpkg -L qbittorent | grep bin

dpkg-query: package 'qbittorent' is not installed  Use dpkg --contents (= dpkg-deb --contents) to list archive files contents.  

I don't know why it says qbittorent is not installed but I can open it directly from Activities panel.

How to fix a route in ad-hoc networks

Posted: 11 Oct 2021 06:54 AM PDT

I have 4 raspberry PI connected through an ad-hoc network. They have the following addresses:
169.254.1.1
169.254.1.2
169.254.1.3
169.254.1.4

I need to fix the route as follow:
169.254.1.1 --> 169.254.1.2 --> 169.254.1.3 --> 169.254.1.4
Currently, I'm using B.A.T.M.A.N. protocol for mesh ad-hoc networks.
I tried the ip route add command but it doesn't work.

How do you install NodeJS on AIX?

Posted: 11 Oct 2021 07:24 AM PDT

I am currently running a server running AIX 7.1 and was wondering how I install NodeJS.

I cannot seem to find the apt-get package manager, nor the yum package manager? How do I go about doing this?

how to make changes to /sys/module/*/parameters persistent?

Posted: 11 Oct 2021 07:13 AM PDT

I recently had an issue where after boot, my keyboard would not work. I needed to plug it out and in again to use it.
The problem was that my usb went into autosuspend, which can be disabled with echo -1 >/sys/module/usbcore/parameters/autosuspend.

But now after some time working /sys/module/usbcore/parameters/autosuspend contains 2 again, I am suspecting this was caused by updating my kernel.

Is there a way to have this parameter not change with updates? I read about loading the modules and providing the parameters in /etc/modprobe.d or /etc/module-load.d but I couldn't find syntax on how to do it.

Reverse UDP Proxy from Public IP to Public IP

Posted: 11 Oct 2021 08:41 AM PDT

is it possible to set up an reverse UDP Proxy to route the Traffic from my VPS in the Cloud to my Homeserver behind my router?(Port Forwarding, Port Triggering all possible)

I am not entirely sure if this is even possible i am not that into networking.

I have googled a bit and found "solutions" with nginx, but that was all for reverse proxying Webservers.

The Deal here is i want to run a Teamspeak Server on my Homeserver without exposing my Home IP.

Appreciate every answer.

Thank you in advance!

P.S.: Homeserver is running Debian and VPS is running Debian aswell.

I try to install Oracle 19 on CENTOS 8 GUI by run vncserver and X11

Posted: 11 Oct 2021 09:07 AM PDT

I try to install Oracle 19 on CENTOS 8-GUI by using vncserver and X11. When I try to run this ./runInstaller, I got this ERROR: Unavale to verify the graphical display setup. This application requires X display. Make sure that xdpyinfo exist under PATH variable After I install X11 then I run these line: export DISPLAY=:0.0 xhost + But I got this unable to open display ":0.0" I try to see /etc/ssh/sshd_config and I got X11Forwarding yes and X11UseLocalhost yes. I got stuck there for a day.

Encode file content and echo it as one line

Posted: 11 Oct 2021 06:52 AM PDT

I am trying to echo the content of key and certificate files encoded with base64 so that I can then copy the output into other places.

I found this thread: Redirecting the content of a file to the command echo? which shows how to echo the file content and also found ways to keep the newline characters for encoding. However when I add the | base64 this breaks the output into multiple lines, and trying to add a second echo just replaces the newlines with white spaces.

$ echo "$(cat test.key)" | base64  LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUpRZ0lCQURBTkJna3Foa2lHOXcwQkFRRUZB  QVNDQ1N3d2dna29BZ0VBQW9JQ0FRRFF4Tkh0aHZvcEp1Z0EKOHBsSUNUUU1pOGMwMzRERlR6Z1E5  ME5tcE5zN2hRczNQZ0QwU2JuSFcyVGxqTS9oM1F1QVE0Q1dqaHRiV1ZUbgpSREcveGxWRFBESVVV  MzB1UHJnK0N6dlhOUkhzQkE9PQotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg==    $ echo $(echo "$(cat test.key)" | base64)  LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUpRZ0lCQURBTkJna3Foa2lHOXcwQkFRRUZB QVNDQ1N3d2dna29BZ0VBQW9JQ0FRRFF4Tkh0aHZvcEp1Z0EKOHBsSUNUUU1pOGMwMzRERlR6Z1E5 ME5tcE5zN2hRczNQZ0QwU2JuSFcyVGxqTS9oM1F1QVE0Q1dqaHRiV1ZUbgpSREcveGxWRFBESVVV MzB1UHJnK0N6dlhOUkhzQkE9PQotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg==  

The desired output would be:

LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUpRZ0lCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQ1N3d2dna29BZ0VBQW9JQ0FRRFF4Tkh0aHZvcEp1Z0EKOHBsSUNUUU1pOGMwMzRERlR6Z1E5ME5tcE5zN2hRczNQZ0QwU2JuSFcyVGxqTS9oM1F1QVE0Q1dqaHRiV1ZUbgpSREcveGxWRFBESVVVMzB1UHJnK0N6dlhOUkhzQkE9PQotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg==  

How can I achieve this output?

oh-my-zsh's prompt is slow: how to fix this

Posted: 11 Oct 2021 08:24 AM PDT

I'm using macOS 10.15.2 with iTerm2, zsh 5.7.1 and oh-my-zsh (theme robbyrussell).

I noticed that the prompt print is slightly slow respect to the bash one. For example, if I press enter, cursor initially goes at the beginning of the next line then, after a little while, the shell prompt comes in and the cursor is moved to its natural position. For example, if → ~ is the prompt when I'm in my home folder, and [] is my cursor, when I press enter I see:

0 - Idle status

→ ~ []

1 - Immediately after pressing enter

[]

2 - Back to idle status

→ ~ []

This slowness is particularly evident when I quickly press enter multiple times. In this case, I see some blank lines. This is what I see

→ ~  → ~  → ~    → ~    → ~      → ~  → ~  → ~    → ~ []  

I come from bash shell and when I use bash, there is not such a slowness. I'm not sure this is an issue of oh-my-zsh or its natural behavior. I'd like to know more about this and, eventually, how to fix it. Thanks.

PS: the problem comes from oh-my-zsh and it persists even if I disable all the plugins.

PPS: I previously posted this question on SO. Thanks to user1934428 for his help and for suggesting me to move this question here.

Detecting where to bind to receive a UDP broadcast

Posted: 11 Oct 2021 07:06 AM PDT

I'm writing an application that needs to capture and print UDP broadcasts. The network interface in use is:

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500          inet 192.168.10.1  netmask 255.255.255.0  broadcast 192.168.10.255          inet6 fe80::a00:27ff:feb9:b18c  prefixlen 64  scopeid 0x20<link>          ether 08:00:27:b9:b1:8c  txqueuelen 1000  (Ethernet)  

Packets are received and printed successfully for the states below.

$ sudo lsof -P -iUDP  python3   5496            root    3u  IPv4  54675      0t0  UDP *:67    $ sudo strace python3 main.py 2>&1 | grep bind  bind(3, {sa_family=AF_INET, sin_port=htons(67), sin_addr=inet_addr("0.0.0.0")}, 16) = 0  

I need to have the binding to a specific address and not all addresses 0.0.0.0. So I change the script to bind to mimic the 0.0.0.0 behavior and loop and bind to any possible address in the subnet. Result being:

$ sudo lsof -P -iUDP  python3   5472            root    3u  IPv4  52392      0t0  UDP 192.168.10.0:67   python3   5472            root    4u  IPv4  52393      0t0  UDP user-VirtualBox:67   python3   5472            root    6u  IPv4  52647      0t0  UDP 192.168.10.255:67   

However, the app still doesn't print anything.

Question

Is there a difference between binding to 0.0.0.0 as opposed to binding to every possible bindable address that could cause a package not to be passed to the userspace application?

Bash: #: command not found

Posted: 11 Oct 2021 08:43 AM PDT

I just moved to Arch Linux with KDE a week ago. Everything worked well until I installed ibus-unikey and ibus-qt, after that, whenever I open konsole, this error appears:

bash: #: command not found  

I doubt that # is a usual command because when I type it in konsole, nothing happens. But when I run pacman -Ss #, a ton of things appear.

My question: what is the # command and what should I do to fix this error?

Here are my .bashrc, .bash_profile and PATH

$ cat .bashrc     #     # ~/.bashrc     #       # If not running interactively, don't do anything     [[ $- != *i* ]] && return  $ cat .bash_profile     #     # ~/.bash_profile     #       [[ -f ~/.bashrc ]] && . ~/.bashrc         alias ls='ls --color=auto'     PS1='[\u@\h \W]\$ '      $ echo $PATH     /usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl  

Addition 1: As @terdon suggest, I run

$ grep -FH '\#' ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login ~/.bash_aliases /etc/bash.bashrc /etc/profile /etc/profile.d/* /etc/environment 2>/dev/null  

and receive nothing. But the later command give me

$ grep -P '(^|\s+)(\.|source) .' ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login ~/.bash_aliases /etc/bash.bashrc /etc/profile /etc/profile.d/* /etc/environment 2>/dev/null     /home/thuyenarc/.bash_profile:[[ -f ~/.bashrc ]] && . ~/.bashrc     /etc/bash.bashrc:[ -r /usr/share/bash-completion/bash_completion   ] && . /usr/share/bash-completion/bash_completion     /etc/profile:           test -r "$profile" && . "$profile"     /etc/profile:   . /etc/bash.bashrc     /etc/profile.d/locale.sh:    . "$XDG_CONFIG_HOME/locale.conf"     /etc/profile.d/locale.sh:    . "$HOME/.config/locale.conf"     /etc/profile.d/locale.sh:    . /etc/locale.conf  

Addition 2: I tried renaming the .bashrc file, then opened konsole, the error had gone. I suspect that the errors must come from .bashrc. Any ideas?

Non-interactive ecryptfs directory encrypt/decrypt

Posted: 11 Oct 2021 09:34 AM PDT

Can I decrypt an ecryptfs Private directory from a script?

My basic use case for this type of activity is for doing remote backups. Imagine you have a machine (call it privatebox) with an encrypted private directory that stores your photos (or some other sensitive information). It is only decrypted upon logging in. And imagine that you want to be able to write a script on a remote machine that will log into the privatebox, decrypt the directory to add a photo, then re-encrypt it and log out. All without user interactive steps being required (maybe it runs from cron). Note that the passphrase for the privatebox would NOT be stored on the privatebox in plain text or anything. And since it would be encrypted (except during the update) it would be protected if someone obtained the SD card, etc.

Such a script would work like this (in my mind):

  • setup private directory on privatebox that is encrypted with a passphrase
  • setup ssh keys from local machine to privatebox so you can use ssh non-interactively (cron can login)
  • Then what? How do you decrypt a private folder non-interactively if you know the passphrase?

It seems that ecryptfs is specifically designed to not allow this (even with SSH key trickery, you still have to manually mount your private directory).

Basically, what I'm looking for is a non-interactive version of 'ecryptfs-mount-private' or something similar if anyone knows a solution. Something like:

% ecryptfs-mount-private -p $PASSPHRASE

Where I could pass the passphrase instead of having to type it.

If ecryptfs can't do this, does anyone know of an alternative? Thanks!

Linux can't see any of my partitions — The backup GPT table is not at the end of the disk

Posted: 11 Oct 2021 10:09 AM PDT

I'm trying to install Linux on my HP Pavilion 14 inch ultrabook, but without any success.

At first I tried installing Ubuntu on it; everything went fine, I got into the Live DVD (yes I'm oldschool like that), and went to install the system on my disk. First weird thing that happened was that I wasn't prompted with the option to install Ubuntu alongside Windows, but instead got thrown directly into the window with the partition table. Or rather, lack thereof.

You see, the window showed my drive as being sda, but no partitions are visible. None. Not the one with windows on it, not any of the ones windows requires, not even the 500 GB free space on my drive that I made specifically for Ubuntu to play on. None of it.

I then went on to try and install Arch on my machine instead, hoping the more barebones system would be able to see my partitions. And indeed it did not. Exact same story as before, it can see the hard drive, but it cannot see any of the partitions.

This bugs me endlessly and I haven't been able to find any information about this on-line.

So what can I do? Is there some kind of trick to make the partition table visible? Everything else seems to be working, even the WLAN card (the one thing I always have trouble with) works. Any help?

NOTE: The ultrabook came with Windows 8

Screenshot of sudo fdisk -l as requested:

fdisk

Trying to run parted gives me the following error:

Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system believes the disk is smaller.  Fix by moving the backup to the end (and removing the old backup)?  

Following the suggestions below, I tried running sudo gdisk /dev/sda and got the following:

GPT fdisk (gdisk) version 0.8.8    Partition table scan:    MBR: protective    BSD: not present    APM: not present    GPT: present    Found valid GPT with protective MBR; using GPT.  

What should I do here?

How to bind arduino as a fix block-device --- /dev/ttyACM0?

Posted: 11 Oct 2021 08:06 AM PDT

I want to bind my Arduino Mega as /dev/ttyACM0. Sometimes, it turns out to be /dev/ttyACM0 and sometimes as /dev/ttyACM1.

I have taken help from this question and this tutorial

Someone please help me to achieve that as there are only 2 entries in /etc/udev/rules.d :-

  1. 20-crystalhd.rules
  2. 98-kexec.rules

The output of udevadm info -a -p $(udevadm info -q path -n /dev/ttyACM0) :-

Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.

looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0/tty/ttyACM0':  KERNEL=="ttyACM0"  SUBSYSTEM=="tty"  DRIVER==""    looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0':  KERNELS=="2-1.5:1.0"  SUBSYSTEMS=="usb"  DRIVERS=="cdc_acm"  ATTRS{bInterfaceClass}=="02"  ATTRS{bmCapabilities}=="6"  ATTRS{bInterfaceSubClass}=="02"  ATTRS{bInterfaceProtocol}=="01"  ATTRS{bNumEndpoints}=="01"  ATTRS{supports_autosuspend}=="1"  ATTRS{bAlternateSetting}==" 0"  ATTRS{bInterfaceNumber}=="00"    looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5':  KERNELS=="2-1.5"  SUBSYSTEMS=="usb"  DRIVERS=="usb"  ATTRS{bDeviceSubClass}=="00"  ATTRS{bDeviceProtocol}=="00"  ATTRS{devpath}=="1.5"  ATTRS{idVendor}=="2341"  ATTRS{speed}=="12"  ATTRS{bNumInterfaces}==" 2"  ATTRS{bConfigurationValue}=="1"  ATTRS{bMaxPacketSize0}=="8"  ATTRS{busnum}=="2"  ATTRS{devnum}=="4"  ATTRS{configuration}==""  ATTRS{bMaxPower}=="100mA"  ATTRS{authorized}=="1"  ATTRS{bmAttributes}=="c0"  ATTRS{bNumConfigurations}=="1"  ATTRS{maxchild}=="0"  ATTRS{bcdDevice}=="0001"  ATTRS{avoid_reset_quirk}=="0"  ATTRS{quirks}=="0x0"  ATTRS{serial}=="55431313937351C05151"  ATTRS{version}==" 1.10"  ATTRS{urbnum}=="17"  ATTRS{ltm_capable}=="no"  ATTRS{manufacturer}=="Arduino (www.arduino.cc)"  ATTRS{removable}=="removable"  ATTRS{idProduct}=="0042"  ATTRS{bDeviceClass}=="02"    looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-1':  KERNELS=="2-1"  SUBSYSTEMS=="usb"  DRIVERS=="usb"  ATTRS{bDeviceSubClass}=="00"  ATTRS{bDeviceProtocol}=="01"  ATTRS{devpath}=="1"  ATTRS{idVendor}=="8087"  ATTRS{speed}=="480"  ATTRS{bNumInterfaces}==" 1"  ATTRS{bConfigurationValue}=="1"  ATTRS{bMaxPacketSize0}=="64"  ATTRS{busnum}=="2"  ATTRS{devnum}=="2"  ATTRS{configuration}==""  ATTRS{bMaxPower}=="0mA"  ATTRS{authorized}=="1"  ATTRS{bmAttributes}=="e0"  ATTRS{bNumConfigurations}=="1"  ATTRS{maxchild}=="6"  ATTRS{bcdDevice}=="0000"  ATTRS{avoid_reset_quirk}=="0"  ATTRS{quirks}=="0x0"  ATTRS{version}==" 2.00"  ATTRS{urbnum}=="70"  ATTRS{ltm_capable}=="no"  ATTRS{removable}=="unknown"  ATTRS{idProduct}=="0024"  ATTRS{bDeviceClass}=="09"    looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2':  KERNELS=="usb2"  SUBSYSTEMS=="usb"  DRIVERS=="usb"  ATTRS{bDeviceSubClass}=="00"  ATTRS{bDeviceProtocol}=="00"  ATTRS{devpath}=="0"  ATTRS{idVendor}=="1d6b"  ATTRS{speed}=="480"  ATTRS{bNumInterfaces}==" 1"  ATTRS{bConfigurationValue}=="1"  ATTRS{bMaxPacketSize0}=="64"  ATTRS{authorized_default}=="1"  ATTRS{busnum}=="2"  ATTRS{devnum}=="1"  ATTRS{configuration}==""  ATTRS{bMaxPower}=="0mA"  ATTRS{authorized}=="1"  ATTRS{bmAttributes}=="e0"  ATTRS{bNumConfigurations}=="1"  ATTRS{maxchild}=="2"  ATTRS{bcdDevice}=="0310"  ATTRS{avoid_reset_quirk}=="0"  ATTRS{quirks}=="0x0"  ATTRS{serial}=="0000:00:1d.0"  ATTRS{version}==" 2.00"  ATTRS{urbnum}=="42"  ATTRS{ltm_capable}=="no"  ATTRS{manufacturer}=="Linux 3.10.0-123.13.2.el7.x86_64 ehci_hcd"  ATTRS{removable}=="unknown"  ATTRS{idProduct}=="0002"  ATTRS{bDeviceClass}=="09"  ATTRS{product}=="EHCI Host Controller"    looking at parent device '/devices/pci0000:00/0000:00:1d.0':  KERNELS=="0000:00:1d.0"  SUBSYSTEMS=="pci"  DRIVERS=="ehci-pci"  ATTRS{irq}=="23"  ATTRS{subsystem_vendor}=="0x104d"  ATTRS{broken_parity_status}=="0"  ATTRS{class}=="0x0c0320"  ATTRS{companion}==""  ATTRS{enabled}=="1"  ATTRS{consistent_dma_mask_bits}=="32"  ATTRS{dma_mask_bits}=="32"  ATTRS{local_cpus}=="000f"  ATTRS{device}=="0x1c26"  ATTRS{uframe_periodic_max}=="100"  ATTRS{msi_bus}==""  ATTRS{local_cpulist}=="0-3"  ATTRS{vendor}=="0x8086"  ATTRS{subsystem_device}=="0x9081"  ATTRS{numa_node}=="-1"  ATTRS{d3cold_allowed}=="1"    looking at parent device '/devices/pci0000:00':  KERNELS=="pci0000:00"  SUBSYSTEMS==""  DRIVERS==""  

Where should I edit my entries in which files and how. Please explain in somewhat depth as I am much naive!! Please help me establish this. It's already taking my mind and mood off.

Use the same file link for both Linux and Windows

Posted: 11 Oct 2021 07:22 AM PDT

Is it even possible to do so? I mean, can I create a link on Linux and than make this link valid also on Windows?

Use-case

I have the folder /media/Data/DownloadedMusic on a NTFS partition. I also have the folder /media/Data/Music on the same partition. How can I create a link to DownloadedMusic inside Music so that the link can be accessible both from a Linux system and a Windows system?

How can one provide colour to tab completion in tcsh?

Posted: 11 Oct 2021 08:41 AM PDT

(Crossposted from StackOverflow.com)

This question and the answer teach us how to introduce colour into tcsh prompts.

This webpage explains nicely how to get colour into any output of the echo command:

> echo \\e[1\;30mBLACK\\e[0m  BLACK  > echo '\e[1;30mBLACK\e[0m'  BLACK  

The word 'BLACK' in the example above is printed with a black (or darkgrey) foreground colour (depending on the overall color scheme).

Now I'd like to introduce this into the [TAB] command autocompletion feature of tcsh. I tried:

complete testcmd 'p/*/`echo '"'"'\e[1;30mf834fef\e[0m'"'"'`/'  

And I get:

> testcmd [TAB]  > testcmd ^[\[1\;30mf834fef^[\[0m  

Obviously the characters lose their special meaning. Hopefully I just did not get the escaping right. But I tried several other ways. So any help is appreciated.

The real use case is that I've got a command completion that offers three different types of completions and I'd like to visually distinguish the types. Also the alternatives are computed by an external command. That is why I need the completion to use the backticks with an external command, such as echo. I don't care about the details of this command. If you make it work in any way with the tcsh's complete command I'll probably be able to adapt (thinking perl -pe wrappers and such).

The reason why I believe this has to work somehow is that the tcsh itself offers coloured command completion if you e.g. type ls [TAB]. That works correctly in my setup. Also you can use ls -1F inside the autocompletion and the colours that ls outputs are also piped through. An example would be:

complete testcmd 'p/*/`ls -1F`/'  

Update: As user mavin points out on stackoverflow, the colourization of ls in this example is indeed not piped through. The colours of ls are lost, but the auto completion can reapply colours according to LS_COLOURS variable based on hints such as the / and * marker endings as added by the ls. This can be verified by doing

complete testcmd 'p/*/`ls --color -1`/'  

which fails to provide colour, and only provides garbled output. (Literally pipes through the escape character sequences)

I'm on tcsh version 6.13.00

Any ideas? Pointers?

Colorizing your terminal and shell environment?

Posted: 11 Oct 2021 06:53 AM PDT

I spend most of my time working in Unix environments and using terminal emulators. I try to use color on the command line, because color makes the output more useful and intuitive.

What options exist to add color to my terminal environment? What tricks do you use? What pitfalls have you encountered?

Unfortunately, support for color varies depending on terminal type, OS, TERM setting, utility, buggy implementations, etc.

Here are some tips from my setup, after a lot of experimentation:

  1. I tend to set TERM=xterm-color, which is supported on most hosts (but not all).
  2. I work on a number of different hosts, different OS versions, etc. I use everything from macOS X, Ubuntu Linux, RHEL/CentOS/Scientific Linux and FreeBSD. I'm trying to keep things simple and generic, if possible.
  3. I do a bunch of work using GNU screen, which adds another layer of fun.
  4. Many OSs set things like dircolors and by default, and I don't want to modify this on a hundred different hosts. So I try to stick with the defaults. Instead, I tweak my terminal's color configuration.
  5. Use color for some Unix commands (ls, grep, less, vim) and the Bash prompt. These commands seem to use the standard "ANSI escape sequences". For example:

    alias less='less --RAW-CONTROL-CHARS'  export LS_OPTS='--color=auto'  alias ls='ls ${LS_OPTS}'  

I'll post my .bashrc and answer my own question Jeopardy Style.

No comments:

Post a Comment