Tuesday, August 24, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


How to install a certificate to sign files in CentOS?

Posted: 24 Aug 2021 09:55 AM PDT

I have a .pfx certificate with which I want to sign XML files in a java application. This application will then send the signed XML files to an external server.

I have investigated the directories of my CentOS server and I have seen that the /etc/pki/ path contains certificates directories but I don't know how to proceed (I have never worked with certificates before).

How do I install the certificate?

Thanks in advance

I can't see my hard disk in CentOs. How can I solve this?

Posted: 24 Aug 2021 09:50 AM PDT

I have the main disk with Windows 7 and I installed CentOs in a flash USB but I want to delete data of main hard disk from Linux CentOs and make storage disk for store backups, I want to do something like that NSA server.

My problem is that I can´t see the main hard disk in Linux, I don't know solve this. I tried with many commands, although it's not work.

Thanks guys !

How to set 'No proxy' on Linux

Posted: 24 Aug 2021 10:19 AM PDT

I can access internet by setting 'No proxy' on Windows:

How can I do the same setting on Linux server?

How to edit /etc/printcap?

Posted: 24 Aug 2021 09:09 AM PDT

We recently changed domain and host name on a RHEL8 server from old.domain.name to more.better.name.

I happened to notice a reference in /etc/printcap to old.domain.name.

[user@box ~]# cat /etc/printcap   # This file was automatically generated by cupsd(8) from the  # /etc/cups/printers.conf file.  All changes to this file  # will be lost.  office_printer_123|office_printer_123:rm=old.domain.name:rp=office_printer_123:  [user@box ~]#   

Correct hostname shows

[user@box ~]# hostname  more.better.name  [user@box ~]#   

The server has been restarted a few times since changing the hostname.

I found zero other references to old.domain.name with

[user@box ~]# grep -r "old.domain.name" /etc/  [user@box ~]#   

old.domain.name is not found in /etc/cups/printer.conf

[user@box]# cat /etc/cups/printers.conf  # Printer configuration file for CUPS v2.2.6  # Written by cupsd on 2021-08-24 10:01  # DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING  <Printer office_printer_123>  UUID urn:uuid:e74ed8e4-e5e6-30b9-64b9-2283cc9c93e7  AuthInfoRequired none  Info office_printer_123  MakeModel HP LaserJet 600 M601 M602 M603 Postscript (recommended)  DeviceURI ipp://111.222.111.222  State Idle  StateTime 1629813648  ConfigTime 1618257051  Type 8425668  Accepting Yes  Shared Yes  JobSheets none none  QuotaPeriod 0  PageLimit 0  KLimit 0  OpPolicy default  ErrorPolicy stop-printer  </Printer>  [user@box]#   

How do I change what's in the printcap file? And where could it be pulling old.domain.name?

how to use sed to replace a string in double quoted with a variable?

Posted: 24 Aug 2021 09:59 AM PDT

the file include this line:

  master_green_cloud_init_version = "v1.16/"  

My bash script will get a parameter like userdata_version=v2.21, how to use sed to replace anything between "" ("v1.16/") with $userdata_version? Cannot hard coded v1.16 as it is keeping on changing.

Why is /etc/fstab preferred over systemd unit files?

Posted: 24 Aug 2021 08:33 AM PDT

The systemd.mount(5) man page says (emphasis mine):

Mount units may either be configured via unit files, or via /etc/fstab (see fstab(5) for details). Mounts listed in /etc/fstab will be converted into native units dynamically at boot and when the configuration of the system manager is reloaded. In general, configuring mount points through /etc/fstab is the preferred approach.

Why is /etc/fstab preferred in this case? To my knowledge systemd has replaced the pre-existing configuration methods in many places. Are there downsides to using .mount unit files?

Split several Unix files into multiple files based on first column

Posted: 24 Aug 2021 08:18 AM PDT

I have several files (*data.txt) and I am trying to split each of them into multiple files based on the content of column 1. I have managed to split them but I do not know how to name the output files with both $filename and column 1($1) using print. At the moment print in the following command gives me $1 ".txt", so for example: ENSG00000108094.txt, ENSG00000115232.txt instead of file1_ENSG00000108094.txt, file1_ENSG00000115232.txt which is not suitable as I need to have separate outputs for each input file. Here it is my command and I am not sure where I should use "$b" to get the expected outcome.

for filename in *_data.txt   do      b=${filename%%_data.txt}  cat $filename | awk 'NR==1 {header = $0; next}!header_printed[$1]++ {print header > $1".txt"}{print > $1".txt"}'  done  

Thanks.

Why am I able to SSH a remote machine even with the wrong keys?

Posted: 24 Aug 2021 07:47 AM PDT

Description: I have created a ssh connection between my Windows Pc and Raspberry Pi. To so I followed the following steps:

Step 1: Somehow get the IP address of the Raspberry Pi. It should be something like this: 192.168.1.52

Step 2: Open a shell and access the Raspberry Pi via ssh:

ssh pi@192.168.1.52  

You will need the password.

Step 3: In the home directory of the remote pc use these commands:

mkdir .ssh  

Step 4: Secure the ssh connection via private/public key. In the local pc use this commands:

ssh-keygen -f .ssh/fede_windows -t rsa -b 4096  

If your local machine is Linux based run this line:

chmod 600 .ssh/fede_windows # if linux  

Finally:

scp .ssh/fede_windows.pub pi@192.168.1.52:.ssh  

Step 5: In the remote pc use these commands:

sudo nano /etc/ssh/sshd_config  

and modify the following lines of the config file:

ChallengeResponseAuthentication no  PasswordAuthentication no  UsePAM no  

Finally:

sudo systemctl reload sshd  

Step 6: In the remote computer use these commands:

cat ~/.ssh/fede_windows.pub >> ~/.ssh/authorized_keys  chmod 700 ~/.ssh/  chmod 600 ~/.ssh/*  

Step 7: In the local computer run this command to log in to the remote one:

ssh -i .ssh/fede_windows pi@192.168.1.52  

Problem: When I perform all these steps again in my Ubuntu Pc by generating this time a key named fede_ubuntu, it looks like that I am able to ssh my Raspberry Pi no matter what I insert in the command:

ssh -i .ssh/fede_xyz pi@192.168.1.52  

It works all the time and this is not supposed to happen since it should be restricted only to the key I just created. If I switch to my Windows machine everything works as expected and only if I specify the right key works.

Question: Would you be able to suggest a possible reason of this issue and how to fix it please?

EDIT: By typing the following command ssh -i .ssh/key_that_does_not_exits -v pi@192.168.1.52 I get:

Warning: Identity file .ssh/key_that_does_not_exits not accessible: No such file or directory.  OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f  31 Mar 2020  debug1: Reading configuration data /etc/ssh/ssh_config  debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files  debug1: /etc/ssh/ssh_config line 21: Applying options for *  debug1: Connecting to 192.168.1.52 [192.168.1.52] port 22.  debug1: Connection established.  debug1: identity file /home/federico/.ssh/id_rsa type -1  debug1: identity file /home/federico/.ssh/id_rsa-cert type -1  debug1: identity file /home/federico/.ssh/id_dsa type -1  debug1: identity file /home/federico/.ssh/id_dsa-cert type -1  debug1: identity file /home/federico/.ssh/id_ecdsa type -1  debug1: identity file /home/federico/.ssh/id_ecdsa-cert type -1  debug1: identity file /home/federico/.ssh/id_ecdsa_sk type -1  debug1: identity file /home/federico/.ssh/id_ecdsa_sk-cert type -1  debug1: identity file /home/federico/.ssh/id_ed25519 type -1  debug1: identity file /home/federico/.ssh/id_ed25519-cert type -1  debug1: identity file /home/federico/.ssh/id_ed25519_sk type -1  debug1: identity file /home/federico/.ssh/id_ed25519_sk-cert type -1  debug1: identity file /home/federico/.ssh/id_xmss type -1  debug1: identity file /home/federico/.ssh/id_xmss-cert type -1  debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3  debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Raspbian-10+deb10u2+rpt1  debug1: match: OpenSSH_7.9p1 Raspbian-10+deb10u2+rpt1 pat OpenSSH* compat 0x04000000  debug1: Authenticating to 192.168.1.52:22 as 'pi'  debug1: SSH2_MSG_KEXINIT sent  debug1: SSH2_MSG_KEXINIT received  debug1: kex: algorithm: curve25519-sha256  debug1: kex: host key algorithm: ecdsa-sha2-nistp256  debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none  debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none  debug1: expecting SSH2_MSG_KEX_ECDH_REPLY  debug1: Server host key: ecdsa-sha2-nistp256 SHA256:hC5w2kDxgHH5eFRY1vOJaS7ipPR+8OWX2tkkEZbF194  debug1: Host '192.168.1.52' is known and matches the ECDSA host key.  debug1: Found key in /home/federico/.ssh/known_hosts:1  debug1: rekey out after 134217728 blocks  debug1: SSH2_MSG_NEWKEYS sent  debug1: expecting SSH2_MSG_NEWKEYS  debug1: SSH2_MSG_NEWKEYS received  debug1: rekey in after 134217728 blocks  debug1: Will attempt key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent  debug1: Will attempt key: /home/federico/.ssh/id_rsa   debug1: Will attempt key: /home/federico/.ssh/id_dsa   debug1: Will attempt key: /home/federico/.ssh/id_ecdsa   debug1: Will attempt key: /home/federico/.ssh/id_ecdsa_sk   debug1: Will attempt key: /home/federico/.ssh/id_ed25519   debug1: Will attempt key: /home/federico/.ssh/id_ed25519_sk   debug1: Will attempt key: /home/federico/.ssh/id_xmss   debug1: SSH2_MSG_EXT_INFO received  debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>  debug1: SSH2_MSG_SERVICE_ACCEPT received  debug1: Authentications that can continue: publickey,keyboard-interactive  debug1: Next authentication method: publickey  debug1: Offering public key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent  debug1: Server accepts key: federico@federico RSA SHA256:E96Hu2Ee+IyAuoZ06GxTvo+ZmAkzqfihbAKkFqxU1AU agent  debug1: Authentication succeeded (publickey).  Authenticated to 192.168.1.52 ([192.168.1.52]:22).  debug1: channel 0: new [client-session]  debug1: Requesting no-more-sessions@openssh.com  debug1: Entering interactive session.  debug1: pledge: network  debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0  debug1: Remote: /home/pi/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding  debug1: Remote: /home/pi/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding  debug1: Sending environment.  debug1: Sending env LC_ADDRESS = it_IT.UTF-8  debug1: Sending env LC_NAME = it_IT.UTF-8  debug1: Sending env LC_MONETARY = it_IT.UTF-8  debug1: Sending env LC_PAPER = it_IT.UTF-8  debug1: Sending env LANG = en_US.UTF-8  debug1: Sending env LC_IDENTIFICATION = it_IT.UTF-8  debug1: Sending env LC_TELEPHONE = it_IT.UTF-8  debug1: Sending env LC_MEASUREMENT = it_IT.UTF-8  debug1: Sending env LC_TIME = it_IT.UTF-8  debug1: Sending env LC_NUMERIC = it_IT.UTF-8  Last login: Sun Aug 22 22:26:00 2021 from 192.168.1.197  

sshpass splitting the password as two strings seperated by the character "&" in password

Posted: 24 Aug 2021 09:23 AM PDT

I have a password variable PASS whose value is abc123&zxcv456 When I try to do SSH in jenkins using the password variable like below

sshpass -p ${PASS} ssh -o StrictHostKeyChecking=no admin@100.200.3.4 'echo '${PASS}' | sudo -S docker stats --no-stream'  

only the string before special character & is interpreted and the value of the variable PASS is read as abc123, any help to get around this?

PS I have tried using escape character "${PASS}" but no progress there .

How to remove test results during the ramping period from a CSV test result file?

Posted: 24 Aug 2021 09:19 AM PDT

I have some test results in a CSV file. The first field has the timestamp.

Here is a sample record in the CSV file:

1628689875326,327,3.1 HTTP Request /api/StaffPortal,200,OK,Concurrency Thread Group   SignIn-ThreadStarter 1-5,text,true,,73018,17,17  

I want to remove the test results during the ramp-up (5 minutes from the start time) and the ramp down period (last 5 minutes) and write the filtered test results into a CSV file.

I tried with the hardcoded values

#!/usr/bin/awk -f      BEGIN {      endTime=1628689875326      startTime=1628689875326-300*1000*1000      offset=1628689875326-3900*1000*1000        FS=","      rowCount=0    }    {        if ($1> startTime && $1<offset){          rowCount++          print $0      }    }  

Equivalent of executing a file (with shebang line) by entering its path?

Posted: 24 Aug 2021 09:58 AM PDT

Say I have a file hello:

#!/bin/sh    echo "Hello World!"  

Provided the executable bit is set on that file, I can execute it by entering its path on the prompt:

$ ./hello  Hello World!  

Is there a more explicit equivalent to the above? Something akin to:

$ execute hello  

I know I can pass hello as an argument to /bin/sh, but I'm looking for a solution that automatically uses the interpreter specified in the shebang line

My use case for this is to execute script files that do not have the executable flag set. These files are stored in a git repository, so I would like to avoid setting their executable flag or having to copy them to another location first.

zsh completion: different completion when stdin is a pipe

Posted: 24 Aug 2021 07:53 AM PDT

I have a program foo. It can be used in 2 different modes:

foo [-c] file1 [file2]  

or

find . -print0 | foo [-0] [-c]  

In first mode, the only optional argument is -c, and then there are one or more files.

In second mode, there are 2 optional arguments -c and -0, and no files.

How can I handle these 2 different modes in zsh completion?

Debian 10 desktop frozen and has a small box appear

Posted: 24 Aug 2021 07:47 AM PDT

The graphical environment on my Debian 10 system has become unusable. The last thing I did was install supervisor and then the desktop locked up and a small grey box appears.

On a restart I can move the box, which interacts with the three desktop icons. (Ie if it's moved above the icons, they move out of the way. (See images)

Desktop window

Desktop window with icons moving out of the way

As soon as I try and do anything but interact with the white box using anything but the left mouse button, the desktop locks. (Even the right mouse locks it up). Nothing is then responsive.

I can get to console using Ctrl-Alt-F1, and have killed just about every process there is, to no avail.

Somewhat new to linux, so unsure what the best way to ask for help is.

Unable to detect a failed print on a remote system using ssh

Posted: 24 Aug 2021 10:12 AM PDT

Below is my code on linux that prints a PDF on a remote MACOS system.

echo "Printing ssh -p 3335 ibrahimince@localhost 'lp -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE'";    echo "Remote File details are:"  ssh -p 3335 ibrahimince@localhost "ls -ltr $HOMEDIR/Printed/$NEWFILE"    until ssh -p 3335 ibrahimince@localhost "lp -o media=A5 -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE" >/home/system/efendibey.de/invoices/send4print/printererror.log 2>&1  do    echo "Exit Code of the command was: $?"  echo "Send email that there is an issue printing invoice for the below file. Issue is: `cat /home/system/efendibey.de/invoices/send4print/printererror.log`"  ls -ltr $FILE >>/home/system/efendibey.de/invoices/send4print/printererror.log    mail -s "PRINTER SERVICE FAIL ALERT. PLEASE CHECK YOUR PRINTER!!" mohtashim@digiklug.com < /home/system/efendibey.de/invoices/send4print/mailbody.txt  sleep 20    done    echo "Print successful. Deleting $FILE"  rm $FILE;    fi  

Here are the logs for a particular print online_delivery_10001333.pdf.

Printing ssh -p 3335 ibrahimince@localhost 'lp -d Brother_HL_L2350DW_series /Users/ibrahimince/Printed/online_delivery_10001333.pdf'  Remote File details are:  -rw-r--r--  1 ibrahimince  staff  11496 Aug  2 19:29 /Users/ibrahimince/Printed/online_delivery_10001333.pdf  Print successful. Deleting /home/system/efendibey.de/invoices/send4print/online_delivery_10001333.pdf  

The logs say that the print was successful and the return code was 0(successful).

But, the print actually failed, and below is the snapshot of the same.

Error: Gestoppt - Can't open "/private/var/spool/cups/d02183-001.

enter image description here

How can I refine my code so to make sure the print was actually successful?

Below is the lpstat -t logs:

Remote File details are:  -rw-r--r--  1 ibrahimince  staff  11507 Aug 18 20:00 /Users/ibrahimince/Printed/online_delivery_10001333.pdf  scheduler is running  system default destination: Brother_HL_L2350DW_series  device for Brother_HL_L2350DW_series: dnssd://Brother%20HL-L2350DW%20series._ipp._tcp.local./?uuid=e3248000-80ce-11db-8000-2c6fc95df52e  device for Brother_MFC_L3750CDW_series_b_3_Fax: dnssd://Brother%20MFC-L3750CDW%20series._ipp._tcp.local./?uuid=e3248000-80ce-11db-8000-3c2af4dd8a75  device for Canon_TS700_series: ippusb://Canon%20TS700%20series._ipp._tcp.local./?uuid=00000000-0000-1000-8000-00186d1376d5  device for Kyocera_ECOSYS_M5526cdw: dnssd://Kyocera%20ECOSYS%20M5526cdw._ipps._tcp.local./?uuid=4509a320-00a6-0073-00bb-002507512ad9  device for Kyocera_ECOSYS_M5526cdw_b_3_Fax: dnssd://Kyocera%20ECOSYS%20M5526cdw._ipps._tcp.local./?uuid=4509a320-00a6-0073-00bb-002507512ad9  Brother_HL_L2350DW_series accepting requests since Wed Aug 18 20:00:24 2021  Brother_MFC_L3750CDW_series_b_3_Fax accepting requests since Tue Jun 29 17:04:09 2021  Canon_TS700_series accepting requests since Wed Aug 18 18:34:42 2021  Kyocera_ECOSYS_M5526cdw accepting requests since Thu Jul  8 12:30:45 2021  Kyocera_ECOSYS_M5526cdw_b_3_Fax accepting requests since Thu Jul  8 12:28:58 2021  printer Brother_HL_L2350DW_series is idle.  enabled since Wed Aug 18 20:00:24 2021          Can't open "/private/var/spool/cups/d03050-001."  printer Brother_MFC_L3750CDW_series_b_3_Fax is idle.  enabled since Tue Jun 29 17:04:09 2021  printer Canon_TS700_series is idle.  enabled since Wed Aug 18 18:34:42 2021  printer Kyocera_ECOSYS_M5526cdw disabled since Thu Jul  8 12:30:45 2021 -          reason unknown  printer Kyocera_ECOSYS_M5526cdw_b_3_Fax is idle.  enabled since Thu Jul  8 12:28:58 2021  Brother_HL_L2350DW_series-3050 ibrahimince      12288   Wed Aug 18 20:00:24 2021  Print successful. Deleting   

Unlock GRUB bootloader password remotely

Posted: 24 Aug 2021 09:07 AM PDT

Is it possible to unlock password protected grub loader remotely? For LUKS encrypted disk, I can unlock using dropbear-initramfs package installed in Debian in which dropbear will run a custom listening port so that I can use it to unlock LUKS encrypted disk remotely. I'm wondering, if there is any solutions for grub password protected bootloader?

Fontconfig: set every font with spacing=100 as 'monospace'

Posted: 24 Aug 2021 08:29 AM PDT

Many of the fonts, including those from the package manager (currently running a Arch System) don't include the generic family as "serif", "monospace" and "cursive". So I have to indicate the correct family manually (see also https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/).

But for "monospace" fonts, there's a workaround: they all have the spacing property of 100. You can check this by running fc-list :spacing=100 (see also https://unix.stackexchange.com/a/363368/473666). So the idea is to automatically set every font with this property value as a "monospace" font.

As an example, in the default configuration files and documentation, they set every font that don't have "serif" and "monospace" as "sans-serif" this way:

  <match target="pattern">      <test qual="all" name="family" compare="not_eq">              <string>sans-serif</string>      </test>      <test qual="all" name="family" compare="not_eq">              <string>serif</string>      </test>      <test qual="all" name="family" compare="not_eq">              <string>monospace</string>      </test>      <edit name="family" mode="append_last">              <string>sans-serif</string>      </edit>    </match>  

So, I tried this:

  <match target="pattern">      <test qual="all" name="spacing" compare="eq">         <int>100</int>      </test>      <test qual="all" name="family"  compare="not_eq">         <string>monospace</string>      </test>      <edit name="family" mode="append_last">         <string>monospace</string>      </edit>    </match>  

The result: EVERY font on the system is now monospace. This also happens changing <int>100</int> for <const>mono</const>. I already read the man fonts.conf and many of the default configuration files listed in fc-conflist but I couldn't make it work. I tried multiple combinations of properties and their values, but the result always is either NONE or EVERY font is treated as monospace.

For now, I used this command to generate a list of sources and added them all manually: fc-list :spacing=100 | awk -F: '{print $2}' | sort -u. This is my first time asking something in Stack Exchange, I hope I managed to make it clear.

Why does find and exec mv not move all files?

Posted: 24 Aug 2021 09:36 AM PDT

The current working directory has multiple test files numbered between 1 to 100. These are titled 1.txt through to 100.txt.

The command find . -maxdepth 1 -regextype posix-egrep -regex '.*/[ -._&a-zA-Z0-9]+\.txt' -exec bash -c 'mv "$@" "TestDir - Level One"' {} + moves all files bar one e.g. 15.txt.

In contrast the command find . -maxdepth 1 -regextype posix-egrep -regex '.*/[ -._&a-zA-Z0-9]+\.txt' -exec mv {} "TestDir - Level One"/ \; moves all files.

If the command find . -maxdepth 1 -regextype posix-egrep -regex '.*/[ -._&a-zA-Z0-9]+\.txt' -exec bash -c 'mv "$@" "TestDir - Level One"' {} + is executed again, it returns the error mv: missing destination file operand after 'TestDir - Level One' Try 'mv --help' for more information.

The version of find is find (GNU findutils) 4.7.0-git

Does find -exec find all results up front, or will it find results added while executing on the previous results?

Posted: 24 Aug 2021 09:39 AM PDT

So if I am downloading say 5000 audio files, each 5 seconds long, and after the first 1000 download, I run:

find . -iname "*.wav" -exec play {} \;  

Will that play only the 1000 files that were present when I first ran the command, or will it play all 5000 files since the files are downloading faster than the exec finishes with them?

grub2-mkconfig not using /etc/default/grub?

Posted: 24 Aug 2021 10:16 AM PDT

I'm trying to add a kernel option "xxx" by adding it to the existing

GRUB_CMDLINE_LINUX="xxxx crashkernel=auto rhgb quiet"  

line in /etc/default/grub, but after doing so, when I run

grub2-mkconfig –o /boot/grub2/grub.cfg  

it produces exactly the same grub.cfg file as before (confirmed with diff).

What am I missing?

I'm running CentOS Linux release 7.6.1810 (Core)

Chaining find exec and a while loop

Posted: 24 Aug 2021 09:36 AM PDT

I'm trying to stack a find command so that the results it returns only contains files with "warning:" or "error:" text within them. I also require those results in a specific format so I'm using exec stat for that.

I can get a version of this to work, but I need to be able to use -exec stat within the while loop to formulate a specific string, and that -exec stat is making my shell hand me the > prompt. The part that's not working is in bold below.

Separately I can get these to work. Together I cannot.

Here's an example of one I've got working:

find . -type f -exec grep -li error: {} \; | while read -r file; do ls -l "$file"; done  

So now I'm trying to shoehorn that in with another process that limits the files to specific times, types etc. It's not going well:

find /my/directory/here/ -type f -name *.log -mmin -480 -mmin +60 -exec grep -li warning: {} \; -exec grep -li error: {} \; | while read -r file; do -exec stat -c "$file" '%n|%y|%x|%s|%U|%u' {} \; done

Note, the whole thing works if I remove the -exec stat from within the while loop. If I replace that with a simple ls -l, results are given back to me. Right now the shell is just giving me a command prompt.

I know I'm not doing this right but I have no ideas right now on what I should be resolving first.

SSH through HTTP proxy with corkscrew

Posted: 24 Aug 2021 10:06 AM PDT

I'm running into an issue connecting from a Cygwin terminal to my home Raspberry Pi with SSH from behind an HTTP proxy. It used-to-work™ and I don't know what changed since a few days ago (maybe the proxy filtering?). I can still connect from outside the proxy-ed network without corkscrew.

Client-wise, my ssh-config is as follows:

Host *          ServerAliveInterval 60          ProxyCommand /bin/corkscrew http.proxy.here 80 %h %p  

And the connection attempt gives this:

blx@proxyed-pc:~$ ssh blx@my.home.ip -v  OpenSSH_7.9p1, OpenSSL 1.0.2p  14 Aug 2018  debug1: Reading configuration data /home/blx/.ssh/config  debug1: /home/blx/.ssh/config line 1: Applying options for *  debug1: Executing proxy command: exec /bin/corkscrew http.proxy.here 80 my.home.ip 22  debug1: identity file /home/blx/.ssh/id_rsa type -1  debug1: identity file /home/blx/.ssh/id_rsa-cert type -1  debug1: identity file /home/blx/.ssh/id_dsa type -1  debug1: identity file /home/blx/.ssh/id_dsa-cert type -1  debug1: identity file /home/blx/.ssh/id_ecdsa type 2  debug1: identity file /home/blx/.ssh/id_ecdsa-cert type -1  debug1: identity file /home/blx/.ssh/id_ed25519 type -1  debug1: identity file /home/blx/.ssh/id_ed25519-cert type -1  debug1: identity file /home/blx/.ssh/id_xmss type -1  debug1: identity file /home/blx/.ssh/id_xmss-cert type -1  debug1: Local version string SSH-2.0-OpenSSH_7.9  ssh_exchange_identification: Connection closed by remote host  

Server-wise, /var/log/auth reports this:

Nov 26 13: 39:36 raspi sshd[19130]: debug1: Forked child 19699.  Nov 26 13: 39:36 raspi sshd[19699]: debug1: Set /proc/self/oom_score_adj to 0  Nov 26 13: 39:36 raspi sshd[19699]: debug1: rexec start in 5 out 5 newsock 5 pipe 7 sock 8  Nov 26 13: 39:36 raspi sshd[19699]: debug1: inetd sockets after dupping: 3, 3  Nov 26 13: 39:36 raspi sshd[19699]: debug1: getpeername failed: Transport endpoint is not connected  Nov 26 13: 39:36 raspi sshd[19699]: debug1: ssh_remote_port failed  

So the TCP connection seems broken, but I don't seem to have this issue when I try to connect with corkscrew directly (i.e. $corkscrew http.proxy.here 80 my.home.ip 22):

Nov 26 13: 39:32 raspi sshd[19130]: debug1: Forked child 19698.  Nov 26 13: 39:32 raspi sshd[19698]: debug1: Set /proc/self/oom_score_adj to 0  Nov 26 13: 39:32 raspi sshd[19698]: debug1: rexec start in 5 out 5 newsock 5 pipe 7 sock 8  Nov 26 13: 39:32 raspi sshd[19698]: debug1: inetd sockets after dupping: 3, 3  Nov 26 13: 39:32 raspi sshd[19698]: Connection from http.proxy.here port 28220 on 192.168.0.11 port 22  Nov 26 13: 39:32 raspi sshd[19698]: Did not receive identification string from http.proxy.here port 28220  

But then of course sshd doesn't know what to do of this...

Any tip? Since I don't think I changed anything in my setup I suspect a sneaky update of the proxy filtering policy that puts me in this situation, but I have no way to be sure. I will try and update my router and Pi to use port 443 when I get home.

Dropping filename extensions with find -exec

Posted: 24 Aug 2021 09:37 AM PDT

When using find, how can I drop the original filename extension (i.e. .pdf) from the second pair of -exec braces ({})?


For example:

find ~/Documents -regex 'LOGIC.*\.pdf' -exec pdf2svg {} {}.svg \;

Input filename:

~/Documents/LOGIC-P_OR_Q.pdf

Output filename:

~/Documents/LOGIC-P_OR_Q.pdf.svg

Desired filename:

~/Documents/LOGIC-P_OR_Q.svg

Piping Find and Move Command Output to a file

Posted: 24 Aug 2021 09:36 AM PDT

I'm executing the following command and the output is not going to the move.log file. Am I missing something in the command?

find /db_backups/30_plus_days -type f -mtime +90 -exec mv {} /db_backups/90_plus_days/ >> /db_backups/move.log 2>&1 \;  

Why does "find / -name '*.txt' | cp /junk" not work?

Posted: 24 Aug 2021 09:37 AM PDT

If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder the following could be considered to work;

find / -name "*.txt" | cp /junk  

but this will not work because find will produce the results as a list, which can't be fed into cp.

So I could use xargs to resolve this

find / -name "*.txt" | xargs cp /junk  

Because xargs will change the list into one line which can be fed into cp. I also think that this command would completely finish searching through the files, 'produce the list', and only then would it run the right side of the pipe (the copy).

Alternatively (and preferably) I could use exec

find / -name ".txt" -exec cp {} /junk \;  

Which would run the copy each time that a match is found, (and it would run the copy in a separate process, so the find command would continue running in parallel).

Can someone confirm that these commands and my understanding is correct?

I should add that this is for education purposes only, this is not a real life scenario.

How to decompress jsonlz4 files (Firefox bookmark backups) using the command line?

Posted: 24 Aug 2021 09:01 AM PDT

There seems to be various JavaScript+browser specific ways of decompressing this, but isn't there some way to transform jsonlz4 files to something unlz4 will read?

Permission denied when using -exec {} ls with find command

Posted: 24 Aug 2021 09:38 AM PDT

When run following command it gives me permission denied message for all the files.

find /data/code/ -name "*.jar" -exec {} ls \;      find: `/data/code/project/shared/build/thirdparty/log4j-1.2.8/commons-logging-1.0.4.jar': Permission denied  

But if I do

ls  /data/code/project/shared/build/thirdparty/log4j-1.2.8/commons-logging-1.0.4.jar  

It prints gives the proper output without any permission denied message.

/data/code/project/shared/build/thirdparty/log4j-1.2.8/commons-logging-1.0.4.jar  

What am I doing wrong?

p.s. : I need to list and remove all the jar files in /data/code

Dual displays, one fixed, one spinning (CentOS 7)

Posted: 24 Aug 2021 09:02 AM PDT

I have 2 monitors and would like to have my setup like this:

  1. Monitor = fixed desktop (only 1)
  2. Monitor = dynamic, spinning desktop (1+)

It was working like this at the beginning but somehow I changed that behavior. Now when I'm spinning both of them have multiple desktops which is a no no for me.

Is there any way to set it up like it was before? I'm using latest GNOME.

Add driver to live distro?

Posted: 24 Aug 2021 08:07 AM PDT

I am using Lightweight Portable Security, and I need to add the FGLRX driver so I can boot it on my system (R9 200 is keeping it from booting). Is there a workaround? Is there a way I can just add the files to ISO image?

find -exec exit 1 \; Doesn't work neither does find -exec sh -c exit 1 \;

Posted: 24 Aug 2021 09:38 AM PDT

Using Enterprise Linux 5/6, Bash 4.x I want this type of logic:

# IF temp file exists, exit because we are restarting already       find /tmp/restarting_server -mmin -10 -exec exit 1    lsof -i TCP:1234 || declare Server_is_down=TRUE      if ! [ -z $Server_is_down ]; then restart_server      fi  # Restart Server Function  restart_server() {      touch /tmp/restarting_server       service server restart      rm -f /tmp/restarting_server   }  

The problem is find's -exec doesn't like builtins it seems. I know I can do an if then statement to check for the file and exit there, but I want to know how to do this in a find -exec (or I'd settle for a good xargs solution).

ssh prompts for password despite ssh-copy-id

Posted: 24 Aug 2021 07:57 AM PDT

I've been using public key authentication on a remote server for some time now for remote shell use as well as for sshfs mounts. After forcing a umount of my sshfs directory, I noticed that ssh began to prompt me for a password. I tried purging the remote .ssh/authorized_keys from any mention the local machine, and I cleaned the local machine from references to the remote machine. I then repeated my ssh-copy-id, it prompted me for a password, and returned normally. But lo and behold, when I ssh to the remote server I am still prompted for a password. I'm a little confused as to what the issue could be, any suggestions?

No comments:

Post a Comment