Tuesday, August 31, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Using SSH with shell script works with manual input but not with parameters

Posted: 31 Aug 2021 10:57 AM PDT

I have a shell script authenticate.sh that looks like

#!/bin/bash  sshpass -p '$1' ssh $2@localhost  

I call it using

bash authenticate.sh password username  

But I get "Permission denied, please try again" when I run it. If I instead run

#!/bin/bash  sshpass -p 'password' ssh user@localhost  

it works...

Any help?

linux tc's (traffic control) fw filter is not working

Posted: 31 Aug 2021 10:18 AM PDT

I am trying to modify the wondershaper script for a different use-case.

So, I am trying to change the following to filter (Refer to line 253) to fwmark filter so that I can set up different download speed limits based on different iptables mark.

# Add filter to rule for IP address  tc filter add dev "$IFB" protocol ip parent 2: prio 1 u32 \      match ip src 0.0.0.0/0 flowid 2:1;  

so, to test this I have tried the following iptable command to add a mark 6 to every packet.

iptables -t mangle -A PREROUTING -j MARK --set-mark 6  

and then used following tc command instead of the tc command above

tc filter add dev ifb0 protocol ip parent 2: handle 6 fw classid 2:1  

However this is not working and I would appreciate if someone can provide proper help. I'm finding it extremely difficult to learn tc.

Cant use space from a mounted disk in a debian GCP VM

Posted: 31 Aug 2021 09:21 AM PDT

I mounted a SD disk to my Google cloud VM running debian 11. It' mounted on /mnt, and it has 100gb of free space.

But when i try to install anything in the VM, it says i dont have free space. Somehow i need to tell to the vm to use that disk storage, but i don't know how, im a new linux user.

Can someone help me here? The print below shows the situation. I'm listing every command i used to mount the disk below too. Thanks

enter image description here

## Format disk  sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb    ## Make disk directory  sudo mkdir -p /mnt/disks/disk1    ## Using mount tool  sudo mount -o discard,defaults /dev/DEVICE_NAME /mnt/disks/disk1    ## Read and write permissions to every user  sudo chmod a+w /mnt/disks/disk1  

Automating KDE Plasma Settings

Posted: 31 Aug 2021 08:59 AM PDT

I have a dual-monitor setup, and I want games to appear on the second monitor (which has a higher resolution). Unfortunately, only a handful will allow for moving on the second monitor, and the rest will just stick with the resolutions from the first (Kwin rules don't help). My current solution is to temporarily set the second monitor as primary whenever I'm playing a game. However, I wish to be able to automate this in a bash script, along with a few other tasks. Is there some API I need (perhaps via dbus?) or a configuration file I can change that would allow me to do this?

GNS3 can't find VMware vmrun

Posted: 31 Aug 2021 08:50 AM PDT

I am trying to create a topology using GNS3 with VMware. I have already created a virtual machine in VMware, yet when I try to add it to GNS3, I get this error message.

G

I can't find any pertinent info on the troubleshooting page of vmware.

Thanks

Iptables u32 module install Centos 8

Posted: 31 Aug 2021 08:43 AM PDT

On Centos 8 stream the dnf version of iptables seems to be missing the u32 module, how does one obtain this module?

Seems to exist in Fedora 34

enter image description here

rm -rf : is there an all or nothing approach?

Posted: 31 Aug 2021 08:12 AM PDT

Let's say I have the following structure :

$ mkdir d1  $ mkdir d1/d2  $ touch d1/f1  $ touch d1/d2/f2    $ chmod u-w d1/d2  

If I try to remove d1, I can't because I don't have write permissions on d1/d2. But it still deletes d1/f1 :

$ rm -rf d1  rm: cannot remove 'd1/d2/f2': Permission denied    $ ls d1  d2          # f1 has been deleted  

Is there a way to implement an "all or nothing" rm tool ? E.g., if it can not delete everything, then it deletes nothing at all.

How do I run things in /etc/fstab and /etc/crypttab interlocked?

Posted: 31 Aug 2021 07:55 AM PDT

Imagine this there is a cloud storage foo which can get mounted via

mount -t s3fs foo /mnt/s3  

Which in turn contains a file luks_file which has a LUKS container in it. That can be unlocked like with local key file bar.

cryptsetup luksOpen --key-file bar /mnt/s3/luks_file storage  

And then get mounted itself.

mount /dev/mapper/storage /mnt/storage  

All these 3 commands have pendants in /etc/fstab and /etc/crypttab, but the need to be run interlocked as shown.

Can this be achieved?

How to create a new column in tsv files by combining two other columns on linux?

Posted: 31 Aug 2021 10:09 AM PDT

I have 70 directories that have files like below:

STAN002     |______ STAN002_sasions.tsv  PTAN044     |______ PTAN044_sasions.tsv  STAN005     |______ STAN005_sasions.tsv  STAN050     |______ STAN050_sasions.tsv  QRED034     |______ QRED034_sasions.tsv  .  .  .  PREC098     |______ PREC098_sasions.tsv  

Each of the .tsv file which are in above directories have same number of columns (30 columns) and look like below in the picture:

enter image description here

The 1st and 2nd columns in the .tsv files are like below:

#gene1    gene2  VAV1      THAP4  ZNF75A    ZNF263  KRCC1     POLR1A  H2AFV     TANC1  B3GALT6  RP3-340N1.5  SH3BP1   CTD-2013M15.1(192243),EMB(3603711)  PTPRO     VASN  

Now, on linux using awk or any bash script I want to create a new column in all the .tsv files in the directories. The newly created column will be the 31st column in the files.

It should be like combining 1st and 2nd columns where the names are separated by --. The 31st column should look like below:

gene1--gene2  VAV1--THAP4  ZNF75A--ZNF263  KRCC1--POLR1A  H2AFV--TANC1  B3GALT6--RP3-340N1.5  SH3BP1--CTD-2013M15.1(192243),EMB(3603711)  PTPRO--VASN  

I tried this way, but got wrong:

awk '{print $0, $1 "-" $NF}' STAN002_sasions.tsv  

How to do that on linux in a single script on all the files? Any help is appreciated.

how to use sed in a specific column of a tabular file

Posted: 31 Aug 2021 07:36 AM PDT

I have a tabular file A.tsv (separator=\t) :

20655|dkljdjj   66  lala  20644|kmkmoii   75  lolo  20477|kmlkooo   88  lili  

And I want to remove all the things after the | ( | pipe include ) in the first column, in order to have that :

20655   66  lala  20644   75  lolo  20477   88  lili  

I know how to do that with sed : sed 's/|.*//' A.tsv > B.tsv but it remove all after the pipe , not only the first column.

So do you know how to do that ? Maybe with a combination with awk ? Thanks

Directory permission showing d?

Posted: 31 Aug 2021 08:06 AM PDT

I downloaded some files and saved them in a folder on an external hard drive. Later when I am trying to search for the folder I couldn't find it. So I try searching using the terminal. I listed all the files in the location where I had saved that folder previously and noticed the folder was present there but it showed d????????? permission. What does it mean and how can I get my files back.

terminal

'at' job fails: Script not found in the directory (raspberry pi)

Posted: 31 Aug 2021 08:27 AM PDT

I am trying to run an 'at' job. The job is in ~/mydir/first.sh. It executes second.sh using (sh second.sh) which is in the same directory. I get an error saying that the file is not found.

This is very unusual as I am doing the exact same thing on another linux laptop and have no issues.

How to exclude paths from being extracted when extracting an iso using xorriso

Posted: 31 Aug 2021 10:51 AM PDT

As an example I'm trying to extract all the files from the ubuntu live iso except the path /casper/filesystem.squashfs. According to the man page:

       Normally  xorriso  only writes to disk files which were given as stdio:         pseudo-drives or as log files.  But its alter ego osirrox  is  able  to         extract  file  objects  from  ISO  images  and to create, overwrite, or         delete file objects on disk.         Disk file exclusions by -not_mgt, -not_leaf, -not_paths apply.  

I can extract all paths on the iso fine using:

xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -extract / extract_dir  

But I've been attempting to use the disk file exclusions but to no avail. I've tried different variations or not_leaf and not_paths in different orders both before and after the -extract action. They all extract all paths. Here's a few that I've tried.

Using not_leaf:

xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -not_leaf 'filesystem.squashfs' -extract / extracted_dir  xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -extract / extracted_dir -not_leaf 'filesystem.squashfs'  xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -not_mgt on -not_leaf 'filesystem.squashfs' -extract / extracted_dir  xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -not_mgt on -extract / extracted_dir -not_leaf 'filesystem.squashfs'  

Using not_paths with reorderings as above:

xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -not_mgt on -not_paths 'casper/filesystem.squashfs' -- -extract / extracted_dir  xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -not_mgt on -not_paths '/casper/filesystem.squashfs' -- -extract / extracted_dir  xorriso -osirrox on -indev ubuntu-21.04-desktop-amd64.iso -not_mgt on -not_paths 'extracted_dir/casper/filesystem.squashfs' -- -extract / extracted_dir  

I would accept an answer with not_leaf or not_paths, but would prefer both. And an explanation of the logic behind how this is supposed to work (ie why am I not getting it?) would be nice.

How is it possible that network is still reachable even after disabling the only connection via nmcli?

Posted: 31 Aug 2021 10:44 AM PDT

I've got a system with an ethernet connected over eth1 and managed by Network Manager. The connection has autoconnect set to no in it's settings. After boot the system has no internet access as ping commands fail. I'm able to turn the connection on just fine with nmcli c up eth1 which makes pings successful and has ifconfig report an ip address against eth1.

However, if I want to take the connection down again (with nmcli c down eth1), ifconfig no longer shows an ip address against the interface but pings keep suceeding. How come that's possible? What is it that I'm missing here?

print awk array and replace special characters with comma

Posted: 31 Aug 2021 07:39 AM PDT

I hope the title explains this correctly. I am currently trying to print out an array after counting unique values from a spreadsheet.

My awk command works correctly:

awk -F"," 'NR>1{col[$1,$9]++} END {for (i in col) printf("%s: %d\n", i, col[i])}' my_file.csv | sort  

When printing though I get a special character that looks like a question mark.

output

How do I print this with a comma + space between the year and the season.

eg: 1896, summer: 151

how to run history -a command at regular intervals automatically?

Posted: 31 Aug 2021 10:43 AM PDT

I am using bash shell and I execute history -a command once in a while manually. My typical shell session lasts for weeks if not for months and I rarely exit my shell session. Thus, I force writing my current session history to bash_history using history -a once in a while. I am thinking of writing an automated script to execute history -a regularly once a day. What would be the best way to accomplish this?

is `yes | rm -r` safer than `rm -rf`

Posted: 31 Aug 2021 08:47 AM PDT

I have heard many times that issuing rm -rf is dangerous since users can accidentally remove the entire system. But sometimes I want to remove a directory recursively without being asked every time. I am thinking about using yes | rm -r instead.

The thing I am thinking is that, is yes | rm -r safer than rm -rf? Or essentially they are the same?

How to edit /etc/printcap?

Posted: 31 Aug 2021 10:54 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?

Capture picture after unlocking screen / logging in i3

Posted: 31 Aug 2021 07:52 AM PDT

Running Manjaro with i3wm, and my .i3/config has the following related to locking the screen:

# Lock screen  exec --no-startup-id xss-lock -- ~/.i3/lock.sh  bindsym $mod+Ctrl+l exec --no-startup-id i3exit lock  bindsym $mod+9 exec --no-startup-id blurlock  

The script lock.sh is:

#!/bin/sh  set -e  xset s off dpms 0 10 0  i3lock --color=4c7899 --ignore-empty-password --show-failed-attempts --nofork  xset s off -dpms  

Similar to this post I want to have a picture taken via a script every time the screen is unlocked. I've written a script that captures a picture from the local webcam, and this works perfectly fine - how do I alter the above setup to have the script run after unlocking my screen?

I hope this can be done at the level of the .i3/config rather than messing with pam.d files like the answer in the linked post.

Stuck in selecting columns using regex (in wazuh decoder)

Posted: 31 Aug 2021 08:58 AM PDT

I have this log but I don't know how to select few columns.

04.07.2021 12:11:31.801 [25760] info  MainForm  -  Database(s) loaded: CA_2021,beforetest,FL_2,FL_Jan_2021,jhon,DC_City_Jan_2021,Statetest,Benchmark_2021  

I used (\d\d\d\d) (\d+:\d+:\d+) and able to select

2021 12:11:31  

Can anyone help on selecting

2021 12:11:31 [25760] info FL_Jan_2021 DC_City_Jan_2021 Benchmark_2021  

https://documentation.wazuh.com/current/user-manual/ruleset/ruleset-xml-syntax/regex.html

thunderbird: force encoding for all composed emails to unicode

Posted: 31 Aug 2021 10:33 AM PDT

I am using thunderbird 68.8. on Debian 10.

I have received an email in HTML format, with what looks to be greek ISO encoding (iso-8859-7)

When I click reply, the composed email is automatically set to same (Greek ISO) encoding, even though normally all my compose emails are in unicode.

How can I set to always compose all emails as unicode, regardless what the original email encoding was? I don't want to "inherit" some weird encoding that somebody else has sent me.

Normally, the emails I send are plaintext and unicode.

arch linux hdmi not detected

Posted: 31 Aug 2021 08:03 AM PDT

today I started my laptop, but my external display was not working. I ran the command xrandr:

Screen 0: minimum 8 x 8, current 1366 x 768, maximum 32767 x 32767  eDP1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 340mm x 190mm     1366x768      59.97*+     1280x720      59.74       1024x768      60.00       1024x576      60.00    59.90    59.82       960x540       60.00    59.63    59.82       800x600       60.32    56.25       864x486       60.00    59.92    59.57       640x480       59.94       720x405       59.51    60.00    58.99       680x384       60.00       640x360       59.84    59.32    60.00    VIRTUAL1 disconnected (normal left inverted right x axis y axis)  

As you can see, there is no hdmi. When I run this exact same command on my other computer, it shows this:

Screen 0: minimum 8 x 8, current 1366 x 768, maximum 32767 x 32767  eDP1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 340mm x 190mm     1366x768      59.97*+     1280x720      59.74       1024x768      60.00       1024x576      60.00    59.90    59.82       960x540       60.00    59.63    59.82       800x600       60.32    56.25       864x486       60.00    59.92    59.57       640x480       59.94       720x405       59.51    60.00    58.99       680x384       60.00       640x360       59.84    59.32    60.00   DP1 disconnected (normal left inverted right x axis y axis)  DP2 disconnected (normal left inverted right x axis y axis)  HDMI1 disconnected (normal left inverted right x axis y axis)  HDMI2 disconnected (normal left inverted right x axis y axis)  VIRTUAL1 disconnected (normal left inverted right x axis y axis)  

my os: Linux acer-a515 5.7.12-arch1-1 #1 SMP PREEMPT Fri, 31 Jul 2020 17:38:22 +0000 x86_64 GNU/Linux Can someone help me?

My RAID 1 always renames itself to /dev/md127 after rebooting | DEBIAN 10

Posted: 31 Aug 2021 07:42 AM PDT

PROBLEM

I create a RAID 1 configuration, I name it /dev/md1, but when I reboot, the name always changes to /dev/md127

Disable Internet Access on Eth0

Posted: 31 Aug 2021 09:05 AM PDT

I have a Raspberry with eth0 (192.168.0.2 / static) connected to a router (Fritz Box @ 192.168.0.1). The Router has internet connection. The Raspberry has a mobile usb stick with ppp connect to the internet. Actually if ppp is not connected the internet access from the Raspberry is through the Router over eth0. If ppp is connected the internet access is via ppp. if I del the default route for eth0 there is no internet connection if ppp is not connected and if ppp is connected internet connection is through ppp. So far everything fine. But if restart the raspberry it again has internet connection through eth0. I want to allow the raspberry internet connection only via ppp. eth0 just for internal communication like ssh. Any ideas how to configure that?

/etc/network/interfaces looks like:

source-directory /etc/network/interfaces.d  auto lo  iface lo inet loopback    auto eth0  iface eth0 inet static  address 192.168.178.2  netmask 255.255.255.0      allow-hotplug wlan0  iface wlan0 inet manual      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf    allow-hotplug wlan1  iface wlan1 inet manual      wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf  

fish shell : exec format error

Posted: 31 Aug 2021 09:48 AM PDT

On an Ubuntu ($ uname -a : Linux kumanaku 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), I just installed fish ($ fish --version : fish, version 2.7.1) using the following commands :

sudo apt-add-repository ppa:fish-shell/release-2  sudo apt-get update  sudo apt-get install fish  chsh -s /usr/bin/fish  echo /usr/bin/fish | sudo tee -a /etc/shells  

I can launch fish and use it but when I launch a simple shell file like :

echo "something"  

I got the following message :

$ ./myscript.sh    Failed to execute process './myscript.sh'. Reason:  exec: Exec format error  The file './myscript.sh' is marked as an executable but could not be run by the operating system.  

There's no shebang in my script. If I add #!/usr/bin/env fish, everything's ok (i.e. the script is successfully launched) but I'd like to avoid such a line to keep my script compatible with different shells.

Any idea ?

GPG cache options don't work

Posted: 31 Aug 2021 07:32 AM PDT

There is an option named default-cache-ttl that controls how long the agent will remember the password to the private key. However, when I put it in the config file it doesn't work - instead, gpg complains:

gpg: /home/jan/.gnupg/gpg.conf:8: invalid option  

My version of GPG is

$ gpg2 --version  gpg (GnuPG) 2.1.11  

Trying to mount and recover data from a DVD/recorder HDD

Posted: 31 Aug 2021 10:06 AM PDT

I have a old DVD/HDD recorder (Panasonic DMR-EH58) with RCA inputs & outputs etc. I want to recover all the recordings off its HDD. The HDD is a 2008 ATA/IDE 7200RPM Hitachi deskstar Model no:HDP725025GLAT80 250 GB has a DVD drive.

It has been used at a conference center for many years recording camera RCA input. It is in good condition but it is outdated so I am trying to copy the recordings to a computer. I also would like to recover the deleted files if possible as they would not have been overwritten yet.

I have borrowed a universal drive adapter and tried to mount it on both Windows 8.1 and ChaletOS Linux (Ubuntu based XFCE type distro). Windows showed it as a grayed F: drive and Linux did not auto mount it either.

GParted shows it as "/dev/sdb: unrecognised disk label":
GParted

Command line attempts follow:

joel@joel-laptop:~$ mount dev/sdb  mount: dev/sdb: No such file or directory    joel@joel-laptop:~$ sudo mount /dev/sdb /mnt/usbdisk  [sudo] password for joel:   mount: special device /dev/sdb does not exist    joel@joel-laptop:~$ mount dev/sdb  mount: dev/sdb: No such file or directory    joel@joel-laptop:~$ ls -alh /dev/disk/by-path/  total 0  drwxr-xr-x 2 root root 160 Apr 30 22:05 .  drwxr-xr-x 6 root root 120 Apr 30 18:41 ..  lrwxrwxrwx 1 root root   9 Apr 30 21:31 pci-0000:00:1f.2-ata-1 -> ../../sda  lrwxrwxrwx 1 root root  10 Apr 30 21:31 pci-0000:00:1f.2-ata-1-part1 -> ../../sda1  lrwxrwxrwx 1 root root  10 Apr 30 21:31 pci-0000:00:1f.2-ata-1-part2 -> ../../sda2  lrwxrwxrwx 1 root root  10 Apr 30 21:31 pci-0000:00:1f.2-ata-1-part3 -> ../../sda3  lrwxrwxrwx 1 root root  10 Apr 30 21:31 pci-0000:00:1f.2-ata-1-part5 -> ../../sda5  lrwxrwxrwx 1 root root  10 Apr 30 21:31 pci-0000:00:1f.2-ata-1-part6 -> ../../sda6  
  • Root directory is dev/sda5
  • Swap is dev/sda6
  • Windows is dev/sda1
  • Spare data partition is dev/sda2

Looks like an unsupported file system error...

How can I monitor the length of the accept queue?

Posted: 31 Aug 2021 08:23 AM PDT

I have a hypothesis: sometimes TCP connections arrive faster than my server can accept() them. They queue up until the queue overflows and then there are problems.

How can I confirm this is happening?

Can I monitor the length of the accept queue or the number of overflows? Is there a counter exposed somewhere?

"psql: could not connect to server: No such file or directory"

Posted: 31 Aug 2021 07:32 AM PDT

Actually, I installed PostgreSQL 9.4 (with postGIS extension), and when installed, everything used to work fine.

As said on many tuts, I've set the /data folder, checked configuration files, and so on. Worked on other projects so I did not work on psql for a while But when installation was done, it used to work correctly, I made a test database, initialized postgres user, etc.

Now, I try to start psql (with "default" postgres user) and cannot connect! Start/stop/restart service do not change anything...

Result of "psql" command (with postgres user) :

psql: could not connect to server: No such file or directory  Is the server  running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?  

When I check service status, I get this :

postgresql.service - PostgreSQL RDBMS  Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)  Active: active (exited) since tue 2016-05-24 09:24:13 CEST; 3s ago  Process: 5658 ExecStart=/bin/true (code=exited, status=0/SUCCESS)  Main PID: 5658 (code=exited, status=0/SUCCESS)  

Starting/Stopping/Restarting service with command

sudo service postgresql start (or restart or stop)  

Does not change anything to actual system behaviour..

Log says:

DETAIL:  Permissions should be u=rwx (0700).  FATAL:  data directory "/var/lib/postgresql/9.4/main" has group or world access  

No comments:

Post a Comment