Wednesday, August 4, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Wiregurd access only to local network without internet masquerade

Posted: 04 Aug 2021 11:11 AM PDT

I work on a Windows computer and I need to use a network folder that is located on a dedicated Linux server (Linux server without NAT and with a white ip in cloud). On Linux I installed samba server and wireguard, I get to connect to the Linux network folder, but recently I needed to provide access to the same Linux folder to several more people, but I don't want to open them access to the Internet when connected via wireguard. When connecting any user via wireguard he accesses the Internet via VPN. How to make sure that any person who connects via wireguard can only access a remote local network, without access to the Internet? To open access to the Internet I use

vim /etc/sysctl.conf   net.ipv4.ip_forward = 1  sysctl -p      firewall-cmd --permanent --zone=public --add-port=35053/udp  firewall-cmd --permanent --zone=public --add-masquerade  firewall-cmd --reload  

If you do not use masquerading at all, then when you connect, you can see the local network, but there is no Internet.

How to: Copy Images from Gnome to public_html on same server

Posted: 04 Aug 2021 10:57 AM PDT

Hi there I am using CentOS7 as server + GUI. I want to move pictures from Gnome to a public_html directory. What is wrong with my command?

cp -R ~orca/Documents/Tree\ of\ Knowledge/oceanahomes.com/393\ Hastings/Pictures/ /var/www/oceanahomes.org/public_html/393     cp: cannot stat '/home/orca/Documents/Tree of Knowledge/oceanahomes.com/393 Hastings/Pictures/': No such file or directory  

On the terminal I am logged in as orca user. I can su

What am I getting wrong here?

Which Performance Co-Pilot metrics correspond to commonly displayed metrics?

Posted: 04 Aug 2021 10:32 AM PDT

I'm trying to use Performance Co-Pilot (pcp.io) to monitor performance on RHEL 7/8 hosts. A quick run of pminfo shows that I have other 2000 metrics available to me. I'd like to view the metrics that correspond to what's displayed by typical *nix tools like top or iostat.

If I wanted to see measurements that correspond to these items:

  • CPU utilization
  • Memory utilization
  • File I/O in kbps
  • Network utilization

which PCP metrics should I try to monitor? top gives a handful of metrics; pcp gives thousands :-)

Compact expression to bash if statement

Posted: 04 Aug 2021 10:17 AM PDT

How can I make a more compact expression to this ?

if [[ $arg =~ ^[[:digit:]]+$ ]]; then     vb=$arg  else    vb=1  fi     

erroe while configuring SLES 15 using autoinst.xml

Posted: 04 Aug 2021 10:07 AM PDT

Environment: SLES 15 SP3

Question:

I got this error while installing and configuring SLES 15 SP3 using autoinst.xml file(autoyast)

Internal error. Please report a bug report with logs.   Run save_y2logs to get complete logs.    Caller: /mounts/mp_0001/usr/share/YaST2/lib/y2network/autoinst/   interfaces_reader.rb:131:in 'load_generic'    Details: undefined method 'values' for '':String  

I cant figure out what this error is about. I searched in my xml file, there is no mention of load_generic or any other term in the error msg. Could someone please help me out with this error. What's the reason for this error?

Increase CentOS root partition with unused Windows partition space on dualbooot system

Posted: 04 Aug 2021 10:15 AM PDT

I am using windows and centos 8 stream dual boot. I want to extend the size of the centos root . I found this link

Increase Linux partition with unused Windows partition space on dualbooot system

and followed the step mentioned in it. I shrank some memory from my windows and created a new partition using GParted. And in the rescue mode, I created the physical volume of this partition and tried to use this to extend the size of root in LVM of the centos. When I tried to run e2fsck -f /dev/mapper/cs-root or e2fsck -f /dev/cs/root, it is not running and showing the errors as shown in the figure

enter image description here

Due to this I could not use resize2fs command even though i can use lvextend command. How to remove this error and increase the size of the root partition successfully?

print variables based on iterator in for loop - bash [duplicate]

Posted: 04 Aug 2021 09:59 AM PDT

I am trying to print the values of a variable which has naming sequentially in bash.

boxes1=abcd boxes2=efgh boxes3=ijkl

for (( i=1; i<=$boxCount; i++ ));      do       echo "\$$boxes{i}"     done  

I want output like: abcd efgh ijkl

How to set a correct access to repository?

Posted: 04 Aug 2021 09:31 AM PDT

In Linux mint, how can one set correct access to repository from command line?

 git push origin master  fatal: 'origin' does not appear to be a git repository  fatal: Could not read from remote repository.    Please make sure you have the correct access rights  and the repository exists.  

rtl8723de not detected in lsusb in kernels after version 4.19

Posted: 04 Aug 2021 09:14 AM PDT

Mine is an HP laptop with RTL8723de adapter for Wi-Fi + Bluetooth. [kernel 4.19 ---- Wi-Fi doesn't work without installing additional drivers but Bluetooth works] [kernel 5.x ---- Bluetooth doesn't work but Wi-Fi works by default]

In kernel versions 4.19, I can see 'Realtek Bluetooth 4.2' in 'lsusb' output, but in the newer kernels, there is no such entry. What might be the reason for this?

openssl and ruby error when using vagrant

Posted: 04 Aug 2021 08:49 AM PDT

I use CentOS 8.4, libvirtd (libvirt) 6.0.0, Vagrant 2.2.18, gem version 2.7.6.3 and ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]

I am trying to use vagrant to build VM's on Qemu/KVM. Technically, KVM is running fine and I am manually able to create VM's. It's just that, I am unable to create VM's using vagrant. I installed vagrant and vagrant plugin for libvirt. Version is: vagrant-libvirt (0.5.3, global)

I tried to bring up vagrant using this command vagrant up --provider=libvirt and got error as

/usr/lib64/libk5crypto.so.3: undefined symbol: EVP_KDF_ctrl, version OPENSSL_1_1_1b - /home/user/.vagrant.d/gems/2.7.4/gems/ruby-libvirt-0.7.1/lib/_libvirt.so (LoadError)  

I use OpenSSL version as 1.1.1g FIPS 21 Apr 2020

How to fix this issue?

Setting verbosity level from list of function arguments

Posted: 04 Aug 2021 09:12 AM PDT

I am using a bash function to which I pass arguments. I would like to capture if a particular option was defined by the user -v NUM or --verbosity=NUM. If defined as described, I would like to set tho local variable vb to NUM.

to convert a list to another data format

Posted: 04 Aug 2021 08:36 AM PDT

I want to convert the following format using unix/shell script. How do I code it in a way it can read the input and transform into the output format?

input:

address bit[0]      bit[1]         bit[2]  00012    1.22,2.33  1.22,2.653    1.2345,2.32425  00013    1.12,2.314  1.23,2.613    1.123,2.13123  

output:

1.22 2.33       [12][0]  1.22,2.653      [12][1]  1.2345,2.32425  [12][2]  1.12,2.314       [13][0]  1.23,2.613      [13][1]  1.123,2.13123  [13][2]  

Script to repeat "if" statement every X minutes for Y minutes and then fail if not true

Posted: 04 Aug 2021 10:25 AM PDT

The 'autorep' & 'sendevent' commands are specific to Autosys but the script I have to run is as follows:

if autorep -g GLOBAL_VARIABLE |grep " 0 " >/dev/null   then     sendevent -E SET_GLOBAL -G "YES"     else    sleep 2  fi  

How do I loop this script until GLOBAL_VARIABLE = 0, or 20 minutes, whichever comes first?

I was thinking a for loop but was hoping for some guidance.

Output of autorep command:

Global Name                                                      Value                                                                                                Last Changed  ________________________________________________________________ ____________________________________________________________________________________________________ ____________________  GLOBAL_VARIABLE                                                        Y                                                                                                    12/15/2020 00:00:01  

If the Value of GLOBAL_VARIABLE is not 0 I need the script to sleep for 2 minutes and try again. The script should exit 1 if 0 isn't the Value at the end of 20 minutes.

Error: Cannot perform an interactive login from a non TTY device when login in GitHub Actions

Posted: 04 Aug 2021 08:56 AM PDT

When I am using this command to login docker in GitHub Actions:

docker login --username=${{ secrets.ALIYUN_DOCKER_REPO_USER_NAME }} --password=${{ secrets.ALIYUN_DOCKER_REPO_USER_PASSWORD }} registry.cn-hangzhou.aliyuncs.com  

shows error:

Run docker login --username=*** --*** registry.cn-hangzhou.aliyuncs.com  Error: Cannot perform an interactive login from a non TTY device  Error: Process completed with exit code 1.  

what should I do to fix this problem? This is my full GitHub Action CI script:

- name: Build image push to aliyun    run: |      docker login --username=${{ secrets.ALIYUN_DOCKER_REPO_USER_NAME }} --password=${{ secrets.ALIYUN_DOCKER_REPO_USER_PASSWORD }} registry.cn-hangzhou.aliyuncs.com      docker build -f dolphin-acientbay/Dockerfile -t="${namespace}/dolphin-acientbay-service:v1.0.0" .  

runs on Ubuntu operation system.

Display Swap memory usage of different processes based on PID [closed]

Posted: 04 Aug 2021 09:39 AM PDT

Script to display swap utilisation of top five processes using shell scripting

Customizing linkifiication in Linux terminal

Posted: 04 Aug 2021 08:51 AM PDT

My employer uses a number of custom link shortcuts. For example, b/ is the bug database. This means that in IRC, we trade links like b/12345.

I'm running weechat in gnome terminal for IRC.

Is there a way to force the terminal (any terminal) to recognize b/12345 as a url?

Systemd service that only runs when USB Drive is mounted

Posted: 04 Aug 2021 09:20 AM PDT

I've been searching for an elegant way of automating a very tedious process.

This is the workflow I want to achieve:

  1. Plug in the USB Disk (single partition)
  2. sdX1 gets automatically mounted to /mnt/data with some mounting options
  3. Some systemd services are started (which interact with the files in the mountpoint.
  4. I manually issue a command to unmount the drive.
  5. Services get automatically terminated.

I've been experimenting with Transmission, so I have the following service:

[Unit]  Description=Transmission BitTorrent Daemon  After=network.target  After=mnt-data.mount    [Service]  User=transmission  Type=notify  ExecStart=/usr/bin/transmission-daemon -f --log-error  ExecReload=/bin/kill -s HUP $MAINPID  NoNewPrivileges=true    [Install]  WantedBy=multi-user.target  WantedBy=mnt-data.mount  

And this is my udev rules file:

SUBSYSTEMS=="usb", ATTRS{idProduct}=="1153", ACTION=="add", ENV{SYSTEMD_WANTS}=="transmission.service"

I thought managed to get the service started when the drive gets mounted but I can't get this to behave.

I appreciate your help.

EDIT: This seems to be a bit harder than what I assumed since udisks doesn't appear to talk to systemd. When I unmount drive via systemctl stop mnt-data.mount the service gets stopped, but if I unmount any other way, the service continues to run.

Quickly wiping multiple large 10tb+ drives

Posted: 04 Aug 2021 10:41 AM PDT

I currently have multiple full 10, 12, and 14tb drives that I plan on selling. The problem I am facing is that I cant seem to find a decently fast method to to wipe to wipe them that doesn't say it will take 30+ weeks. In regards to the data I really don't care if its securly deleted or not because that data is literally completely random. I've looked at multiple sources online but haven't really been able to find a viable solution so if someone can point me in the right direction I would really appreciate it.

Rollback qcow image of kvm guest

Posted: 04 Aug 2021 09:37 AM PDT

Good morning, I have a fedora server, in which I have kvm with virt-manager. The images of the guests are qcow2. Days ago by mistake 2 images of 2 guests were deleted. Both are in the snapshot the day before, but I can't put them back in the location where they were deleted. The snapshots are made with btrfs, the partition of the vm and the snapshots is the same


sorry for the delay in answering. yes, I mean the host. Before any problem, cp /mnt/snapshots/server/serverimage.qcow2 / mnt / vm / server / for example. At this moment, when doing the example, cp throws the input / output error. Solve by copying with rsync and the --inplace function (at the end of the copy rsync also gave an error and began to copy again, but what was already copied was in its entirety and working. Now, the cp and rsync errors, are they disk errors? btrfs partition? Do not know.

Debug Postfix Mail Delivery with direct console output, like sendmail -bv

Posted: 04 Aug 2021 08:43 AM PDT

We know about

sendmail -bv target@example.com  

This sends a mail to the currently logged in user, which is problematic if local delivery does not work.

Is there such a command which will print the delivery directly to the console?

How do I adjust the display color whitout any hardware (e.g. spectrometer)?

Posted: 04 Aug 2021 09:54 AM PDT

I recently replaced my laptop screen, and when it was first installed, its color was too greenish. I go into Windows 10 and use dccw.exe(a windows built-in color calibration tool) adjust the gamma and RGB of the display by looking at some pictures with the naked eye, so that the screen displayed more normal. And then dccw generated an icc profile. Later, I go into Pop OS, imported the icc profile to gnome's settings->color, and gnome told me "full screen display correction not possible with this profile". So I'm now looking for other ways to adjust the display color on linux.

I am not an artist, I just want my screen to display a bit more normal, so I don't plan to buy any hardware, it would be too much trouble. Pop OS did Pre-installed NVIDIA driver, but my laptop are using Intel core graphics output, NVIDIA graphics calculation, so the NVIDIA X Server Settings told me the display can't control by nvidia. I have also tried searching the icc profile shared by others on the Internet. I can't find the model of mine(BOE NV156FHM-N69), only find the NV156FHM-N61 and used it. The effects not perfect but ok, but I prefer to customize by self. I've also tried redshift and gnome night lights, and customized color temperature, but it's not as good as using other screens' icc profile. I wonder if there is a better and easier way customize the display color RBG and Gamma like using dccw.exe on windows.

Any thoughts and ideas on that topic would be highly appreciated.

Thanks in advance!

Can we get address of a variable in a C program using GDB?

Posted: 04 Aug 2021 08:37 AM PDT

Actually, I was learning about the buffer overflow attack. So, can we figure out buffer address (I am using buffer variable in my program so that while writing in the buffer, I will make changes in the stack)?

How to install the latest Nvidia drivers on Linux Mint 20

Posted: 04 Aug 2021 10:54 AM PDT

I have a Linux Mint 20.0 (Ulyana) Cinnamon, which is Ubuntu 20.04 based.


GPU: NVIDIA, GeForce GTX 1060, Max-Q Design, 6 GB GDDR5/X VRAM

which has the basic specification as follows:

GeForce GTX 1060 specs


Objective

To install the latest available drivers without using any PPA (Personal Package Archive).


Status

If I run the integrated Mint's Driver Manager, I only see an old version 390 available below.

nvidia-driver-390

Using sed command arguments to be compatible with both GNU & BSD Unix (in-place editing)

Posted: 04 Aug 2021 10:54 AM PDT

I have a shell script that I currently use for some build related stuff for a mobile application.

Due to the the subtle differences between BSD & GNU one of build scripts originally written on a Mac (BSD)

environment=$1    if [[ -z $environment ]]; then     environment="beta"  fi  if ! [[ $environment =~ (live|beta) ]]; then    echo "Invalid environment: $environment"    exit 1  fi    mobile_app_api_url="https://api"$environment".mysite.com"    cp app/index.html.mob MobileApp/www/index.html    sed -i'' "s#MOBILE_APP_API_URL#\"$mobile_app_api_url\"#g" MobileApp/www/index.html  

The sed command has been written on BSD (Mac) but as builds may take place on both Mac or Ubuntu (GNU) I need to modify this to work with on both flavours, what is the best approach for this?

Intermingled input when using local gpg-agent from remote site

Posted: 04 Aug 2021 10:09 AM PDT

I'm starting a local gpg-agent on my Mac, with the extra-socket option. Then I connect to a remote site using SSH, forwarding the remote S.gpg-agent socket to the local S.gpg-agent.extra socket. This works:

ssh -R /remotehome/.gnupg/S.gpg-agent:/localhome/.gnupg/S.gpg-agent.extra remotesystem  

When I want to sign something on the remote machine, the pinentry dialog pops up locally and asks for the password, which is the way it should work. However, when I start typing my password, some of the key presses obviously goes into pinentry (they are displayed as *) whereas some key presses ends up in the shell that runs on the same tty as the pinentry process.

     ┌────────────────────────────────────────────────────────────────┐       │ Note: Request from a remote site.                              │       │                                                                │       │ Please enter the passphrase to unlock the OpenPGP secret key:  │       │ "My name  <my.email@address>"                                  │       │ 4096-bit RSA key, ID MYKEYIDXXX0000YYY,                        │       │ created 2015-06-17 (main key ID MYMAINKEYIDXXX0000YYY).        │       │                                                                │       │                                                                │       │ Passphrase: t*i*e_____________________________________________ │       │                                                                │       │         <OK>                                    <Cancel>       │       └────────────────────────────────────────────────────────────────┘  

Pressing Return has a chance of either sending the mangled password to gpg, or sending whatever key presses that didn't go into pinentry to the shell:

/bin/ksh: tie: not found

How do I get pinentry to grab all keys from the tty?

The local machine is a Mac running GnuPG 2.1.14 (compiled from pkgsrc). The remote site is either a Linux machine with the same version of GnuPG or an OpenBSD machine with GnuPG version 2.1.15 (no difference). The extra-socket option is the only option enabled in my gpg-agent.conf. The environment variable GPG_TTY is correctly set, and running gpg-connect-agent updatestartuptty /bye locally will move the tty on which pinentry starts up, but with the same problem.

Doing gpg-connect-agent updatestartuptty /bye on the remote machine results in

$ gpg-connect-agent updatestartuptty /bye gpg-connect-agent: connection to agent is in restricted mode ERR 67109115 Forbidden <GPG Agent>

... which is what I kinda expect should happen.

Changing from the curses interface to the tty interface for pinentry makes no difference. These are the only two pinentry interfaces available to me. I do not run X11.


Update: With the local system running OpenBSD 6.3 (GnuPG 2.2.9) and the remote being some Ubuntu system (GnuPG 2.1.11), it's even worse with no key presses going into pinentry and everything being read by the shell.

Split string by delimiter and get N-th element

Posted: 04 Aug 2021 08:13 AM PDT

I have a string:

one_two_three_four_five  

I need to save in a variable A value two and in variable B value fourfrom the above string

I am using ksh.

Sync two Directories without rsync

Posted: 04 Aug 2021 09:00 AM PDT

I know what you are thinking right now "Just use rsync" but unfortunately this system does not have rsync, and I would like to come up with another solution.

The Setup:

  1. The source Server has a Upload folder containing 140 000+ Files (No Sub Directories)
  2. The destination Server needs the Upload folder containing 140 000+ Files

Let's call it Migrating with only Post-It Notes... Now to complicate matters, Server 1 keeps getting new files every day, due to new Uploads or Thumbnails being generated, so that idea in your head right now "just copy the file from 1 to 2" will not work, as once I am done with the Copy of about 20+GB I can start again, as there is already new file on the source Server...

My Solution Idea

  • Copy the complete folder from source to destination
  • Find the latest create date in the destination Server and use as starting point on the source Server
  • Copy all files since the last create date from the source to the destination (delta)
  • Setup a cron to do this as often as possible.

My Problem

find /uploads/* -mtime -1 bash: /bin/find: Argument list too long

Now before I start writing a bash script loop , I was wondering if there is someone out there that could suggest another way of doing this without a bash script... good old low level CLI.

PostgreSQL Remote Connection debugging

Posted: 04 Aug 2021 11:02 AM PDT

I'm having issues connecting to my PostgreSQL database from an online source.

PostgreSQL seems to be setup up fine it is running on it's default port 5432 and the postgresql.conf has the following line

listen_addresses = '*'  

And the pg_hba.conf has the following

host    dbname    usname    all    md5  

I can connect to the PostgreSQL database from a different machine using the following credentials in pgadmin

Name              local  Host              192.xx.xx.xx  Port              5432  Maintenance DB    dbname  Username          usname  Password          psword  

Using these I can connect perfectly it seems to work fine.

Then I forwarded the port 192.xx.xx.xx:5432 on the ADSL router and checked it using the public IP address 197.xx.xx.xx (visible to the internet IP) http://www.canyouseeme.org/ Where I can see the port was forwarded ok.

I've disabled SELinux and disabled the firewall temporarily as well.

However when I try to connect using

Name              online  Host              197.xx.xx.xx  Port              5432  Maintenance DB    dbname  Username          usname  Password          psword  

I get the server doesn't listen error message

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "197.xx.xx.xx" and accepting TCP/IP connections on port 5432?  

Why is this? Do I need to add an extra step to making it accept connections through port forwarding?

Remote DLNA / UPnP Media Client / Controller

Posted: 04 Aug 2021 10:31 AM PDT

I have a MiniDLNA + Bubble UPnP Server running at home and I would like to access it remotely from my PC at work. I can check that the server is properly accessible though the Bubble UPnP App for Android, where I can enter the URL to my server.

There is a wide range of UPnP client software for Linux, but non of them offers the possibility to enter an URL, which is quite hard to believe. During my search I checked all of them listed here on wikipedia, and all of them just search the local network for servers.

Does anybody know a UPnP client / controller software which can deal with remote servers?

How to copy files to the timestamp generated directory?

Posted: 04 Aug 2021 10:03 AM PDT

Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to copy files from the Documents directory to the new created directory that is unique. This will be in a crontab backing up files from documents and when the backup will kick in, it will create new directory for each backup that is uniquely identified by the directory timestamp. For some reason I cannot get the cp or cpio -mdp.

bkdate="date +%Y_%m_%d_%H_%M_%S"  PATH=/home/user/backup/  bksource="/home/user/Documents/"    mkdir /home/user/backup/"bk$(date +%Y_%m_%d_%H_%M_%S)"  cp $bksource * ls | tail -l | $PATH  

I could of went with the ctime but unfortunately it does not work with the directory creation date.

This was my approach but with the latest created directory and not file

find $HOME -type d -daystart ctime 0  

If someone could please help me out to copy to that new directory, I would really appreciate it.

Solution: This is one solution using target. I am open to other ways that could be used for this purpose.

bkdest=/home/user/backup  bksource=/home/user/Documents  target=${bkdest}/bk.$(date +%Y_%m_%d_%H_%M_%S)  mkdir -p $target  cp ${bksource}/* ${target}/  

No comments:

Post a Comment