Return to Level1Techs.com

The small linux problem thread

linux
helpdesk

#2144

its the return status $?


#2145

Yep that’t it, he has exit code in is $PS1


#2146

Yeah, it makes sense now. I’ve been staring at this too long.


Here’s one that is getting frustrating…

[ ${__ABORT} -eq 1 ] &&
echo ${__ABORT} &&
debug "Backup was aborted. Compiling report."

is generating:

0
2019/02/17 00:45:37 DEBUG : Backup was aborted. Compiling report.

#2147

I have a problem with switching my audio adapters in Fedora 29. I have headphones plugged in the front I/O of my case and the speakers in the MB at the back. I only get audio from the headphones. I switch to the other adapter inside the audio settings and silence.
Edit to add: on windows I just click on the speaker next to the clock and choose the output. In fedora, this isn’t the case.


#2148

Hi,
On my main machine man -k doesn’t seem to work, man -K works but is not the same

command taken from the man manpage

$ man -k printf
printf: nothing appropriate.

just doing man printf gives the expected result

screenfetch

OS: Arch Linux
Kernel: x86_64 Linux 4.20.8-arch1-1-ARCH
Uptime: 34m
Packages: 1284
Shell: bash 5.0.0
Resolution: 4480x1440
WM: i3
GTK Theme: deepin [GTK2/3]
Icon Theme: deepin
CPU: Intel Core i7-4770K @ 8x 3.9GHz [27.8°C]
GPU: GeForce GTX 970
RAM: 2753MiB / 15988MiB

[edit1]
For some reason i didn’t think about searching for man -k nothing appropriate, after doing that i found an answear, sorry for posting this


#2149

What shell are you using?
Shouldn’t that be (for bash):

if [ ${__ABORT} -eq 1 ]; then
echo ${__ABORT} 
debug "Backup was aborted. Compiling report."
fi

#2150

I had an || before it that was messing it up.

I like to use && and || for logic and error handling. Like this:


#2151

Good to know, I’m gonna bookmark this.


#2152

It has a nice unixy flow to it. I probably overdo it, but here’s the script I was working on:

There are aspects of it that I still need to test, but the basics work.

It adds lock file, email reporting and simplified arguments to rclone and will automatically copy/sync from the most recent zfs snapshot with the -S flag.


#2153

I sort of prefer the if then style. The && and || make the logic harder to follow. (I’m not saying you should change it, use whatever style makes it easier to maintain – that’s the important part)

For example:

if [ $use_backup_dir -eq 1 ] ; then
  backup_dir_total_size_after=$( 
    rclone size $( dirname ${backup_dir} ) 2> /dev/null | 
      tail -1 | 
        sed 's/Total size: //'
  ) || fail

  debug "Total backup directory size is: ${backup_dir_total_size_after}."
  
  backup_dir_size=$( 
    rclone size ${backup_dir} 2> /dev/null |
      tail -1 |
        sed 's/Total size: //' 
  ) || fail

  debug "Current backup directory size is: ${backup_dir_size}."
else
  warn "${__BLOCK}"
  more code...
fi

#2154

Another thing that bothers me is that there is no way to catch the return status from a piped command. The return status is always the last command executed.

So, this

backup_dir_size=$( 
    rclone size ${backup_dir} 2> /dev/null |
      tail -1 |
        sed 's/Total size: //' 
  ) || fail

Doesn’t work, since sed will always succeed, even if rclone fails. The status has to be sent via signal to cause the pipeline to stop running. Like this:

#!/bin/bash

function list_files() {
  if ! ls -l $1 ; then
    echo error listing files in $1 1>&2
    kill 0
  fi
}

function show_number() {
  local num=$(
        list_files $1 |
          head -1 |
            sed -e 's/total //'
      )
  echo num is $num
} 

show_number $1

When list_files fails, it signals that so that show_number never runs. The above is in a script called test.sh here:

$ ./test.sh /
num is 48
$ ./test.sh /adfasdf
ls: cannot access '/adfasdf': No such file or directory
error listing files in /adfasdf
Terminated

Without the kill, the script continues on it’s merry way when it should have failed.

After removing kill 0 from list_files function:

$ ./test.sh /adfasdf
ls: cannot access '/adfasdf': No such file or directory
error listing files in /adfasdf
num is

Num is set to the null string when the directory doesn’t exist since the shell script continues to run.

More on the pipe status in this stack overflow


#2155

For some reason my laptop isn’t getting a default route when connecting via ethernet. It pulls DHCP fine (gets a /8 route instead of a /24 for some reason) but has no default gateway.
Using NetworkManager btw.


#2156

Boot another os and see what address it gets


#2157

Just tested another laptop, and it does the same thing. /8 route instead of /24 no gateway set, no default route.
Also running NetworkManager, but this laptop is Ubuntu running default configs instead of Gentoo.


#2158

Bad DHCP server settings?


#2159

Remember kiddos… when you install in CSM mode and boot in UEFI mode you’re going to have a bad time.


#2160

That’d be my guess.


#2161

I’m having trouble installing steam. it appears to install just fine, both through the CLI and the ubuntu app store but it won’t launch. I have an HP Envy x360 ryzen 5 2500u model, running Ubuntu 18.10 running the linux kernel 4.20.10


#2162

What does it spit back if you try running it from a Terminal Emulator?


#2163

how do you do that?