Monday, April 5, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Using single quotes inside input of heredocs

Posted: 05 Apr 2021 10:32 AM PDT

I need some help debugging my tcsh script. It uses heredocs. The code:

<pre_setup> <<EOF1  <setup> <<EOF2    <command>    exit 0  EOF2  exit 0  EOF1  

The <pre_setup> is some pre setup command (like wash) and setup is some setup that runs after it. It works but I noticed that if setup contains single quotes, it fails. My setup looks like:

run_setup -cmd '$SOME_ENV -o outdir'  

The run_setup sets $SOME_ENV and executes $SOME_ENV -o outdir. So running:

wash -n group_name <<EOF1  run_setup -cmd '$SOME_ENV -o outdir' <<EOF2    <command>    exit 0  EOF2  exit 0  EOF1  

Fails with SOME_ENV: Undefined variable.. It's not problem of wash in pre_setup because If I use setenv X 1 as pre_setup, it still fails with the same error. It has something to do with the way heredocs works. How can I make it work?

time --format e command fails to recognize format arg?

Posted: 05 Apr 2021 10:30 AM PDT

Can someone please show me how to use time -f e correctly? I want just the real wall clock time in seconds.

LVM - how to disable scrub --assume-clean

Posted: 05 Apr 2021 10:29 AM PDT

Building a raid10 array with LVM. lvs -a -o name,raid_sync_action,sync_percent reports resync 60.23. Is there a way to disable this scrub like you could do with mdraid by using the --assume-clean flag in raid creation?

Going through the arch linux they report that to stop the running data scrub safely you can run echo idle > /sys/block/md0/md/sync_action however lvm seems todo things differently so this file location does not have what is needed, atleast on rhel8.

Xdeb not working in Void Linux

Posted: 05 Apr 2021 10:19 AM PDT

I am trying to install a deb file in Void Linux using xdeb utility. However, I am getting following error:

$ xdeb -Sde aeskulap_0.2.1-2_i386.deb  [+] Synced shlibs  ar: aeskulap_0.2.1-2_i386.deb: file format not recognized  [-] Not a valid deb file  

Where is the problem and how can it be solved? Thanks for your help.

docker service + service is down but not know the reason

Posted: 05 Apr 2021 10:14 AM PDT

we have docker service installed on all or rhel 7.5 machines ( 5 machines )

from some unclear reason we see that docker service is stooped on all machines ( machine are up last 1 year )

this is strange because the docker service is configured with Restart=always , so in case docker service is down , then after few seconds it will start automatically , according to the following docker service configuration

TimeoutSec=0  RestartSec=2  Restart=always  

and full description:

more /etc/systemd/system/multi-user.target.wants/docker.service  [Unit]  Description=Docker Application Container Engine  Documentation=https://docs.docker.com  BindsTo=containerd.service  After=network-online.target firewalld.service containerd.service  Wants=network-online.target  Requires=docker.socket    [Service]  Type=notify  # the default is not to use systemd for cgroups because the delegate issues still  # exists and systemd currently does not support the cgroup feature set required  # for containers run by docker  ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock  ExecReload=/bin/kill -s HUP $MAINPID  TimeoutSec=0  RestartSec=2  Restart=always    # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.  # Both the old, and new location are accepted by systemd 229 and up, so using the old location  # to make them work for either version of systemd.  StartLimitBurst=3    # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.  # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make  # this option work for either version of systemd.  StartLimitInterval=60s    # Having non-zero Limit*s causes performance problems due to accounting overhead  # in the kernel. We recommend using cgroups to do container-local accounting.  LimitNOFILE=infinity  LimitNPROC=infinity  LimitCORE=infinity  

what I am worry is about some kill action as kill -9 on docker service PID , and maybe this is the case , but on the the hand , no user was login to the machines , so this is very strange
any hint about this ?

Wine not working in Void Linux

Posted: 05 Apr 2021 10:31 AM PDT

I am trying to install a program called aeskulap dicom image viewer in Void Linux. This Void Linux desktop installation is otherwise working very well. Aeskulap program is not present in Void Linux repositories (current, multilib, nonfree, multilib-nonfree). Hence, I am trying to install its exe setup file with wine. However, I am getting following error:

$ wine aeskulap-0.2.1-setup.exe  002c:err:winediag:WS_getaddrinfo Failed to resolve your host name IP  Application could not be started, or no application associated with the specified file.  ShellExecuteEx failed: File not found.  

Same error comes if I use wine64 instead of wine

I found some links for this error (e.g. this) but could not understand how to correct it.

Where is the problem and how can it be solved? Thanks for your help.

How to route only certain large subnet ranges (ipsets) from Ubuntu client to Ubuntu Wireguard server?

Posted: 05 Apr 2021 10:33 AM PDT

I have a working server & clients, all server & clients are on Ubuntu 20.04 & have wg-quick installed with wireguard-tools.

I need to route ONLY certain but very large amount of ip ranges / subnets (4000-5000) over vpn server & it should be fast.

The rest of the traffic should NOT go over vpn.

I know that you can put any subnets into client.conf AllowedIPs instead of 0.0.0.0/0 config but I'm looking for an option to put a lot of different subnets there.

If I used iptables then I'd need ipset create vpn hash:net hashsize 65535 + ipset add vpn a.b.c.d/ef & some rules but I'm not sure what to do with wireguard since I don't see any iptables rules added after seccessful connection to vpn server with AllowedIPs = 0.0.0.0/0 as well as no new routes in ip route or route so I'm not even sure where to try to configure that.

Please advise & then it should probably be added to client.conf

[Interface]  PostUp  PostDown  

or even directly into wg-quick?

Thanks.

Here's the code of wg-quick which seems to be configuring what I need but can't really figure out how exactly to adjust it/where to add ipsets:

#!/bin/bash  # SPDX-License-Identifier: GPL-2.0  #  # Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.  #    set -e -o pipefail  shopt -s extglob  export LC_ALL=C    SELF="$(readlink -f "${BASH_SOURCE[0]}")"  export PATH="${SELF%/*}:$PATH"    WG_CONFIG=""  INTERFACE=""  ADDRESSES=( )  MTU=""  DNS=( )  DNS_SEARCH=( )  TABLE=""  PRE_UP=( )  POST_UP=( )  PRE_DOWN=( )  POST_DOWN=( )  SAVE_CONFIG=0  CONFIG_FILE=""  PROGRAM="${0##*/}"  ARGS=( "$@" )    cmd() {      echo "[#] $*" >&2      "$@"  }    die() {      echo "$PROGRAM: $*" >&2      exit 1  }    parse_options() {      local interface_section=0 line key value stripped v      CONFIG_FILE="$1"      [[ $CONFIG_FILE =~ ^[a-zA-Z0-9_=+.-]{1,15}$ ]] && CONFIG_FILE="/etc/wireguard/$CONFIG_FILE.conf"      [[ -e $CONFIG_FILE ]] || die "\`$CONFIG_FILE' does not exist"      [[ $CONFIG_FILE =~ (^|/)([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] || die "The config file must be a valid interface name, followed by .conf"      CONFIG_FILE="$(readlink -f "$CONFIG_FILE")"      ((($(stat -c '0%#a' "$CONFIG_FILE") & $(stat -c '0%#a' "${CONFIG_FILE%/*}") & 0007) == 0)) || echo "Warning: \`$CONFIG_FILE' is world accessible" >&2      INTERFACE="${BASH_REMATCH[2]}"      shopt -s nocasematch      while read -r line || [[ -n $line ]]; do          stripped="${line%%\#*}"          key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"          value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"          [[ $key == "["* ]] && interface_section=0          [[ $key == "[Interface]" ]] && interface_section=1          if [[ $interface_section -eq 1 ]]; then              case "$key" in              Address) ADDRESSES+=( ${value//,/ } ); continue ;;              MTU) MTU="$value"; continue ;;              DNS) for v in ${value//,/ }; do                  [[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )              done; continue ;;              Table) TABLE="$value"; continue ;;              PreUp) PRE_UP+=( "$value" ); continue ;;              PreDown) PRE_DOWN+=( "$value" ); continue ;;              PostUp) POST_UP+=( "$value" ); continue ;;              PostDown) POST_DOWN+=( "$value" ); continue ;;              SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;              esac          fi          WG_CONFIG+="$line"$'\n'      done < "$CONFIG_FILE"      shopt -u nocasematch  }    read_bool() {      case "$2" in      true) printf -v "$1" 1 ;;      false) printf -v "$1" 0 ;;      *) die "\`$2' is neither true nor false"      esac  }    auto_su() {      [[ $UID == 0 ]] || exec sudo -p "$PROGRAM must be run as root. Please enter the password for %u to continue: " -- "$BASH" -- "$SELF" "${ARGS[@]}"  }    add_if() {      local ret      if ! cmd ip link add "$INTERFACE" type wireguard; then          ret=$?          [[ -e /sys/module/wireguard ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret          echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2          cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"      fi  }    del_if() {      local table      [[ $HAVE_SET_DNS -eq 0 ]] || unset_dns      [[ $HAVE_SET_FIREWALL -eq 0 ]] || remove_firewall      if [[ -z $TABLE || $TABLE == auto ]] && get_fwmark table && [[ $(wg show "$INTERFACE" allowed-ips) =~ /0(\ |$'\n'|$) ]]; then          while [[ $(ip -4 rule show 2>/dev/null) == *"lookup $table"* ]]; do              cmd ip -4 rule delete table $table          done          while [[ $(ip -4 rule show 2>/dev/null) == *"from all lookup main suppress_prefixlength 0"* ]]; do              cmd ip -4 rule delete table main suppress_prefixlength 0          done          while [[ $(ip -6 rule show 2>/dev/null) == *"lookup $table"* ]]; do              cmd ip -6 rule delete table $table          done          while [[ $(ip -6 rule show 2>/dev/null) == *"from all lookup main suppress_prefixlength 0"* ]]; do              cmd ip -6 rule delete table main suppress_prefixlength 0          done      fi      cmd ip link delete dev "$INTERFACE"  }    add_addr() {      local proto=-4      [[ $1 == *:* ]] && proto=-6      cmd ip $proto address add "$1" dev "$INTERFACE"  }    set_mtu_up() {      local mtu=0 endpoint output      if [[ -n $MTU ]]; then          cmd ip link set mtu "$MTU" up dev "$INTERFACE"          return      fi      while read -r _ endpoint; do          [[ $endpoint =~ ^\[?([a-z0-9:.]+)\]?:[0-9]+$ ]] || continue          output="$(ip route get "${BASH_REMATCH[1]}" || true)"          [[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ${BASH_REMATCH[1]} -gt $mtu ]] && mtu="${BASH_REMATCH[1]}"      done < <(wg show "$INTERFACE" endpoints)      if [[ $mtu -eq 0 ]]; then          read -r output < <(ip route show default || true) || true          [[ ( $output =~ mtu\ ([0-9]+) || ( $output =~ dev\ ([^ ]+) && $(ip link show dev "${BASH_REMATCH[1]}") =~ mtu\ ([0-9]+) ) ) && ${BASH_REMATCH[1]} -gt $mtu ]] && mtu="${BASH_REMATCH[1]}"      fi      [[ $mtu -gt 0 ]] || mtu=1500      cmd ip link set mtu $(( mtu - 80 )) up dev "$INTERFACE"  }    resolvconf_iface_prefix() {      [[ -f /etc/resolvconf/interface-order ]] || return 0      local iface      while read -r iface; do          [[ $iface =~ ^([A-Za-z0-9-]+)\*$ ]] || continue          echo "${BASH_REMATCH[1]}." && return 0      done < /etc/resolvconf/interface-order  }    HAVE_SET_DNS=0  set_dns() {      [[ ${#DNS[@]} -gt 0 ]] || return 0      { printf 'nameserver %s\n' "${DNS[@]}"        [[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"      } | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x      HAVE_SET_DNS=1  }    unset_dns() {      [[ ${#DNS[@]} -gt 0 ]] || return 0      cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE" -f  }    add_route() {      local proto=-4      [[ $1 == *:* ]] && proto=-6      [[ $TABLE != off ]] || return 0        if [[ -n $TABLE && $TABLE != auto ]]; then          cmd ip $proto route add "$1" dev "$INTERFACE" table "$TABLE"      elif [[ $1 == */0 ]]; then          add_default "$1"      else          [[ -n $(ip $proto route show dev "$INTERFACE" match "$1" 2>/dev/null) ]] || cmd ip $proto route add "$1" dev "$INTERFACE"      fi  }    get_fwmark() {      local fwmark      fwmark="$(wg show "$INTERFACE" fwmark)" || return 1      [[ -n $fwmark && $fwmark != off ]] || return 1      printf -v "$1" "%d" "$fwmark"      return 0  }    remove_firewall() {      if type -p nft >/dev/null; then          local table nftcmd          while read -r table; do              [[ $table == *" wg-quick-$INTERFACE" ]] && printf -v nftcmd '%sdelete %s\n' "$nftcmd" "$table"          done < <(nft list tables 2>/dev/null)          [[ -z $nftcmd ]] || cmd nft -f <(echo -n "$nftcmd")      fi      if type -p iptables >/dev/null; then          local line iptables found restore          for iptables in iptables ip6tables; do              restore="" found=0              while read -r line; do                  [[ $line == "*"* || $line == COMMIT || $line == "-A "*"-m comment --comment \"wg-quick(8) rule for $INTERFACE\""* ]] || continue                  [[ $line == "-A"* ]] && found=1                  printf -v restore '%s%s\n' "$restore" "${line/#-A/-D}"              done < <($iptables-save 2>/dev/null)              [[ $found -ne 1 ]] || echo -n "$restore" | cmd $iptables-restore -n          done      fi  }    HAVE_SET_FIREWALL=0  add_default() {      local table line      if ! get_fwmark table; then          table=51820          while [[ -n $(ip -4 route show table $table 2>/dev/null) || -n $(ip -6 route show table $table 2>/dev/null) ]]; do              ((table++))          done          cmd wg set "$INTERFACE" fwmark $table      fi      local proto=-4 iptables=iptables pf=ip      [[ $1 == *:* ]] && proto=-6 iptables=ip6tables pf=ip6      cmd ip $proto route add "$1" dev "$INTERFACE" table $table      cmd ip $proto rule add not fwmark $table table $table      cmd ip $proto rule add table main suppress_prefixlength 0        local marker="-m comment --comment \"wg-quick(8) rule for $INTERFACE\"" restore=$'*raw\n' nftable="wg-quick-$INTERFACE" nftcmd       printf -v nftcmd '%sadd table %s %s\n' "$nftcmd" "$pf" "$nftable"      printf -v nftcmd '%sadd chain %s %s preraw { type filter hook prerouting priority -300; }\n' "$nftcmd" "$pf" "$nftable"      printf -v nftcmd '%sadd chain %s %s premangle { type filter hook prerouting priority -150; }\n' "$nftcmd" "$pf" "$nftable"      printf -v nftcmd '%sadd chain %s %s postmangle { type filter hook postrouting priority -150; }\n' "$nftcmd" "$pf" "$nftable"      while read -r line; do          [[ $line =~ .*inet6?\ ([0-9a-f:.]+)/[0-9]+.* ]] || continue          printf -v restore '%s-I PREROUTING ! -i %s -d %s -m addrtype ! --src-type LOCAL -j DROP %s\n' "$restore" "$INTERFACE" "${BASH_REMATCH[1]}" "$marker"          printf -v nftcmd '%sadd rule %s %s preraw iifname != "%s" %s daddr %s fib saddr type != local drop\n' "$nftcmd" "$pf" "$nftable" "$INTERFACE" "$pf" "${BASH_REMATCH[1]}"      done < <(ip -o $proto addr show dev "$INTERFACE" 2>/dev/null)      printf -v restore '%sCOMMIT\n*mangle\n-I POSTROUTING -m mark --mark %d -p udp -j CONNMARK --save-mark %s\n-I PREROUTING -p udp -j CONNMARK --restore-mark %s\nCOMMIT\n' "$restore" $table "$marker" "$marker"      printf -v nftcmd '%sadd rule %s %s postmangle meta l4proto udp mark %d ct mark set mark \n' "$nftcmd" "$pf" "$nftable" $table      printf -v nftcmd '%sadd rule %s %s premangle meta l4proto udp meta mark set ct mark \n' "$nftcmd" "$pf" "$nftable"      [[ $proto == -4 ]] && cmd sysctl -q net.ipv4.conf.all.src_valid_mark=1      if type -p nft >/dev/null; then          cmd nft -f <(echo -n "$nftcmd")      else          echo -n "$restore" | cmd $iptables-restore -n      fi      HAVE_SET_FIREWALL=1      return 0  }    set_config() {      cmd wg setconf "$INTERFACE" <(echo "$WG_CONFIG")  }    save_config() {      local old_umask new_config current_config address cmd      [[ $(ip -all -brief address show dev "$INTERFACE") =~ ^$INTERFACE\ +\ [A-Z]+\ +(.+)$ ]] || true      new_config=$'[Interface]\n'      for address in ${BASH_REMATCH[1]}; do          new_config+="Address = $address"$'\n'      done      while read -r address; do          [[ $address =~ ^nameserver\ ([a-zA-Z0-9_=+:%.-]+)$ ]] && new_config+="DNS = ${BASH_REMATCH[1]}"$'\n'      done < <(resolvconf -l "$(resolvconf_iface_prefix)$INTERFACE" 2>/dev/null || cat "/etc/resolvconf/run/interface/$(resolvconf_iface_prefix)$INTERFACE" 2>/dev/null)      [[ -n $MTU && $(ip link show dev "$INTERFACE") =~ mtu\ ([0-9]+) ]] && new_config+="MTU = ${BASH_REMATCH[1]}"$'\n'      [[ -n $TABLE ]] && new_config+="Table = $TABLE"$'\n'      [[ $SAVE_CONFIG -eq 0 ]] || new_config+=$'SaveConfig = true\n'      for cmd in "${PRE_UP[@]}"; do          new_config+="PreUp = $cmd"$'\n'      done      for cmd in "${POST_UP[@]}"; do          new_config+="PostUp = $cmd"$'\n'      done      for cmd in "${PRE_DOWN[@]}"; do          new_config+="PreDown = $cmd"$'\n'      done      for cmd in "${POST_DOWN[@]}"; do          new_config+="PostDown = $cmd"$'\n'      done      old_umask="$(umask)"      umask 077      current_config="$(cmd wg showconf "$INTERFACE")"      trap 'rm -f "$CONFIG_FILE.tmp"; exit' INT TERM EXIT      echo "${current_config/\[Interface\]$'\n'/$new_config}" > "$CONFIG_FILE.tmp" || die "Could not write configuration file"      sync "$CONFIG_FILE.tmp"      mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" || die "Could not move configuration file"      trap - INT TERM EXIT      umask "$old_umask"  }    execute_hooks() {      local hook      for hook in "$@"; do          hook="${hook//%i/$INTERFACE}"          echo "[#] $hook" >&2          (eval "$hook")      done  }    cmd_usage() {      cat >&2 <<-_EOF      Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]          CONFIG_FILE is a configuration file, whose filename is the interface name        followed by \`.conf'. Otherwise, INTERFACE is an interface name, with        configuration found at /etc/wireguard/INTERFACE.conf. It is to be readable        by wg(8)'s \`setconf' sub-command, with the exception of the following additions        to the [Interface] section, which are handled by $PROGRAM:          - Address: may be specified one or more times and contains one or more          IP addresses (with an optional CIDR mask) to be set for the interface.        - DNS: an optional DNS server to use while the device is up.        - MTU: an optional MTU for the interface; if unspecified, auto-calculated.        - Table: an optional routing table to which routes will be added; if          unspecified or \`auto', the default table is used. If \`off', no routes          are added.        - PreUp, PostUp, PreDown, PostDown: script snippets which will be executed          by bash(1) at the corresponding phases of the link, most commonly used          to configure DNS. The string \`%i' is expanded to INTERFACE.        - SaveConfig: if set to \`true', the configuration is saved from the current          state of the interface upon shutdown.        See wg-quick(8) for more info and examples.      _EOF  }    cmd_up() {      local i      [[ -z $(ip link show dev "$INTERFACE" 2>/dev/null) ]] || die "\`$INTERFACE' already exists"      trap 'del_if; exit' INT TERM EXIT      execute_hooks "${PRE_UP[@]}"      add_if      set_config      for i in "${ADDRESSES[@]}"; do          add_addr "$i"      done      set_mtu_up      set_dns      for i in $(while read -r _ i; do for i in $i; do [[ $i =~ ^[0-9a-z:.]+/[0-9]+$ ]] && echo "$i"; done; done < <(wg show "$INTERFACE" allowed-ips) | sort -nr -k 2 -t /); do          add_route "$i"      done      execute_hooks "${POST_UP[@]}"      trap - INT TERM EXIT  }    cmd_down() {      [[ " $(wg show interfaces) " == *" $INTERFACE "* ]] || die "\`$INTERFACE' is not a WireGuard interface"      execute_hooks "${PRE_DOWN[@]}"      [[ $SAVE_CONFIG -eq 0 ]] || save_config      del_if      unset_dns || true      remove_firewall || true      execute_hooks "${POST_DOWN[@]}"  }    cmd_save() {      [[ " $(wg show interfaces) " == *" $INTERFACE "* ]] || die "\`$INTERFACE' is not a WireGuard interface"      save_config  }    cmd_strip() {      echo "$WG_CONFIG"  }    # ~~ function override insertion point ~~    if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then      cmd_usage  elif [[ $# -eq 2 && $1 == up ]]; then      auto_su      parse_options "$2"      cmd_up  elif [[ $# -eq 2 && $1 == down ]]; then      auto_su      parse_options "$2"      cmd_down  elif [[ $# -eq 2 && $1 == save ]]; then      auto_su      parse_options "$2"      cmd_save  elif [[ $# -eq 2 && $1 == strip ]]; then      auto_su      parse_options "$2"      cmd_strip  else      cmd_usage      exit 1  fi    exit 0  

dialog for pass (unix password manager) disappeared

Posted: 05 Apr 2021 09:39 AM PDT

I recently migrated from Arch to Artix Linux and the GUI dialog for pass disappeared. I need to get it back.

In Arch, passmenu launches a GUI dialog to insert the password for the gpg keys, but in Artix pass or passmenu only opens terminal dialogs. That means I can't launch a password prompt dialog from scripts or from keybindings. T

This is very inconvenient because if I want to login into a website I have to open a terminal just for that (in Arch, it would open a floating dialog in the middle of the screen to type the password, which is very convenient).

I bet there is a package for opening such GUI dialogs, but I don't know which package. Does anyone know the package?

Note: the packages from Arch's repository are avaialble on Artix too.

How can i test something like if it's the format of car plate?

Posted: 05 Apr 2021 10:09 AM PDT

I need to test if an input it has the fromat of a car plate (0000-XYZ) and from the japanese ZIP wich the format is 000-0000

I have Q4OS and I can't get internet

Posted: 05 Apr 2021 09:08 AM PDT

I have Q4OS and I tried so many things with the sudo commands. I can't get my Archer T2U usb wifi adapter to work so I don't get internet because my internal adapter doesn't work. The error I get is

Package git is not available, but is referred to another package

after I type in

sudo apt install git dkms.

What does it mean <<EOF in (t)csh?

Posted: 05 Apr 2021 09:14 AM PDT

I have the following command:

wash -n <groups> <<EOF  echo hi   echo bye <<BYE    <commands>    exit 0  BYE  exit 0  EOF    <commands>  

where <groups> are some groups and <commands> are commands. I don't understand what <<EOF and <<BYE mean? Is it some label which the script jumps in case fails? What does this script do?

over the wire level 1

Posted: 05 Apr 2021 08:52 AM PDT

the hidden dash file

cat ./- (works perfect, and shows password)

However yesterday i used a similar command with quotations i just cannot remember it :(

can anyone suggest what that may have been ?

n.b i am now documenting every step using nano and creating files so that i learn nano and also terminal commands. This site is great for answers thank you

Now i need to build rep :(

Why is my message not displayed?

Posted: 05 Apr 2021 08:47 AM PDT

I have a following script:

#!/bin/bash    set -euo pipefail  IFS=$'\n\t'    CIRCLE_USERNAME="${1:-}"  CIRCLE_BUILD_URL="${2:-}"  CIRCLE_JOB="${3:-}"  CIRCLE_PROJECT_USERNAME="${4:-}"  CIRCLE_PROJECT_REPONAME="${5:-}"  CIRCLE_BRANCH="${6:-}"  CIRCLE_SHA1="${7:-}"    export CIRCLE_USERNAME="XXX"  export CIRCLE_BUILD_URL="XXX"  export CIRCLE_JOB="build"  export CIRCLE_PROJECT_USERNAME="XXX"  export CIRCLE_PROJECT_REPONAME="XXX"  export CIRCLE_BRANCH="main"  export CIRCLE_SHA1="XXX"  export CIRCLECI_SLACK_INTEGRATION_TOKEN=XXX  export GITHUB_AUTHORIZATION_TOKEN=XXX  export CIRCLECI_AUTHORIZATION_TOKEN=XXX    BASE_PATH="$(readlink --canonicalize $0)"  BASE_DIRECTORY="${BASE_PATH%/*}"    GIT_COMMIT=$(curl -s --header "Content-Type: \"application/vnd.github.v3+json\"" --header "Authorization: token $GITHUB_AUTHORIZATION_TOKEN" https://api.github.com/repos/integromat/$CIRCLE_PROJECT_REPONAME/commits | jq -r '.[1].commit.message')  echo "GIT_COMMIT: "$GIT_COMMIT    SHORT_HASH=$(echo $CIRCLE_SHA1 | cut -c -7)  API_URL=$(echo $CIRCLE_BUILD_URL | cut -d/ -f4-7)    echo "SHORT_HASH: "$SHORT_HASH  echo "API_URL: "$API_URL      read -r -d  MESSAGE << EOF  "blocks":  [    {      "type": "section",      "text":      {        "type": "mrkdwn",        "text": "Success: $CIRCLE_USERNAME's workflow (<$CIRCLE_BUILD_URL|$CIRCLE_JOB>) in <https://app.circleci.com/pipelines/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME|$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME> (<https://app.circleci.com/pipelines/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME?branch=$CIRCLE_BRANCH|$CIRCLE_BRANCH>)\n- $GIT_COMMIT (<https://github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/commit/$CIRCLE_SHA1|$SHORT_HASH> by $CIRCLE_USERNAME)"      }    }  ]  EOF    echo "${MESSAGE}"  

My problem is that message in the end is not displayed at all (last paragraph), I have no clue why, as following script displays the message without any problem:

#!/bin/bash    CIRCLE_BUILD_URL='aaa'  CIRCLE_JOB='bbb'  CIRCLE_PROJECT_USERNAME='ccc'  CIRCLE_PROJECT_REPONAME='ddd'  CIRCLE_BRANCH='eee'  GIT_COMMIT_DESC='fff'  CIRCLE_SHA1='ggg'    read -r -d '' MESSAGE << EOF  "blocks":  [    {      "type": "section",      "text":      {        "type": "mrkdwn",        "text": "Success: $CIRCLE_USERNAME's workflow (<$CIRCLE_BUILD_URL|$CIRCLE_JOB>) in <https://app.circleci.com/pipelines/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME|$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME> (<https://app.circleci.com/pipelines/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME?branch=$CIRCLE_BRANCH|$CIRCLE_BRANCH>)\n- $GIT_COMMIT_DESC (<https://github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/commit/$CIRCLE_SHA1|$SHORT_HASH> by $CIRCLE_USERNAME)"      }    }  ]  EOF    echo "${MESSAGE}"  

Please, what am I doing wrong?

Test if a variable has more that 4 digits in bash script

Posted: 05 Apr 2021 08:58 AM PDT

i want to test if a variable has more than 4 digits something like this

#!/bin/bash  if [ $input has more than 4 digits ]; then        echo "  * Please only 4 digits" >&2       echo""  else     the other option  fi  

What are the message formats in `/var/log/syslog` and the output of `dmesg`?

Posted: 05 Apr 2021 09:12 AM PDT

On Debian or Ubuntu, what are the formats of /var/log/syslog and the output of dmesg?

In /var/log/syslog, I figure from

Apr  1 08:15:01 mycomputer CRON[12494]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)  

that its log message format is

timestamp hostname program-name[pid]: unstructured-message  

In output of dmesg, I figure from

[    0.309493] system 00:01: [mem 0xe0000000-0xefffffff] has been reserved  

that its message format is

[timestamp] ?  ?: [?] unstructured-message  

But they are just guesses, certainly with missing and wrong parts.

/var/log/syslog is written by rsyslogd, which might (or not?) follow the syslog protocol for receiving messages, but may write the messages in different format. The manpage of rsyslogd doesn't say anything about the message format, if I am correct.

The output of dmesg is exactly what the kernel follows when it writes the messages. It is unrelated to the syslog protocol. So there is more unknown. The manpage of dmesg doesn't say any thing about the message format, if I am correct.

Call variable from within udev rule

Posted: 05 Apr 2021 09:19 AM PDT

I have multiple udev rules that check if ATTRS{name}=="abc123" and invokes various functions if that device is present. These udev rules are located within multiple locations as this is being created within bitbake for a custom embedded OS. Now, if I want to change this device to test different hardware, this is too time consuming to change every ATTR{name} call every time.

My solution would be to define a var, e.g. $UDEVVAR="[device_name]" in some conf file (to be determined), and then change each ATTR{name} call to something like ATTR{name}=="${UDEVVAR}".

I've tested this approach in a local rule written for proof of concept, although the rule didn't invoke. This local rule was a bit different, though followed the same concept. Whatever flash drive I had lying around didn't have an ATTR{name} defined, so I used a usb mouse and that flash drive. This udev rule is:

SUBSYSTEM=="${UDEVVAR}", ACTION=="add", RUN+="/usr/local/bin/trigger.sh"

trigger.sh simply writes the date-time stamp to a log file. When hard coding SUBSYSTEM as =="block", the rule invokes successfully, although when defining UDEVVAR="block", the rule does not get invoked. The idea was, if that worked, then I would define UDEVVAR="hidraw" to test the mouse.

I can't seem to find much documentation on anyone trying to do something like this. I figure I'm making some sort of syntactical mistake, or maybe udev rules don't allow for something like this.

I appreciate any help!

swapoff -a + why swapoff never finished

Posted: 05 Apr 2021 09:26 AM PDT

we have rhel machines version rhel 7.2

since we want to set the kernel parameter vm.swappiness to 1
we need to perform swapoff and swapon

so we set the vm.swappiness to 1

and we performed swapoff -a

but after 1-2 days , still swapoff -a is running and not finished , seems that "memory" that located on a disk isn't completely transferring to the memory cards

from free -g , we can see that consume swap is around 3-4 giga but its not decreasing from this point

I don't sure why swapoff -a not ended , but the other choice is to reboot the RHEL 7.2 machine , but we want to avoid machine restart

enter image description here

using command subsitition in a bash for loop

Posted: 05 Apr 2021 09:35 AM PDT

I am probably making an obvious mistake but I could use a strong hint:-)

for file in *; do ls $file | var=$(ls $file | grep -Eo '.{18}$' | cut -d '.' -f1 |sed 's/.\{12\}/&./'); echo "var is $var. File is $file";done  

RESULT: $var is empty. $file is not. Why is $var empty?

When I manually put my test string in $file and run as follows, $var contains what I want:

var=$(ls $file | grep -Eo '.{18}$' | cut -d '.' -f1 |sed 's/.\{12\}/&./')  

So there is something about the for loop which is causing this. It seems the $var variable has a scope limitation preventing me from using in following statements.

Have a great Easter:-)

full example:

As asked, here is an example to hopefully clarify my query. The file's inventory_a_test-20190605161153.txt1 date must match the date in its file name. First, I set the file to the wrong date:

$ touch inventory_a_test-20190605161153.txt  $ ls -l --full-time inventory_a_test-20190605161153.txt  -rw-rw-r-- 1 root root 0 **2021-04-05** 15:02:05.000000000 +0200 inventory_a_test-20190605161153.txt  

Now I want to write a command flow like the one below as a for loop in bash to correct the date:

$ file=inventory_a_test-20190605161153.txt  $ ls $file | grep -Eo '.{18}$' | cut -d '.' -f1 |sed 's/.\{12\}/&./'  201906051611.53  $ touch -a -m -t 201906051611.53 $file  $ ls -l --full-time inventory_a_test-20190605161153.txt  -rw-rw-r-- 1 root root 0 **2019-06-05** 16:11:53.000000000 +0200   inventory_a_test-20190605161153.txt  

Find files with matched whole lines from a file

Posted: 05 Apr 2021 10:28 AM PDT

I have a file with this content:

$ cat compromised_header.txt  some unique string 1  some other unique string 2  another unique string 3  

I wanted to find all files that have all the lines of above file exactly in the same order.

Example input file:

$ cat a-compromised-file.txt  some unique string 1  some other unique string 2  another unique string 3  unrelated line x  unrelated line y  unrelated line z  

I tried using below grep:

grep -rlf compromised_header.txt dir/  

But I wasn't sure it will give the expected files as it will also match this file:

some unique string 1  unrelated line x  unrelated line y  unrelated line z  

Is there a file that will always not exist?

Posted: 05 Apr 2021 10:07 AM PDT

Along the lines of '/dev/null' (path to an empty file), is there a path that will never point to a valid file on at least Linux? This is mostly for testing purposes of some scripts I'm writing, and I don't want to just delete or move a file that doesn't belong to the script if it exists.

EXT4-fs (vda): couldn't mount RDWR because of unsupported optional features (4000)

Posted: 05 Apr 2021 09:57 AM PDT

I want to virtualize correctly Android 10 on top of my Jetson nano (arm64) using qemu and kvm on ubuntu 18.04. This is the tutorial that I'm following :

https://github.com/antmicro/kvm-aosp-jetson-nano/blob/master/README_Jetson_Nano_BSP.md

It ends with an error :

[ 1.074939] EXT4-fs (vda): couldn't mount RDWR because of unsupported optional features (4000)  [ 1.078049] init: [libfs_mgr]__mount(source=/dev/block/vda,target=/system,type=ext4)=-1: Invalid argument  [ 1.081515] init: Failed to mount /system: Invalid argument  [ 1.084120] init: Failed to mount required partitions early ...  [ 1.096129] init: #00 pc 00000000000e90a0 /init  [ 1.097856] init: #01 pc 000000000006c4d8 /init  [ 1.099631] init: #02 pc 000000000006e930 /init   

Unfortunately the developer of the github closed the bug section,so I can't ask directly there. This is the script that I use to run it :

qemu-system-aarch64 \          -enable-kvm \          -smp 2 \          -m 2048 \          -cpu host \          -M virt \          -device virtio-gpu-pci \          -device usb-ehci \          -device usb-kbd \          -device virtio-tablet-pci \          -usb \          -serial stdio \          -display sdl,gl=on \          -kernel aosp/Image \          -initrd aosp/ramdisk.img \          -drive index=0,if=none,id=system,file=aosp/system.img \          -device virtio-blk-pci,drive=system \          -drive index=1,if=none,id=vendor,file=aosp/vendor.img \          -device virtio-blk-pci,drive=vendor \          -drive index=2,if=none,id=userdata,file=aosp/userdata.img \          -device virtio-blk-pci,drive=userdata \          -full-screen \          -append "console=ttyAMA0,38400 earlycon=pl011,0x09000000 drm.debug=0x0 rootwait rootdelay=5 androidboot.hardware=ranchu androidboot.selinux=permissive security=selinux selinux=1 androidboot.qemu.hw.mainkeys=0 androidboot.lcd.density=160"  

I've compiled the android images on Ubuntu 20.10. My jetson nano is running with :

# ./jetsonInfo.py    NVIDIA Jetson Nano (Developer Kit Version)    L4T 32.5.1 [ JetPack UNKNOWN ]   Ubuntu 18.04.5 LTS Kernel Version: 4.9.201+   Xlib:  extension "NV-GLX" missing on display ":1003.0".    Xlib:  extension "NV-GLX" missing on display ":1003.0".    Xlib:  extension "NV-GLX" missing on display ":1003.0".   CUDA 10.2.89   CUDA Architecture: 5.3   OpenCV version: 4.5.0   OpenCV Cuda: YES   CUDNN: 8.0.0.180    TensorRT: 7.1.3.0   Vision Works: 1.6.0.501  VPI: ii libnvvpi1 1.0.15 arm64 NVIDIA Vision Programming  

It seems that the solution is here :

Linux - couldn't mount RDWR because of unsupported optional features (400)

he says :

To create a ext4 filesystem without this feature:

sudo mke2fs /dev/sdb1 -O ^metadata_csum  

Or turn it off on an already created filesystem:

sudo tune2fs -O ^metadata_csum /dev/sdb1  

good. So,I should modify the right python script which build the system.img file. Anyway I don't know which is the right one. BTW I copied all the python files that have been used to build the android images on my google drive,here :

https://drive.google.com/drive/folders/1bEeV2Bt-ubuazvwnyi8a-81PTZsMOooI?usp=sharing

what I'm asking is if someone can identify the right python file and if he can modify it a little bit,like suggested on the unix stack exchange site.

Run two commands one after another in bash, via a function, called with `eval`

Posted: 05 Apr 2021 09:44 AM PDT

I am facing problems running two commands one after another in bash.  When I run

source2() { '/home/ds/Documents/scripts/Untitled Document 1.sh' && imgpath="$(ls | grep "^unsplash")" }    source3()  {  '/home/ds/Documents/scripts/Untitled Document 2.sh' && imgpath="$(ls | grep "^1920x1080" | shuf -n 1)" }    source4()   {  '/home/ds/Documents/scripts/Untitled Document 3.sh' && imgpath="$(ls | grep "^unsplashimg")" }        SOURCES=("source2" "source3" "source4")  $(eval $(shuf -n1 -e "${SOURCES[@]}"))  echo $imgpath  

The bash script part runs, but the part after && does not and hence echo $imgpath gives no output. When I run individual commands like

'/home/ds/Documents/scripts/Untitled Document 1.sh' && imgpath="$(ls | grep "^unsplash")"  

then I get desired outputs.

What am I doing wrong?

I have taken hints from

Btrfs RAID1: How to replace a disk drive that is physically no more there?

Posted: 05 Apr 2021 09:10 AM PDT

I have a btrfs RAID1 system with the following state:

# btrfs filesystem show  Label: none  uuid: 975bdbb3-9a9c-4a72-ad67-6cda545fda5e          Total devices 2 FS bytes used 1.65TiB          devid    1 size 1.82TiB used 1.77TiB path /dev/sde1          *** Some devices missing  

The missing device is a disk drive that failed completely and which the OS could not recognize anymore. I removed the faulty disk and sent it for recycling.

Now I have a new disk installed under /dev/sdd. Searching the web, I fail to find instructions for such a scenario (bad choice of search terms?). There are many examples how to save a RAID system when the faulty disk still remain somewhat accessible by the OS. btrfs replace command requires a source disk.

I tried the following:

# btrfs replace start 2 /dev/sdd /mnt/brtfs-raid1-b  # btrfs replace status /mnt/brtfs-raid1-b  Never started  

No error message, but status indicate it never started. I cannot figure out what the problem with my attempt is.

I am running Ubuntu 16.04 LTS Xenial Xerus, Linux kernel 4.4.0-57-generic.

Update #1

Ok, when running the command in "non background mode (-B)", I see an error that did not showed up before:

# btrfs replace start -B 2 /dev/sdd /mnt/brtfs-raid1-b                                                                                                                       ERROR: ioctl(DEV_REPLACE_START) failed on "/mnt/brtfs-raid1-b": Read-only file system  

/mnt/brtfs-raid1-b is mounted RO (Read Only). I have no choice; Btrfs does not allow me to mount the remaining disk as RW (Read Write). When I try to mount the disk RW, I get the following error in syslog:

BTRFS: missing devices(1) exceeds the limit(0), writeable mount is not allowed  

When in RO mode, it seams I cannot do anything; cannot replace, nor add, nor delete a disk. But there is no way for me to mount the disk as RW. What option is left?

It shouldn't be this complicated when a simple disk fails. The system should continue running RW and warn me of a failed drive. I should be able to insert a new disk and have the data recopied over it, while the applications remain unaware of the disk issue. That is a proper RAID.

How to add more system event sound effects in Cinnamon?

Posted: 05 Apr 2021 09:01 AM PDT

How can I add more sounds to different system events on Linux for different actions or events? For example by default on some Linux desktops, say Linux Mint for example, you get sound effects when you take a screenshot, or open and close windows.

But what about having sound notifications trigger for other certain dialogs or important things that needs attention? I'd like to know how system sounds are triggered for certain event, and how can also be made so that it shows up in the Sound Effects tab of Sound panel for System Preferences so it can be changed at any time?

Sound panel of System Preferences

How to resize / shifting partitions?

Posted: 05 Apr 2021 09:08 AM PDT

I am running out of space on my root partition and would like to steal some from a different partition. The drives are 2x120GB with mdadm software RAID. I am using CentOS 6.5 64-bit. I used the centos installer guided RAID setup. It seems like most of the HowTos are gearing me towards not having the underlying partitions. So others would have just /dev/md0. They would perform a resize2fs /dev/md0 25G (reducing from 50G for example) and then use mdadm to resize it, etc.

The layout is:

  Filesystem            Size  Used Avail Use% Mounted on  /dev/md0p5            9.7G  7.1G  2.1G  78% /  tmpfs                  16G     0   16G   0% /dev/shm  /dev/md0p1            194M   99M   86M  54% /boot  /dev/md0p2             68G  7.2G   57G  12% /var/www  

cat /proc/mdstat:

  Personalities : [raid1]   md0 : active raid1 sdb[1] sda[0]        117220736 blocks [2/2] [UU]    unused devices:   

Here is the fdisk:

  fdisk -l    Disk /dev/sda: 120.0 GB, 120034123776 bytes  255 heads, 63 sectors/track, 14593 cylinders  Units = cylinders of 16065 * 512 = 8225280 bytes  Sector size (logical/physical): 512 bytes / 512 bytes  I/O size (minimum/optimal): 512 bytes / 512 bytes  Disk identifier: 0x00035afc       Device Boot      Start         End      Blocks   Id  System  /dev/sda1   *           1          26      204800   83  Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2              26        8950    71680000   83  Linux  /dev/sda3            8950       11039    16777216   82  Linux swap / Solaris  /dev/sda4           11039       14594    28557312    5  Extended  /dev/sda5           11039       12314    10240000   83  Linux    Disk /dev/sdb: 120.0 GB, 120034123776 bytes  255 heads, 63 sectors/track, 14593 cylinders  Units = cylinders of 16065 * 512 = 8225280 bytes  Sector size (logical/physical): 512 bytes / 512 bytes  I/O size (minimum/optimal): 512 bytes / 512 bytes  Disk identifier: 0x00035afc       Device Boot      Start         End      Blocks   Id  System  /dev/sdb1   *           1          26      204800   83  Linux  Partition 1 does not end on cylinder boundary.  /dev/sdb2              26        8950    71680000   83  Linux  /dev/sdb3            8950       11039    16777216   82  Linux swap / Solaris  /dev/sdb4           11039       14594    28557312    5  Extended  /dev/sdb5           11039       12314    10240000   83  Linux    Disk /dev/md0: 120.0 GB, 120034033664 bytes  2 heads, 4 sectors/track, 29305184 cylinders  Units = cylinders of 8 * 512 = 4096 bytes  Sector size (logical/physical): 512 bytes / 512 bytes  I/O size (minimum/optimal): 512 bytes / 512 bytes  Disk identifier: 0x00035afc        Device Boot      Start         End      Blocks   Id  System  /dev/md0p1   *         257       51456      204800   83  Linux  Partition 1 does not end on cylinder boundary.  /dev/md0p2           51457    17971456    71680000   83  Linux  Partition 2 does not end on cylinder boundary.  /dev/md0p3        17971457    22165760    16777216   82  Linux swap / Solaris  Partition 3 does not end on cylinder boundary.  /dev/md0p4        22165761    29305088    28557312    5  Extended  Partition 4 does not end on cylinder boundary.  /dev/md0p5        22166273    24726272    10240000   83  Linux  

So what can I do to grow the root partition and shrink the /var/www partition?

API Monitoring and Hooking

Posted: 05 Apr 2021 10:00 AM PDT

I am currently reading the "Malware Analyst's Cookbook and DVD". There is a chapter "Dynamic Analysis" and there are also some recipes about hooking and monitoring API calls of process but it is for Windows.

I want to do the same thing like recipe 9-10 explains but for Linux. 9-10 is called "Capturing process, Thread, and Image Load Events". In this receipe it is showed "how to implement a driver that alerts you when any events occure on the system while your malware samlpe executes". It uses the API functions of the Windows Driver Kit (WDK) to call a user-defined callback function. It uses the callback functions:

  • Process creation callback function called PsSetCreateProcessNotifyRoutine(...)
  • Thread creation callback function called PsSetCreateThreadNotifyRoutine(...)
  • Image load callback function called PsSetLoadImageNotifyRoutine(...).

And when any events occur it will display them as a debug message which can then be viewed in e.g. DebugView.

It seems well documented for Windows and it is easy to find information for this, but I have a bit of a problem in finding information for Linux.

I've found some general introduction to drivers and a one for hooking, but I still haven't found any that are not so general or at least are a bit more focused on malware analysis.

I would be happy for tips for further readings or recommended tutorials on this topic.

How to add all binaries to bash tab completion for some command?

Posted: 05 Apr 2021 09:29 AM PDT

I've installed program trickle that allow to throttle the net for specified command like:

trickle -u10 -d10 <COMMAND>  

How to add bash completion for all binaries to trickle command?

bash scripting add arguments

Posted: 05 Apr 2021 09:09 AM PDT

I have created a script which takes parameters and arguments. I want to insert the --help argument.

I already know how to parse normal arguments with -, but I don't know how to parse the -- ones.

To parse options for test.sh -h, I use the following check:

while getopts ":h" opt;   do   case $opt in      h ) {              echo "help!!!"              exit 1      } ;;  esac  done  

But I want to have the option to call the script with test.sh --help.

P.S. I am using Ubuntu 12.04… but it doesn't really matter.

Emacs M-h selects paragraph + an extra line

Posted: 05 Apr 2021 09:44 AM PDT

In Emacs, when I type M-h (mark-paragraph), Emacs selects the paragraph under point plus an extra line (typically right above the paragraph). Is there a way to ask Emacs to just select the paragraph?

Note: I have noticed this behavior under shell-script-mode, but haven't checked if it occurs with other major modes.

No comments:

Post a Comment