Saturday, July 10, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Can it possibly work if I assign two shells to SHELL in cron?

Posted: 10 Jul 2021 10:37 AM PDT

Recently I started the process of gradual switching my shell to nu and because of it I thought about assigning its path to SHELL in cron.

Having read a good part of the manual at man 5 crontab, I took a look at PATH and copied the convention of using : in between the values attempting to assign two shells to SHELL:

SHELL=/bin/bash:/home/jerzy/.cargo/bin/nu  

It does not work, the scripts from my crontab are not doing their job. Whereas either SHELL=/bin/bash and SHELL=/home/jerzy/.cargo/bin/nu works fine.

Can I assign two shells to SHELL? Does it even make sense to do so?

Execute command and output stdout when specific file is read

Posted: 10 Jul 2021 10:29 AM PDT

I want a file to contain the output of a command whenever it is read. For example, when I read (or copy) ~/.programlist/pacman.txt the file should contain the stdout of pacman -Qe.

This may not be possible, but considering the unix philosophy of "Everything is a file", and considering the fact that anything from the raw bytes of a partition to the process list a file, would there be any way to achieve this (on Linux specifically)?

I could obviously run a cron job every hour that automatically updates the file, or mess around with pacman config options or compile pacman with my own modifications, but those implementations would be tedious and not that elegant. Any ideas?

Snap in Pamac CLI

Posted: 10 Jul 2021 10:30 AM PDT

is it possible to manage snap packages on the cli with pamac, such as running pamac search wickr for example. I see them in the GUI, and can also list them with snap, but I was hoping for a one size fits all cli.

Strange uncontrollable scrolling

Posted: 10 Jul 2021 09:08 AM PDT

I woke up this morning to this strangeness. It was not doing this when I left my computer yesterday.

I first noticed it when my tmux key bindings did not work. My prefix is Ctrl+Space. Then I noticed when my mouse went over my browser tabs they continuously scrolled to the right. Then I noticed terminal always scrolled to the bottom. But not inside my vim sessions, and only inside tmux. Then I also noticed that any browser frame which contains text wider than the frame and has a horizontal scroll bar, it will scroll to the right. Also holding my Ctrl key inside my browser continuously zooms it out.

What I have done to troubleshoot:

  • updated all my packages and rebooted
  • different mouse and keyboards
  • cleaned my mouse thoroughly including the sensor on the bottom making sure it wasn't a hair
  • this happens when my keyboard is completely unplugged
  • I'm able to navigate my mouse from my keyboard, so I turned off my mouse and tested with my keyboard only

If it happens without my mouse on, and without my keyboard plugged in, it has to be outside the devices I would think

  • Computer: Dell 13 XPS
  • OS: Arch Linux
  • Desktop Environment: None
  • Window Manager: AwesomeWM
  • Keyboard: Ergodox EZ
  • Mouse: J-Tech Digital

My question is, how can I troubleshoot this? Is there a way to see some unknown key strokes happening? Or a stuck mouse wheel command?

Recover Windows from Grub Rescue - No partition active

Posted: 10 Jul 2021 08:28 AM PDT

I had a dual boot Windows and Ubuntu. I wanted to get rid of the Ubuntu. So during the clean-up process I ended up with Grub-resuce (I deleted the linux partitions from my Windows).

I only have a bootable Ubuntu USB. I followed this link to fix the Grub rescue - https://unix.stackexchange.com/a/71634/53123

However, now I am getting "No partition active"

How can I fix this and recover my Windows without losing the data?

Debian 8.0 Not working after installation in vm

Posted: 10 Jul 2021 08:03 AM PDT

I installed Debian 8.0 recently in vmware workstation 16. When Debian boots up after instalation I see the following picture: Boot Failure.

I know this version of Debian was made in 2015, but I really want to use it. Please help! (It does the same thing in live cd mode.)

How do I set-up a PKI certificate-based SSH login in a REHL8 Virtual Machines

Posted: 10 Jul 2021 07:03 AM PDT

Do I need 3 virtual machines to do so? One for CA, Client and server?

Is there a full and complete guide for doing so? It seems like every article insist on having some sort of requite knowledge. Thank you!

Get all directories with only one specific file inside

Posted: 10 Jul 2021 06:11 AM PDT

I have a series of directories on a remote server (D1, D2, D3,...) and each directory contains multiple files (f1, f2, f3) with the same names.

What I have on the remote Server:
D1: f1, f2, f3
D2: f1, f2, f3
D3: f1, f2, f3
.
.
.

What I want on the local machine:
D1: f1
D2: f1
D3: f1
.
.
.

I need to get all directories with only f1 inside (D1/f1, D2/f1, D3/f1,...). I know SFTP doesn't support regular expressions but is there an alternative way to do that? If that's not possible in SFTP, is there a way to do it using scp or rsync?

i cant grep tmux ls output when no server is running

Posted: 10 Jul 2021 05:12 AM PDT

what im trying to achieve:

  • display in zsh prompt when tmux server is running, even if i am attached to a session or not

when tmux server is alive

> tmux ls  0: 1 windows (created Sat Jul 10 13:47:36 2021) (attached)  

so i can grep that output, correct?

grepping that output:

> tmux ls | grep -i "windows"  0: 1 windows (created Sat Jul 10 13:47:36 2021)  

windows is colored in red (for me), or whatever color you have in your terminal. anyway the command worked.

i chose windows because the word will appear always in the tmux ls output

good. now checking if the server is offline

first i need to kill the server:

tmux kill-server  

easy

now check if server is alive using tmux ls

> tmux ls  no server running on /tmp/tmux-1000/default  

normal output, as expected

but

if i want to grep that output when server is dead, check this strange thing out:

> tmux ls | grep -i "windows"  no server running on /tmp/tmux-1000/default  

exit code of this command:

> echo $?  1  

meaning that grep failed to grab the output.

another testcase of thing strangeness

> tmux ls > file.txt  no server running on /tmp/tmux-1000/default  

its always priting no server ... bla bla on the screen, no matter what you run.

when catting the file:

> cat file.txt    

nothing there

i need to find a way to check if server is running or not in order to update my zsh prompt with that information

NOTE: variable $TMUX is useless for me, because i dont want to know if im in a session while already being in a session, that is pointless. I want to know if the server is alive or dead, no matter if im attached to a session or not.

any help guys?

thanks in advance.

What's the difference between GNOME, KDE, and XFCE? [closed]

Posted: 10 Jul 2021 09:42 AM PDT

What's the difference between GNOME, KDE, and XFCE? I know KDE's lighter than GNOME, but I don't know what XFCE has to offer.

I am most concerned about performance, as in speed, but a few features would be nice as well. I'm on Ubuntu 21.04, with a Intel Core i3 4020y - not great :|

Thanks!

How to redirect the output of a pipe to >/dev/null

Posted: 10 Jul 2021 05:18 AM PDT

I would like to redirect the STDOUT and STDERR of the whole pipe to /dev/null.

Considering this is my command:

sudo lsof -i:22000 -t | xargs kill -9  

I know this is the wrong way of doing it:

sudo lsof -i:22000 -t | xargs kill -9 >/dev/null 2>&1  

How can we achieve that since simply adding >/dev/null 2>&1 will not have any effect in the pipe as it will be interpreted as part of the STDIN of xargs kill -9?

Service hosted as daemon unreachable

Posted: 10 Jul 2021 05:14 AM PDT

I recently hosted an API as a daemon service but I am unable to curl to http://localhost:9001, as this returns 404 Not Found. The API has different internal levels but even navigating to those show the same error eg. api/route/apples How can I get the hosted site to return the data I am expecting. I run a Nginx reverse proxy in order to pass through from public_ip to the internal_port of the running application. Trying to run the application manually still fails to redirect the requests to the internal_port.

Below is the entire nginx config file I created for this particular API. So internally when I check the systemctl for the status of the service I created, I see it says running and at http://[::]:5000. The API was made in dotnetcore and stored in the /var/www/api/test/ directory, firewall temporarily disabled. I tried navigating using the browser and I get a 404 error trying to reach 111.111.111.111/api/. I was expecting the proxy pass to route traffic through to the http://localhost:5000 application.

 server {  listen        80;  listen        443;  server_name   111.111.111.111;    location /api/ {     proxy_pass         http://127.0.0.1:5000;     try_files $uri $uri/ =404;    }  

Prevent the second command from starting in the bash pipe if the first command fails

Posted: 10 Jul 2021 06:39 AM PDT

After learning (more or less) some useful discussions about pipes like Get exit status of process that's piped to another and Exit when one process in pipe fails I still can't avoid starting the second command when the first command fails. Am I missing a fundamental detail about pipes?

So for example

$ somecommand | tar -T - -czf /tmp/someProject.tar.gz  

shouldn't create the almost empty tar.gz file if somecommand didn't work properly and produced just a few error messages instead of the expected file list.

VM boots with wrong keyboard layout

Posted: 10 Jul 2021 07:31 AM PDT

Question edited, please keep in mind when reading the comments below.

I use VMware Workstation Player to run my Linux VMs. Starting from the boot and during GRUB menu, LUKS password entry, and initial user login screen, the keyboard appears to be set to US. This is source of errors when entering passwords as I have a French Swiss keyboard (QWERTZ). The system uses the correct keyboard layout (CH-FR) only after the user has logged in.

How can I set the correct keyboard locale on a CentOS 8 Stream VM so that it is applied since the boot?

This is the output of localectl:

System Locale: LANG=en_US.UTF-8      VC Keymap: ch-fr     X11 Layout: us      X11 Model: pc105+inet    X11 Options: terminate:ctrl_alt_bksp  

I found this answer for Ubuntu, but it references a UEFI system. My VM uses BIOS. Is there a way to do so that does not require UEFI?

BREW ERROR : compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask

Posted: 10 Jul 2021 05:22 AM PDT

I recently got this error:

compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask  

I didn't install anything new. I just updated the brew using "brew update" command. The next time I updated the terminal my Oh-My-Zsh theme was gone. So I checked the ZSH_THEME variable and it was properly set. I restarted my MacBook and found that my theme came back to normal but I still get the same compinit error whenever I try to run the source command.

I uninstalled and reinstalled Homebrew but still the same problem. What should I do?


UPDATE(Solved):

I found out that it was an issue with the symlinks.

I used the following command brew cleanup and the problem was solved.

cannot open '/home/user/original/AndroidManifest.xml' for reading: No such file or directory

Posted: 10 Jul 2021 08:49 AM PDT

I've been trying to use evil-droid to backdoor an apk. But it showed me this error.

] Adding permission and Hook Smali  [ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ]  head: cannot open '/home/user/original/AndroidManifest.xml' for reading: No such file or directory  head: cannot open '/home/user/original/AndroidManifest.xml' for reading: No such file or directory  sed: can't read /home/user/original/AndroidManifest.xml: No such file or directory  rm: cannot remove '/home/user/payload/smali/com/metasploit/stage/MainActivity.smali': No such file or directory  sed: can't read /home/user/payload/smali/com/metasploit/stage/.smali: No such file or directory  grep: /home/user/original/AndroidManifest.xml: No such file or directory  grep: /home/user/original/AndroidManifest.xml: No such file or directory  sed: can't read /home/user/payload/smali/com/metasploit/stage/*.smali: No such file or directory  sed: can't read /home/user/original/AndroidManifest.xml: No such file or directory  sed: can't read /home/user/original/AndroidManifest.xml: No such file or directory  grep: /home/user/original/AndroidManifest.xml: No such file or directory  grep: android.intent.category.LAUNCHER: invalid context length argument  grep: android.intent.action.MAIN: invalid context length argument  grep: android.intent.action.MAIN: invalid context length argument  grep: android.intent.category.LAUNCHER: invalid context length argument  grep: android.intent.action.MAIN: invalid context length argument  grep: android.intent.category.LAUNCHER: invalid context length argument  

Please someone help me!! I've been searching for a solution for hours now!!

How do i get python to tail a logfile? Tried various methods

Posted: 10 Jul 2021 06:01 AM PDT

I'm trying to get python to tail a logfile e.g. syslog.

I've tried opening the file in read mode, but it never realises if another process writes to the file. Using a popen, and actual 'tail -f' together with registering the popened process to select, python is able to read any writes. And using the python systemd module, i can get systemd to respond with the contents, but I'd like to know if there are other ways instead of these methods and, why the opening a file for reading and constantly trying to read 1024 bytes, doesn't work.

How do I stop memory issue caused by baloo_file_extractor?

Posted: 10 Jul 2021 06:29 AM PDT

I using Arch Linux with XFCE/XFWM4. The default FM is very lightweight thunar, but I installed dolphin for some more functionality.

I was studying about large files and creating some 2 gigs of files on my system. I suddenly saw my system is going wild where baloo_file_extractor uses 3.1 GiB RAM! I suddenly killed it.

But every time I create a big file, I see baloo_file_extractor uses up all of my RAM and start consuming swap again and again.

On the other hand, I haven't used dolphin for weeks now. Why does it daemonize baloo when dolphin is not in use?

Apart from uninstalling baloo, baloo_widgets and dolphin file manager, is there any other way to prevent that from happening again?

How to pin a package in dnf (Fedora)

Posted: 10 Jul 2021 08:53 AM PDT

I've got a temporary situation where I'm working with pre-release F27, and need to keep one package to a specific (working) version and not be upgraded until the subsequent versions stop breaking something. I know in general "you don't really want to do this", but as I said, it's a temporary dealing with a pre-rel system. You can "pin" packages with the apt system, but I can't locate anything equivalent for dnf.

Problem with phpmyadmin

Posted: 10 Jul 2021 05:06 AM PDT

When I type localhost/phpmyadmin, it shows "The localhost page isn't working localhost is currently unable to handle this request. HTTP ERROR 500". Please help! Apache error log is:

[Tue Jun 14 16:35:47.699632 2016] [:error] [pid 14660] [client 192.168.0.101:44854] PHP Fatal error:  require_once(): Failed opening required '/usr/share/php/php-gettext/gettext.inc' (include_path='.:/usr/share/php') in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 477

Force linker to find stdc++ library in non-standard directory

Posted: 10 Jul 2021 07:02 AM PDT

I've read a lot of guidance that says the LD_LIBRARY_PATH is searched before anything else, but one of my .so libraries is linking with libtdc++.so.6 in /usr/lib64.

ldd mylib.so:  ...  libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f82abd18000)  ...  

I want mylib.so to link with libstdc++.so.6 in another location, like /apps/gcc_4.8.0/lib/libstdc++.so.6

So I add /apps/gcc_4.8.0/lib to LD_LIBRARY_PATH, which does not have /usr/lib64 in it, but it still doesn't find it there.

If I add:

setenv LD_PRELOAD /apps/gcc_4.8.0/lib/libstdc++.so.6  

to my environment, there are no more linker errors. Yay, but that doesn't solve the problem. Users downstream aren't going to want to depend on this library being in the proper place. WHY ISN"T LD_LIBRARY_PATH BEING SEARCHED FIRST!?!

Understanding network problem (syslog)

Posted: 10 Jul 2021 08:02 AM PDT

I am running a lubuntu 14.04 server and its always worked well, except for the last couple of days it keeps dropping off the LAN. I am using a couple of powerlink adapters to connect it up as WiFi was never very solid on it.

Anyway, I plugged a screen and mouse/keyboard into it to try to work out whats up with it, and I tailed the syslog. Here is an excerpt: http://pastebin.com/4ftXsai4

Can someone please give me any clues to what might the problem be? Or any tips on how to track down the issue.

I have unplugged the Ethernet cable from my router and rebooted it all, to no avail.

EDIT #1

I'm not sure what happened. But the server has been up, connected all day today. I am tailing a log file via a remote SSH connection and its not disconnected once.

Could have been that the WiFi card was playing up, or the router was struggling to assign DHCP, although, if it was a DHCP problem, why would it keep disconnecting?

Convert video to exactly the same format as another video

Posted: 10 Jul 2021 09:07 AM PDT

Suppose I have two video files A and B.

Now I want to convert A to the same format (i.e. same container, same audio and video codec), same bitrate, size etc. as B.

Is there a way to do this automatically (i.e. without extracting the information manually and giving it manually as input parameters) using a command line tool (or even a GUI tool)?

Why not use "which"? What to use then?

Posted: 10 Jul 2021 06:07 AM PDT

When looking for the path to an executable or checking what would happen if you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, whereis, whatis, hash, etc).

We often hear that which should be avoided. Why? What should we use instead?

Text to yaml conversion

Posted: 10 Jul 2021 09:17 AM PDT

I have a tab separated text file in this format:

your-email  your-order-id   PayPal-transaction-id   your-first-name your-second-name  s@ess.com   12345   54321   sooky   spooky  t@tee.com   23456   23456   kiki    dee  r@arrgh.com 34567   76543   cheeky  chappy  

and I'd like to use awk to convert this to yaml:

---    your-email: s@ess.com  your-order-id: 12345  PayPal-transaction-id: 54321  your-first-name: sooky  your-second-name: spooky    your-email: t@tee.com  your-order-id: 23456  PayPal-transaction-id: 23456  your-first-name: kiki  your-second-name: dee    your-email: r@arrgh.com  your-order-id: 34567  PayPal-transaction-id: 76543  your-first-name: cheeky  your-second-name: chappy  

So far my awk script looks like this

#!/usr/bin/awk  FS=="\t"  BEGIN {print "---"}   NR==1 {for (i=1;i<=NF;i++) print $i ": "}  

But I can't figure out how to get each field from line 1 onwards to print after it's header and then recreate the yaml key values from the first line of the input file. In the real file there are 38 fields and 34 records (so not huge).

XML parsing using xmllint and customizing the output

Posted: 10 Jul 2021 09:59 AM PDT

I have xml file (say input.xml) of the following schema:

<?xml version="1.0"?>    <TagA>      <TagB>        <File Folder="FOLDER1M\1" File="R1.txt" />      </TagB>      <TagB>        <File Folder="FOLDER1M\2" File="R2.txt" />      </TagB>      <TagB>        <File Folder="FOLDER2M\1" File="R3.txt" />      </TagB>    </TagA>  

I need to parse this file and write the output to another file. The required output should be of the following form:

www.xyz.com\FOLDER1M\1\R1.txt  www.xyz.com\FOLDER1M\2\R2.txt  www.xyz.com\FOLDER2M\1\R3.txt  

What I have got so far is:

echo 'cat /TagA/TagB/File/@*[name()="Folder" or name()="File"]' | xmllint --shell input.xml | grep '=' > xml_parsed  

This gives me o/p of the form:

/ > cat /TagA/TagB/File/@*[name()="Folder" or name()="File"]  Folder="FOLDER1M\1"  File="R1.txt"  Folder="FOLDER1M\2"  File="R2.txt"  Folder="FOLDER2M\3"  File="R3.txt"  

How should I go about getting my required output instead of this current o/p?

How to delete a line containing pattern which is first found after a specific pattern

Posted: 10 Jul 2021 10:03 AM PDT

I am writting a shell script to delete an entry from a specific group. eg: file name is dest.xml

<domain id="1" group_name="group1">      <node id="ABC">      <node id="PQR">      <node id="XYZ">  </domain>  <domain id="2" group_name="group2">      <node id="PQR">      <node id="XYZ">  </domain>  <domain id="3" group_name="group3">      <node id="ABC">      <node id="PQR">   </domain>  

I want to delete an entry from above file (filename is dest.xml) with node id="PQR" from group_name="group1" (it should not get deleted from group2 and group3). I can do it by reading a file sequentially n then delete it from a specific group. But if the file is to large (>10k lines) then it takes time.

Is there any simple way to this this?

how to compare two xml files having same data in different lines?

Posted: 10 Jul 2021 10:23 AM PDT

I have two files have same data but in different lines.

File 1:

<Identities>      <Identity>          <Id>048206031415072010Comcast.USR8JR</Id>          <UID>ccp_test_79</UID>          <DisplayName>JOSH CCP</DisplayName>          <FirstName>JOSH</FirstName>          <LastName>CCP</LastName>          <Role>P</Role>          <LoginStatus>C</LoginStatus>      </Identity>      <Identity>          <Id>089612381523032011Comcast.USR1JR</Id>          <UID>94701_account1</UID>          <DisplayName>account1</DisplayName>          <FirstName>account1</FirstName>          <LastName>94701</LastName>          <Role>S</Role>          <LoginStatus>C</LoginStatus>      </Identity>  </Identities>  

File 2 :

<Identities>      <Identity>          <Id>089612381523032011Comcast.USR1JR</Id>          <UID>94701_account1</UID>          <DisplayName>account1</DisplayName>          <FirstName>account1</FirstName>          <LastName>94701</LastName>          <Role>S</Role>          <LoginStatus>C</LoginStatus>      </Identity>      <Identity>          <Id>048206031415072010Comcast.USR8JR</Id>          <UID>ccp_test_79</UID>          <DisplayName>JOSH CCP</DisplayName>          <FirstName>JOSH</FirstName>          <LastName>CCP</LastName>          <Role>P</Role>          <LoginStatus>C</LoginStatus>      </Identity>  </Identities>  

If I use diff file1 file2 command I am getting below response:

1,10d0  <     <Identities>  <         <Identity>  <             <Id>048206031415072010Comcast.USR8JR</Id>  <             <UID>ccp_test_79</UID>  <             <DisplayName>JOSH CCP</DisplayName>  <             <FirstName>JOSH</FirstName>  <             <LastName>CCP</LastName>  <             <Role>P</Role>  <             <LoginStatus>C</LoginStatus>  <         </Identity>  20a11,20  >     <Identities>  >         <Identity>  >             <Id>048206031415072010Comcast.USR8JR</Id>  >             <UID>ccp_test_79</UID>  >             <DisplayName>JOSH CCP</DisplayName>  >             <FirstName>JOSH</FirstName>  >             <LastName>CCP</LastName>  >             <Role>P</Role>  >             <LoginStatus>C</LoginStatus>  >         </Identity>  

But I need to get no difference, because these files having same data in different lines.

No comments:

Post a Comment