Wednesday, March 24, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Skip password prompt and pass password to ssh-add in script

Posted: 24 Mar 2021 10:09 AM PDT

I'm trying to write a script that automatically unlocks all of my rsa keys with ssh-add.

I use pass to store my passwords (encrypted with gpg keys) and I'm trying to pass its input to ssh-add as follows:

rsa_dir=~/.ssh  cd $rsa_dir  ls -1 id_rsa* |  grep -v '.pub' |  while read file; do    # example: file == id_rsa_github -> keyname == rsa/github    key_name=${file/id_rsa_/rsa/}    # pass will prompt (only once) for the master password, then print out the request password to stdout    pass $key_name | ssh-add $file  done  

However, it gives an error:

ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory  

But if I just run ssh-add $file, it prompts for a password and works fine. I don't want to use the default ssh-askpass to get the password. I need to use my own script.

Can someone please help me?

"symbol lookup error: /usr/lib/x86_64-linux-gnu/libnssutil3.so undefined symbol: PR_GetEnvSecure"

Posted: 24 Mar 2021 10:02 AM PDT

I'm in puppy linux (Tahr), installed Discord and tried to run it with

sudo discord  

First the problem was that I didn't have the libnss3.so, installed it. Then I need the libnssutil3.so, installed it. Now when I run:

sudo discord  

I get:

/usr/share/discord/Discord: symbol lookup error: /usr/lib/x86_64-linux-gnu/libnssutil3.so undefined symbol: PR_GetEnvSecure  

What does "Missing value on line X of /var/cache/cups/jobs.cache" mean?

Posted: 24 Mar 2021 09:47 AM PDT

When I do sudo cupsd -t I get the following error:

Missing value on line 238 of /var/cache/cups/jobs.cache  Missing value on line 3282 of /var/cache/cups/jobs.cache  

What does this mean?

Is there a way to detect the user's password entry in sshd to warn that they must change it?

Posted: 24 Mar 2021 09:54 AM PDT

I have a box I would like to distribute as a Vagrant box (and eventually Dockerfile). the initial password specified in the README file, I'd like to detect if it is being used (it's very simple and is 4 characters long) and warn the user on login that they need to change it. Is this possible? I don't see anything that hints this in /etc/ssh/sshd_config

An acceptable workaround if not would be reading the number of keystrokes and if 4 are detected warn the user that way. A REALLY good feature would be to change the password if the user doesn't reply after 3 times.

(NOTE: I'm following a tip from a reviewer that this is a better place to post this question than stack overflow proper)

How should I create and use a filesystem for a build server?

Posted: 24 Mar 2021 09:46 AM PDT

I'm about to add a new (virtual) disk to one of my build machines, that runs on a VM host I have no control over. This will be used for compiling large amounts of source code (a Yocto distribution) from sources that are obtained elsewhere (Web servers or Git repositories).

Read and write speed for the many small files and a few very large files is my most important consideration. Long-term data integrity is of low importance, as everything can easily be re-created: I'm comfortable with losing files when there's an unplanned power interruption, for example.

I think I'm going to use an ext4 filesystem, though I'm open to considering other types if there will be an appreciable benefit.

What mkfs flags should I use, and what mount options?

There's a similar, but old, question on Server Fault; I'd like advice that's relevant in 2021.

Find and print the length of the longest line in multiple files?

Posted: 24 Mar 2021 09:53 AM PDT

In my folder, I have 2000 files, which are labeled A0001-A2000. In the second line of each file, there is a long (it should be the longest) line of characters. I would like to print all the file names with the length of the second line in one output.

so the output will look something like

A0001 231  A0002 123  A0003 56  

If it is helpful I already have a code that will print the longest line of a file, but I am not tied to using awk if there is an easier way.

$ awk '{print length}' A0001.txt |sort -nr|head -1  231  

Libreoffice's instert special character window looks HUGE (can't resize to smaller)

Posted: 24 Mar 2021 09:40 AM PDT

I write this post because I have the doubt about this being a libreoffice bug, a GNOME bug... or what could be the cause, because I don't seem to find and issue related to this anyware else.

When I go to Libreoffice Insert > special characters menu, the window that opens with the characters, is huge and doesn't fit on the screen, so I can't really use it.

enter image description here

I used to be in Debian 10 (since it came out up until 2 months ago) and now I'm in Debian testing. Back in the day I had installed the flatpak version (so, the "fresh" version; the last one I had was v. 7.1, I believe) of libreoffice and had the same issue. I thought back then that the problem might be due to using a flatpak (sometimes they don't integrate well with system themes... etc).

But now I've realized that I have the same problem with the official repos from Debian bullseye: I'm running LibreOffice 7.0.4.2. Having the same problem in different number versions... and both flatpak and regular repo packages... makes me thing the problem should be something different.

I'm now running GNOME 3.38.4. Back in the day, GNOME 3.30 in Debian stable.

I can make the window a bit bigger, but I cant make it smaller! It's twice my desktop resolution (1440p) in high, so it is impossible for me to reach the INSERT button... lol! I rarely use this option, but when I need it... I end up searching for the character online and copy&pasting... which doesn't seem ok.

Anyone else has this problem? Do you guys have any idea what should I try?

EDIT: I searched about how to report a bug in libreoffice, but I've never used bugzilla, so I thought I should ask first.

My Script need to kills previous instances of itself upon running not killing one of the child process

Posted: 24 Mar 2021 09:29 AM PDT

I have the following Script File 'bored.sh'. This file recursively calls itself.

curl "https://www.boredapi.com/api/activity" >>./bored.json  bash ./bored.sh  

I realized that this is a bad approach as it creates several instances and runs many processes that uses the system resources and ultimately crashes the system.

How do I terminate/kill all the previous instances of the scripts after they are executed (series of API call and store those response to file) sequentially but make sure this script runs indefinitely as only one or few child process and create less stress to my system?

iptables: Route outgoing requests to a local proxy preserving destination address and port

Posted: 24 Mar 2021 09:15 AM PDT

I want the proxy to make some routing decisions based on the original destination IP and port. I can do this easily for an incoming request:

iptables -t mangle -A PREROUTING -p tcp --destination 10.37.253.90 \      --dport 8080 -j TPROXY --on-port 8081  

This intercepts the packets headed for 10.87.253.90:8080 on local port 8081 of the proxy.

But how can I intercept an outgoing request and redirect to a local port retaining the original destination address?

I deleted the Ubuntu partition, and proceeded to delete Ubuntu from my system files. Can't access grub rescue

Posted: 24 Mar 2021 09:11 AM PDT

I'm in this loop. Whatever I select, I get back to the same options. I have Windows installed in my HDD but I can't access it. Even the grub rescue won't open (I may have deleted it accidentally?)

Wifi isnt working after using wifite [duplicate]

Posted: 24 Mar 2021 09:17 AM PDT

I was using wifite command I know that WiFi state goes to down when we run wifite command. And, WiFi state goes to up after restarting laptop also. I was running that command few hours ago. When I restarted my laptop I noticed it(WiFi) was working properly. But, when I have start laptop again I am not getting any WiFi list even WiFi isn't showing after typing ifconfig

After running ifconfig -a enter image description here

Sorry I am unable to format my question and copy and paste those texts from terminal. ~ cause, I am using Unix SE from android device

I have tried answers from here

when I tried sudo service network-manager restart I got error Failed to restart network-manager.service: Unit network-manager.service not found.

BASH command not found when executing in remote linux cluster using shell script

Posted: 24 Mar 2021 10:13 AM PDT

I am trying to automate a few steps that I need to execute in a remote linux machine from my local ubuntu computer.

My shell script is as follows :-

#!/bin/sh    ssh XYZ '    qlogin -l cuda=1    '  

When I am trying to execute it by collecting the ./fileName.sh . I am getting

bash: line 2: qlogin: command not found  

However, when I do it manually i.e. ssh into the cluster and than run this command , I am able to execute it.

Troubleshooting till now

  1. Both the local and remote terminal is bash . This I got by echo $0

  2. When I manually ssh into the remote and print the path for qlogin (via which qlogin). I get

/opt/ge/bin/lx-amd64/qlogin  

However, when I do the same via the script,I don't get any which means that qlogin is not installed.

  1. Finally, I the user executing the script and the user that logs in when i manually ssh are not the same (got it by printing the who).

What should I do ?

How do I determine which filesystem is in use on my "Microsoft basic data" partition? [duplicate]

Posted: 24 Mar 2021 09:10 AM PDT

I'm looking at WD Mybook disk, connected via USB as disk sde. Now, fdisk -l /dev/sde tells me that the single partition on the drive is:

Device     Start         End     Sectors  Size Type  /dev/sde1   2048 15628050431 15628048384  7.3T Microsoft basic data  

but what's that? I don't quite understand what the Wikipedia page is telling me about this partition type. It seems to be auto-mounted fine, and still I don't undestand what filesystem is in use.

Push etckeeper created repository to remote Gitlab server, advices welcomed

Posted: 24 Mar 2021 08:05 AM PDT

I'm playing with etckeeper and it seems to be a good product. I use it only to track /etc filesystem locally, but these days the idea came to my mind - to create central Gitlab repository and to store all the node /etc repositories there.

The question is how can I do that?

I noticed in the config of etckeeper, there is a variable called: PUSH_REMOTE="", but do I have to create separate repository for every server or I can use one and combine all the servers in it? Maybe I can use branches? Or different folders?

Any advice's are welcomed. I will try to do it in manual way, and if it works I will think how to do it in automated way, via Puppet or Ansible..

Thanks in advance.

egrep matching lines that shouldn't match

Posted: 24 Mar 2021 07:41 AM PDT

I am trying to find out if any of the floats in the first column containing floats in a CSV have a 1 after the decimal point. Here is an example row from my CSV:

1082805252197942751,34225793738713276,serialtooldata,1,Goals,75512140,125.0,63.0,29.0,1,,,,0,899,,

The seventh column is the one I am interested in, and in the row above it does not have a 1 after the decimal point (125.0)

I've come up with two potential regular expressions:

^[0-9]+,[0-9]+,[a-z0-9]+,[0-9]+,[A-Za-z0-9\ ]+,[0-9]+,[0-9]+\.1  

or

^[A-Za-z0-9\ ,]+\.1  

These both seem to work, i.e. on a regex test page (like regex101 here and here) the line correctly fails to match either regex. But when I try them at the terminal like this

egrep ^[0-9]+,[0-9]+,[a-z0-9]+,[0-9]+,[A-Za-z0-9\ ]+,[0-9]+,[0-9]+\.1 tool_data_160321.csv  

or

egrep ^[A-Za-z0-9\ ,]+\.1 tool_data_160321.csv  

then the line is listed as a match. Why does egrep think the line matches either regex when it doesn't?

Run thousands of simple scripts in parallel

Posted: 24 Mar 2021 09:34 AM PDT

I would like to run a simple python script in ~6500 directories. The easiest, and least efficient way is to do:

for d in *_directorynumber; do (cd "$d" && cp ../script.py . && python ./script.py );done  

This obviously takes forever. Instead, I try to run in parallel:

task(){     cd "$d" && python ./script.py .   }  

Then run this task as such:

for d in *_directorynumber; do     task "$d" &  done  

After ~500 runs or so, I get the following error:

-bash: fork: retry: Resource temporarily unavailable  -bash: fork: retry: No child processes  -bash: fork: retry: No child processes  -bash: fork: retry: No child processes  

Is there another way to parallelize?

Unable to use "SSH" command while connecting to Rasperry Pi (Octoprint)

Posted: 24 Mar 2021 08:50 AM PDT

On my Mac (Big Sur v11.2), when I open Terminal, I receive the statement "The default interactive shell is now zsh. To update you account to use zsh, please run 'chsh -s /bin/zsh'." I receive this both on my MacBook Pro and iMac.

So I ran chsh -s /bin/zsh ... after fiddling with the command not working for a while.

When I type % ssh pi@octopi.local, I get -bash: fg: %: no such job

To me, that means the command is not in the directory that I'm located, but I could be wrong.

Going off other troubleshooting I've found, when I run the command declare -p PATH, I get back declare -x PATH="/usr/bin:/bin:/usr/sbin:/sbin"

Not sure where I should go from here.

Docker is not running when trying to create a Laravel application

Posted: 24 Mar 2021 07:33 AM PDT

I am starting with Laravel and I am following the installation guide from the official website.

So I had to install Docker with this guide.

When I run the last command it works fine

sudo docker run hello-world

Then, following the guide on the Laravel site, I run the command:

curl -s https://laravel.build/example-app | bash

to create a Laravel application as it said.

But when I do so it doesn't work and this message appears:

Docker is not running.

The output of systemctl status docker

● docker.service - Docker Application Container Engine     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)     Active: active (running) since Wed 2021-03-24 09:55:07 EDT; 6min ago       Docs: https://docs.docker.com   Main PID: 1445 (dockerd)      Tasks: 13     CGroup: /system.slice/docker.service             └─1445 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock    Mar 24 09:55:06 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:06.568086445-04:00" level=warning msg="Your kernel does not support CPU realtime scheduler"  Mar 24 09:55:06 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:06.568093668-04:00" level=warning msg="Your kernel does not support cgroup blkio weight"  Mar 24 09:55:06 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:06.568100040-04:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"  Mar 24 09:55:06 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:06.568236866-04:00" level=info msg="Loading containers: start."  Mar 24 09:55:07 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:07.227307787-04:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"  Mar 24 09:55:07 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:07.501565370-04:00" level=info msg="Loading containers: done."  Mar 24 09:55:07 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:07.551553136-04:00" level=info msg="Docker daemon" commit=363e9a8 graphdriver(s)=overlay2 version=20.10.5  Mar 24 09:55:07 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:07.551881250-04:00" level=info msg="Daemon has completed initialization"  Mar 24 09:55:07 wrrnrtm-A320M-HD2 systemd[1]: Started Docker Application Container Engine.  Mar 24 09:55:07 wrrnrtm-A320M-HD2 dockerd[1445]: time="2021-03-24T09:55:07.578162675-04:00" level=info msg="API listen on /var/run/docker.sock"  

I have no idea what I'm doing wrong. I'm using Xubuntu 18.04

Replace specific lines of a file with values of other file

Posted: 24 Mar 2021 07:30 AM PDT

I would like to replace the 2nd, 6th, and 7th rows of file1 with the values in each row of file2 and generate a series of files equal to wc -l file2

cat file1  
w  3  y  G  7  1.2  Q  
cat file2  
1        1        1  6        6        7  5        6        5  

Desired outcomes:

cat out1  
w  1  y  G  7  1  1  
cat out2  
w  6  y  G  7  6  7  
cat out3  
w  5  y  G  7  6  5  

Extracting data from multi line field value pairs

Posted: 24 Mar 2021 09:37 AM PDT

I have a file containing file value pairs in multiple lines.

Line: 1 Field name1: Value1 Field name2: Value2 Field name3: Value3    Line: 2 Field name1: Value1 Field name2: Value2 Field name3: Value3   Line: 3 Field name1: Value1 Field name2: Value2 Field name3: Value3   Line: 4 Field name1: Value1 Field name2: Value2 Field name3: Value3   ...  

I need to create a table as:

Line Field name1 Field name2 Field name3  1 Value1 Value2 Value3  2 Value1 Value2 Value3  3 Value1 Value2 Value3  4 Value1 Value2 Value3  

How do I do it using awk or sed?

I tried formulating the following command based on answers on Stackexchange but failed to get the desired output.

echo "field: 1 value: 3" | sed 's/field:[0-9].*value:[0-9].*/\1 \2/'  

I am getting an error: sed: -e expression #1, char 35: invalid reference \2 on s' command's RHS

Edit 1: The separator is a tab or space. And the format is just as shown above.

Execute a command after some time if no input from user

Posted: 24 Mar 2021 09:53 AM PDT

For zsh, see the EDIT section in the accepted answer


Let's say I have the following in my ~/.bash_aliases to ask for confirmation before suspending the system:

function suspend()  { #      echo "Please confirm/cancel system suspension:"      select confirmation in "confirm" "cancel"; do          case ${confirmation} in          confirm )              echo "System suspending..."              systemctl suspend              break;;          cancel )              echo "Canceled suspension."              break;;          esac      done  }  

I would like systemctl suspend to be still executed if no answer is given by the user. For example, after 10 seconds without user input, the content of the "confirm" case would be executed.

I tried the following, with a backgrounded sleep in a subshell:

function suspend()  { #      flag_cancel=0      echo "Please confirm/cancel system suspension:"      (      sleep 10 &&          if [ $flag_cancel -eq 0 ]; then          echo "System suspending..."          systemctl suspend          fi &      )      select confirmation in "confirm" "cancel"; do      case ${confirmation} in          confirm )          echo "System suspending..."          systemctl suspend          break;;          cancel )          flag_cancel=1          echo "Canceled suspension."          break;;      esac      done  }  

but a change of the value of flag_cancel is not taken into account, so the command is always executed after the sleep.

How to achieve what I want?

How to make TeamViewer service be on-demand rather than always-on?

Posted: 24 Mar 2021 07:16 AM PDT

I am on Linux Mint 19.3 and would like to make the TeamViewer systemd service only run when I launch the GUI app (/opt/teamviewer/tv_bin/script/teamviewer). On Windows, this is fairly easy to do from the Services dialog by selecting the TeamViewer and changing its "Startup Type" from "Automatic" to "Manual".

In Linux, I have TeamViewer 15 (installed via deb file from official site). I am seeing that the systemd service file has:

$ cat /etc/systemd/system/teamviewerd.service  [Unit]  Description = TeamViewer remote control daemon  After = network.target network-online.target dbus.service  Wants = network-online.target  Requires = dbus.service    [Service]  Type = forking  PIDFile = /var/run/teamviewerd.pid  ExecStart = /opt/teamviewer/tv_bin/teamviewerd -d  Restart = on-abort  StartLimitInterval = 60  StartLimitBurst = 10    [Install]  WantedBy = multi-user.target  

and the service autostarts during login which I don't want. I don't mind hacking out a new bash script to start the service just before launching the gui but I'm not great with editing systemd services and had a concern about new versions overwriting my changes.

Questions:

  1. I could probably just remove the service file and use a bash wrapper script just before/after the gui process starts/ends vs just launching its 'ExecStart' args directly. BUT... seems like this could be bad if the gui process were to interface with the service process using systemd calls... If I were going to keep the systemd service file around for better compat, is there a way to configure the service file to still have the service enabled but NOT to run on startup but still allow it to be manually controlled via sudo systemctl [start|stop] teamviewerd ?

  2. Is there a way in apt to specify a post-install script for a particular package. (e.g. when apt etc installs a new version of teamviewer which presumably reinstalls the systemd service and *.desktop files, I would like to have it automatically run a script to "fix" those things). I saw this and this and get that I would need something like /etc/apt/apt.conf.d/custom-hooks with a path to a script but not seeing how to: a) pass a list of last installed packages or b) find out which packages were just installed by apt. Is there a more elegant way to do things than capturing a list in the PRE hook and then recapturing and checking for changes in the POST hook?

  3. Is there a more elegant approach that I have not considered?

Tap-to-Click is Shown, but Can't Be Toggled

Posted: 24 Mar 2021 07:18 AM PDT

The touchpad on my laptop is a poor design, because it doesn't recede down into its housing to avoid my thenar and hypothenar's proclivity for inadvertent tap-to-clicks.

In Ubuntu 19.10, using this same laptop, I was able to toggle off "Tap to Click", as shown here.

However, in Kubuntu 20.04, this option is grayed out (disabled), and cannot be Toggled:

enter image description here

Is there another way that I might disable Tap-to-Click, given that the GUI isn't offering the ability to toggle this setting?

How to remove/uninstall Apache Netbeans if there is no uninstall.sh?

Posted: 24 Mar 2021 07:54 AM PDT

Some time ago I installed Apache Netbeans on my Linux Mint laptop, but since there are no official installers for the LTS version, I downloaded the binaries and unzipped the archive they were in.

Since I was using the binaries-version and it was not installed with any installer or through software center, can I just delete the Netbeans folder in my User directory (and other files/directories associated with Netbeans)?

There is no uninstall.sh anywhere.

How to configure dnsmasq on Mint-18 with NetworkManager?

Posted: 24 Mar 2021 10:05 AM PDT

I am learning linux networking. I am very confused by the config file locations. What I read on the web doesn't match how my machine is set up.

I am using Mint 18. I am using network-manager & dnsmasq.

On the dnsmasq setup page, they mention that dnsmasq can be configured in /etc/dnsmasq.conf. I do not have this file...

However there is a /etc/dnsmasq.d/network-manager and there is also /etc/NetworkManager/dnsmasq.d/

I think (alhtough I do not know), that /etc/NetworkManager/dnsmasq.d is where I should place my config file. Is this to do with NetworkManager's plugins?

If so what is /etc/dnsmasq.d? Should I put my config file here?

how to repair uefi boot option

Posted: 24 Mar 2021 08:07 AM PDT

I somehow erased all the boot options in my bios (maybe caused by some operation using super-grub disk). I have tried to fix my grub using boot-repair live-usb. After performing recommended repair and reboot, there is still no boot option in the bios, and I'm brought to the bios setup screen itself everytime I boot.

Complete information about my setup is here.

The whole story started when I found my windows cannot boot (BCD broken error). Then I thought it was a grub issue so I used boot-repair in my linux and performed the recommended repair. Then I found I cannot get into my linux either, only left with a grub> prompt. So I tried super-grub disk and super-grub2 disk live. Then I found I've basically erased all my boot-options in the bios/uefi. Now I've installed another linux (kubuntu) in hope that the new installation could fix the grub, but it didn't. So I finally tried boot-repair live usb and performed the recommended repair, but still no luck. Any idea how to fix this?

NixOS: How do I change my group and clean up the bad configurations?

Posted: 24 Mar 2021 09:03 AM PDT

This is my current users expression

   users.users = {       john = {         name = "john";         group = "users";         extraGroups = [           "wheel" "disk" "audio" "video" "networkmanager" "systemd-journal"         ];         isNormalUser = true;         uid = 1000;         home = "/home/john";         createHome = true;       };     };  

My problem is that group = "users"; allows all users to see my files. How can I make the group = "john"; and clean up permissions on all of my files in the home directory? Is it possible to do this in my configuration.nix file? Also would restarting in one of these bad configurations mess up permissions again? How do I remove these old configurations so they cannot be accessed?

Prefix and suffix strings to each output line from command

Posted: 24 Mar 2021 10:06 AM PDT

I have ran into a problem trying to write a Bash script. When grep outputs, it returns (usually) many lines. I would like to prefix and suffix a string to each of these output lines.

I would also like to note that I'm piping ls into grep, like:

ls | grep  

How can I test the encoding of a text file... Is it valid, and what is it?

Posted: 24 Mar 2021 08:56 AM PDT

I have several .htm files which open in Gedit without any warning/error, but when I open these same files in Jedit, it warns me of invalid UTF-8 encoding...

The HTML meta tag states "charset=ISO-8859-1". Jedit allows a List of fallback encodings and a List of encoding auto-detectors (currently "BOM XML-PI"), so my immediate problem has been resolved. But this got me thinking about: What if the meta data wasn't there?

When the encoding information is just not available, is there a CLI program which can make a "best-guess" of which encodings may apply?

And, although it is a slightly different issue; is there a CLI program which tests the validity of a known encoding?

No comments:

Post a Comment