Saturday, June 5, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Iptables redirection need masquerade to work, but how to deny internet access after it?

Posted: 05 Jun 2021 09:30 AM PDT

Im working on a custom portal captive, i have a public hotspot working on ip 20.0.0.1 and i redirect all incoming trafic from port 80 to 20.0.0.1:8000 with:

iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j DNAT --to 20.0.0.1:8000  

Also have ip forward enabled:

sysctl net.ipv4.ip_forward=1  

Redirection don't work if i don't masquerade first.

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  

All work good after this, and now i need to block internet access but keep port 8000 for the redirection thing.

iptables -A FORWARD -i wlan0 -p tcp --dport 8000 -j ACCEPT  iptables -A FORWARD -j DROP  

But traffic redirected to 8000 never reach 20.0.0.1:8000 where my http server is listening, i need allow internet access but after login in my captive portal and this way keeps blocked all traffic, redirection never happent.

What im doing wrong? sorry my bad english and thanks in advance.

what does 'gYw' mean?

Posted: 05 Jun 2021 09:21 AM PDT

i see the text phrase gYw in a popular shell script attributed to Daniel Crisman for illustrating terminal color codes.. does it have any meaning, or is it maybe a very short form of lorem ipsum text?

Can I relate a USB device from /sys to a particular USB connector from Dmidecode?

Posted: 05 Jun 2021 09:47 AM PDT

Having had a bit of an internet-scour, I think the answer may be "No", but:

Can I find the USB port description (as per dmidecode) corresponding to the USB device from sysfs?

We can enumerate all USB hubs and devices by listing /sys/bus/usb/devices. For example:

lrwxrwxrwx 1 root root 0 May 18 09:40 1-2 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-2  lrwxrwxrwx 1 root root 0 May 18 09:40 1-2:1.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0  lrwxrwxrwx 1 root root 0 May 18 09:36 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-0:1.0  lrwxrwxrwx 1 root root 0 May 18 09:36 2-3 -> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-3  lrwxrwxrwx 1 root root 0 May 18 09:36 2-3:1.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.0  lrwxrwxrwx 1 root root 0 May 18 09:36 usb1 -> ../../../devices/pci0000:00/0000:00:14.0/usb1  lrwxrwxrwx 1 root root 0 May 18 09:36 usb2 -> ../../../devices/pci0000:00/0000:00:14.0/usb2  

…And we can list all built-in USB ports on the machine by doing dmidecode -t connector. For example it shows (among many other connectors):

Handle 0x000D, DMI type 8, 9 bytes  Port Connector Information      Internal Reference Designator: USB REAR      Internal Connector Type: Proprietary      External Reference Designator: Rear: USB-1      External Connector Type: Access Bus (USB)      Port Type: USB    [...]    Handle 0x0014, DMI type 8, 9 bytes  Port Connector Information      Internal Reference Designator: USB 3.0 REAR      Internal Connector Type: Proprietary      External Reference Designator: Rear: USB 1      External Connector Type: Access Bus (USB)      Port Type: USB  

(On my machine, it looks like each USB port appears twice, in the guise of "USB" and "USB 3.0".)

I'd love to be able show the connector description ("Rear: USB 1") corresponding to a particular USB device— but there does not seem to be a reliable way to relate /sys/bus/USB devices to dmidecode connectors— Is there?

(In my particular case, it would be tempting to relate "usb1" from the bus to "USB 1" from Dmidecode… but I'm willing to bet that that's a coincidence.)

Edit: Or if not dmidecode, some other tool which could provide an external description of the port.

Find a resource that is missing OSX

Posted: 05 Jun 2021 09:11 AM PDT

On OSX (big sur -so Zhell)I have a folder that contains .bundle files , each bundle containa several files and folders. in most of the files there is a resource called PNG_.zip and some do not.

so if i run this :

find ~/Desktop/test  -name "PNG_.zip"    

it will output anything that contains PNG_.zip .

I want however to find all the items that do not contain PNG_.zip how can i do that?

Thanks!

Print a portion of a lines in a text file between predefined tags

Posted: 05 Jun 2021 09:48 AM PDT

I have a file like the following

<g> Good wheatear </g> other parts of line   <g> The farm land is to be sold </g> other parts of line  <g> knock knock </g> other parts of line   

I want my output to be like this:

<g> Good wheatear </g>   <g> The farm land is to be sold </g>  <g> knock knock </g>  

i.e. print the content between <g> and </g> tags including the tags

I have tried this command:

awk '/<s>/, /<\/s>/' trsTest.txt

But it prints the whole line.

How to print the content between the tags ?

MySQL-Workbench has uninstallable dependencies on POP!_OS

Posted: 05 Jun 2021 08:50 AM PDT

I started by installing mysql-server from the offical repos which was no problem. But here was no installation candidate for mysql-workbench in the official repos, so I opted to download the debian package from here

When i tried to install the debian package I was met with this error.

The following packages have unmet dependencies:    mysql-workbench-community: Depends: libc6 (>= 2.33) but 2.32-0ubuntu3 is to be installed    Depends: libgdk-pixbuf-2.0-0 (>= 2.22.0) but it is not installable    Depends: libproj19 (>= 7.2.0) but it is not going to be installed    Depends: libzip4 (>= 0.10) but it is not installable  

Someone on reddit then recommended that I do this

wget -O /tmp/mysql-apt-config.deb https://repo.mysql.com/mysql-apt-config_0.8.16-1_all.deb    sudo apt install /tmp/mysql-apt-config.deb    sudo apt update    sudo apt install mysql-server mysql-workbench-community gnome-keyring  

Which left me here

The following packages have unmet dependencies:  mysql-workbench-community : Depends: libproj15 (>= 6.3.0) but it is not installable  E: Unable to correct problems, you have held broken packages.  

You can find a reddit-thread for my issue here

list all folder name only in one line

Posted: 05 Jun 2021 09:27 AM PDT

How list all folder name in the same line : Because, I tried:

ls $workspace  

I get

parm  shell  sql  

But I want the final result look like :

parm shell sql  

NOTE

I am writing this command in script window of the jenkins job. And the command result should be saved in file named "folder1.txt" So the original command is :

ls $WORKSPACE --ignore={"Jenkinsfile",".gitignore",".editorconfig","branches.txt","folders.txt"} > folder1.txt  

I tried also :

ls -1 $WORKSPACE --ignore={"Jenkinsfile",".gitignore",".editorconfig","branches.txt","folders.txt"} > folder1.txt  

But the command result given in folder1.txt, is

parm  shell  sql  

How do I get domain's nameservers from the "source"?

Posted: 05 Jun 2021 08:42 AM PDT

When I run whois google.com, it shows following name servers:

Name Server: ns2.google.com  Name Server: ns4.google.com  Name Server: ns3.google.com  Name Server: ns1.google.com  

So my question is, where is the source of this data? Can I make some kind of request (http/tcp/udp etc.) to get it directly from the "source", without doing whois command?

Keep the partition type unchange when to dd a file into it

Posted: 05 Jun 2021 08:24 AM PDT

List the file type on sdb:

debian@debian:~$ sudo blkid |grep  sdb  /dev/sdb1: UUID="19a2c9fa-f793-415d-9e25-082fa3bbbb3d" TYPE="ext4" PARTUUID="eb3ae1bb-01"  /dev/sdb2: UUID="11d2d221-e53e-4828-8e3e-50e63ffb01ce" TYPE="ext4" PARTUUID="eb3ae1bb-02"  

DD a image file into sdb1.

debian@debian:~$ sudo dd if=openwrt-19.07.7-x86-64-combined-ext4.img of=/dev/sdb1   bs=4M  68+1 records in  68+1 records out  285736960 bytes (286 MB, 272 MiB) copied, 0.156294 s, 1.8 GB/s  debian@debian:~$ sync  

Show the file type again:

debian@debian:~$ sudo blkid |grep sdb  /dev/sdb1: PTUUID="eb3ae1bb" PTTYPE="dos" PARTUUID="eb3ae1bb-01"  /dev/sdb2: UUID="11d2d221-e53e-4828-8e3e-50e63ffb01ce" TYPE="ext4" PARTUUID="eb3ae1bb-02"  

How to keep the partition type unchange when to dd a file into it

Search for pattern if exist then replace the whole line else insert a new line after another pattern using SED command

Posted: 05 Jun 2021 09:05 AM PDT

I am attempting to write a very simple one liner SED command that does not employ bash conditions.

For a SED command that does something similar but instead appends to the end of the file, I use the following:

sed -n -e '/.*MYLINE.*/!p' -e '$aVAR=MYLINE' -i /path/to/file  

But this time, the position of inserted line is critical, so it should be right after specific string. I attempted the following:

sed -n -e '/.*MYLINE.*/!p' -e t -i '/^ANOTHER_PATTERN.*/aVAR=MYLINE' /path/to/file    

so I can turn the /path/to/file from this one

...  ANOTHER_PATTERN=SOMETHING  ...  

or this one

...  ANOTHER_PATTERN=SOMETHING  VAR=OTHERS MYLINE  ...  

to produce this

...  ANOTHER_PATTERN=SOMETHING  VAR=MYLINE  ...  

however, it does not produce the expected outcome. I tried googling but to no avail.

How to correctly perform search for pattern if exist then replace the whole line else insert a new line after a another pattern using SED?

psycopg2.OperationalError: could not connect to server: No route to host Is the server running on host "db" and accepting TCP/IP connections on port

Posted: 05 Jun 2021 07:55 AM PDT

Following the instructions here was fine on openSUSE Tumbleweed with Docker version 20.10.6-ce, build 8728dd246c3a

https://github.com/mirumee/saleor-platform#how-to-run-it

But on openSUSE Leap 15.3 with Docker version 19.03.15, build 99e3ed89195c the migrate command (last command) throws an error:

$ git clone https://github.com/mirumee/saleor-platform.git --recursive --jobs 3  $ cd saleor-platform  $ docker-compose build  $ docker-compose run --rm api python3 manage.py migrate  

Error

psycopg2.OperationalError: could not connect to server: No route to host Is the server running on host "db" (172.21.0.4) and accepting TCP/IP connections on port 5432?

Error log

m3@localhost:~/repos/saleor-platform> docker-compose run --rm api python3 manage.py migrate  Creating network "saleor-platform_default" with the default driver  Creating network "saleor-platform_saleor-backend-tier" with driver "bridge"  Creating saleor-platform_jaeger_1 ... done  Creating saleor-platform_db_1     ... done  Creating saleor-platform_redis_1  ... done  Traceback (most recent call last):    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection      self.connect()    File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner      return func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect      self.connection = self.get_new_connection(conn_params)    File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner      return func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection      connection = Database.connect(**conn_params)    File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect      conn = _connect(dsn, connection_factory=connection_factory, **kwasync)  psycopg2.OperationalError: could not connect to server: No route to host          Is the server running on host "db" (172.21.0.4) and accepting          TCP/IP connections on port 5432?      The above exception was the direct cause of the following exception:    Traceback (most recent call last):    File "manage.py", line 10, in <module>      execute_from_command_line(sys.argv)    File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line      utility.execute()    File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute      self.fetch_command(subcommand).run_from_argv(self.argv)    File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv      self.execute(*args, **cmd_options)    File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute      output = self.handle(*args, **options)    File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped      res = handle_func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 92, in handle      executor = MigrationExecutor(connection, self.migration_progress_callback)    File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__      self.loader = MigrationLoader(self.connection)    File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__      self.build_graph()    File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph      self.applied_migrations = recorder.applied_migrations()    File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations      if self.has_table():    File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table      with self.connection.cursor() as cursor:    File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner      return func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor      return self._cursor()    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor      self.ensure_connection()    File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner      return func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection      self.connect()    File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__      raise dj_exc_value.with_traceback(traceback) from exc_value    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection      self.connect()    File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner      return func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect      self.connection = self.get_new_connection(conn_params)    File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner      return func(*args, **kwargs)    File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection      connection = Database.connect(**conn_params)    File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect      conn = _connect(dsn, connection_factory=connection_factory, **kwasync)  django.db.utils.OperationalError: could not connect to server: No route to host          Is the server running on host "db" (172.21.0.4) and accepting          TCP/IP connections on port 5432?    m3@localhost:~/repos/saleor-platform>   

Tried

Might be due to operating system settings. I added PostgreSQL port 5432 to public ports by firewall, but error is still received.

Tried

Didn't work:

  • Restarting Docker service
  • Rebooting the machine

Tried

Following commands didn't help:

https://stackoverflow.com/a/57502873/3405291

Get Subnet (172.19.0.0/16) by:

docker network ls  docker inspect ${NETWORK_NAME}  

Then:

sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=172.19.0.0/16 accept'  sudo firewall-cmd --reload  sudo systemctl restart docker.service  

Tried

This approach didn't work, i.e. adding this to database service inside docker-compose.yml file:

     environment:         - POSTGRES_HOST_AUTH_METHOD=trust  

https://unix.stackexchange.com/a/589519/158683

How to run an expect script in parallel rather than sequentially?

Posted: 05 Jun 2021 08:55 AM PDT

#!/bin/expect --    set vm_num [lindex $argv 0]    puts "``````````````````````````````````````````````````````````````"  puts "``````````````````````````````````````````````````````````````"  puts "Registering Stations on VM"  puts "Tarts to be Registered: $vm_num"  puts "``````````````````````````````````````````````````````````````"  puts "``````````````````````````````````````````````````````````````"    for { set index 0 } { $index < [llength $vm_num] } { incr index } {    puts "Registering Tart Num: [lindex $vm_num $index]"    switch -- [lindex $vm_num $index]\  1 {          spawn telnet 10.171.0.10 6187          set timeout -1          expect {                  puts "``````````````````````````````````````````````````````````````"                  "*traffic*" { puts "Registering Group1, Group2"                  send "traffic map rate reg_group1 30000\r"                  send "traffic map rate reg_group2 30000\r"                    puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    puts "Registering Group3, Group4"                  send "traffic map rate reg_group3 30000\r"                  send "traffic map rate reg_group4 30000\r"                  puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    puts "Registering Group5, Group6"                  send "traffic map rate reg_group5 30000\r"                  send "traffic map rate reg_group6 30000\r"                  puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    puts "Registering Group7, Group8"                  send "traffic map rate reg_group7 30000\r"                  send "traffic map rate reg_group8 30000\r"                  puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    }                      puts "wait 3 seconds"                  sleep 3                    send -- "^]"                  expect -exact "^\]\rtelnet> "                  send -- "close\r"                  expect eof                  wait          }    } 2 {          spawn telnet 10.171.0.11 6187          set timeout -1          expect {                  "*traffic*" {                  puts "``````````````````````````````````````````````````````````````"                  puts "Registering Group1, Group2"                  send "traffic map rate reg_group1 30000\r"                  send "traffic map rate reg_group2 30000\r"                    puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    puts "Registering Group3, Group4"                  send "traffic map rate reg_group3 30000\r"                  send "traffic map rate reg_group4 30000\r"                  puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    puts "Registering Group5, Group6"                  send "traffic map rate reg_group5 30000\r"                  send "traffic map rate reg_group6 30000\r"                  puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    puts "Registering Group7, Group8"                  send "traffic map rate reg_group7 30000\r"                  send "traffic map rate reg_group8 30000\r"                  puts "wait 100 seconds .."                  send "traffic go\r"                  sleep 100                    }                    puts "wait 3 seconds"                  sleep 3                      send -- "^]"                  expect -exact "^\]\rtelnet> "                  send -- "close\r"                  expect eof                  wait          }  } 3 {          spawn telnet 10.171.0.12 6187          set timeout -1          expect {                  "*traffic*" {                  puts "``````````````````````````````````````````````````````````````"                  puts "Registering Group1, Group2"                  send "traffic map rate reg_group1 50000\r"                  puts "wait 220 seconds .."                  send "traffic go\r"                  sleep 220                    puts "Registering Group2"                  send "traffic map rate reg_group2 50000\r"                  puts "wait 220 seconds .."                  send "traffic go\r"                  sleep 220                    }                    puts "wait 3 seconds"                  sleep 3                    send -- "^]"                  expect -exact "^\]\rtelnet> "                  send -- "close\r"                  expect eof                  wait          }  }  default {  puts "$vm_num is not a valid tart"  }  }  

Can someone please guide me I have the above expect script which is executed when we run the script for instance ./vmSetup.ex "1 2 3" but this is executed sequentially. I had created this expect script but now I want to run the cases in the script i.e. 1, 2 and 3 in parallel. Can someone also tell me how to run for instance 8 cases in parallel? Futhermore I am also using similar cases from 1 to 3 the only difference is the IPs. I have 25 such cases. Can someone also tell me how can I use just one case for all the 25 VMs of them?

I have accidentally removed my dev/sda while trying yo intall linux using unet bootin

Posted: 05 Jun 2021 08:43 AM PDT

Since I wanted to install Linux alongside Windows 7 (without usb since my PC refuses to boot from usb or anything, so I decided to use Unet bootin) and then I made a mistake and removed /dev/sda and I can't boot to windows or Linux anymore. All I have is a Windows 7 CD that contains repair pc options. How can I fix my problem? I don't want to end up erasing my data and I can't use terminal. Also did I lose my data?

Find and add quotes in between particular string

Posted: 05 Jun 2021 09:15 AM PDT

when I'm working with csv, unwanted commas(',') is misleading my csv file, in result it gives the inconsistency.

please find in details below.

My sample csv file:

1|a,b|4  1|c,d|4  1|e,f|4  1|g,h|4  1|i,j|4  

I want the end result As:

1|"a,b"|4  1|"c,d"|4  1|"e,f"|4  1|"g,h"|4  1|"i,j"|4  

After adding the quotes I will replace "|" with "," so that my csv will work as I expected.

I used below commnd but its not giving as exprected.

sed -e 's/,/"&"/' file1.txt  

How do I replace leading tabs with 4 spaces with sed?

Posted: 05 Jun 2021 09:00 AM PDT

In vim it seems possible to do like this :

:s/^\t\+/\=repeat('    ',len(submatch(0)))  

I didn't find out how this translates into sed. I tried the following :

sed -ri "s/^\t\+/\=repeat('    ',len(submatch(0)))/g" test.txt  

The command seems to have no effect.

Linux as a router to forward

Posted: 05 Jun 2021 08:14 AM PDT

PC_A has 192.168.1.133/27. PC_B has 192.168.1.140/27.

PC_A has 10.26.14.16/25 route. PC_B has no 10.26.14.16/25 route.

I want PC_B to reach 10.26.14.16/25 via PC_A.

Note: PC_B is an OpenStack Instance. It's private IP is 192.168.118.10/27 and public IP is 192.168.1.140/27.

netselect-apt is unable to find the fastest repo in MX-Linux

Posted: 05 Jun 2021 07:38 AM PDT

Recently, I accidently made some changes in /etc/apt/sources.list file in my system. So after performing apt-get update there was output full of warnings. So I googled for the default sources.list and replaced that with mine. But when I use to the repo manager to find the fastest debian repo for me, the process fails with the following message: netselect-apt could not detect the fastest repo. I am attaching the pic for your convenience. enter image description here

When I use the terminal command sudo netselect-apt, it gives the following output:

  Using distribution stable.  Retrieving the list of mirrors from www.debian.org...    URL transformed to HTTPS due to an HSTS policy  --2021-06-05 09:09:00--  https://www.debian.org/mirror/mirrors_full  Resolving www.debian.org (www.debian.org)... 128.31.0.62, 130.89.148.77, 149.20.4.15, ...  Connecting to www.debian.org (www.debian.org)|128.31.0.62|:443... connected.  HTTP request sent, awaiting response... 200 OK  Length: 129107 (126K) [text/html]  Saving to: '/tmp/netselect-apt.HIfkAg'    /tmp/netselect-apt.HIfkAg                       100%[=======================================================================================================>] 126.08K   137KB/s    in 0.9s        2021-06-05 09:09:03 (137 KB/s) - '/tmp/netselect-apt.HIfkAg' saved [129107/129107]    Choosing a main Debian mirror using netselect.  netselect-apt was unable to obtain a list of valid hosts from  the file downloaded from the url 'http://www.debian.org/mirror/mirrors_full'.  This might happen because of any of the following reasons:      - there was an error in the file      - the file is not in the format netselect-apt expected      - there is a bug in netselect-apt   Please manually check the file. If you believe its contents are correct, file   a bug (hint: use 'reportbug') against netselect-apt and provide the file as   well as the output generated by the program (hint: use 'script').  

Is there anyway to solve this issue? I fear of having broken packages in my system.

How can I automatically mount multiple disks on Ubuntu 20.04 LTS without editing fstab?

Posted: 05 Jun 2021 09:11 AM PDT

I have hundreds of disks that need to be plugged in on several Ubuntu desktops. Currently, the disks will not automatically mount under /media/user/ (but can be found under /dev/sd*). However, with GUI, I can use the file explorer Other locations to show all the plugged-in disks. If I click one, it will be mounted and can be found at /media/user/Disk-UUID. The problem is, there are many disks that need to be clicked, and everything restores to original after reboot.

So, how can I write a script to mimic the behavior of clicking on the disks to automatically mount all disks that have been plugged in?

When I look up the method online, it seems that most people are talking about editing /etc/fstab. However, I do not want to do it this way, because I treat these disks as temporarily plugged in, do not want to name them, and do not want to make permanent changes to the system. Besides, after the disks being mounted, I see no entry in file /etc/fstab, so Ubuntu itself are doing it by other means. How can I achieve the same?

Update: Based on the suggestion of @fra-san, I found that for a disk such as /dev/sdn, udisksctl mount --block-device /dev/sdn is a simple way to achieve the goal. However, by default, that will require authentication. To avoid this, on Ubuntu 20.04 LTS, one needs to edit file /usr/share/polkit-1/actions/org.freedesktop.UDisks2.policy, and change the entries under org.freedesktop.udisks2.filesystem-mount-system (notice that there is another similar entry) to yes:

    <defaults>        <allow_any>yes</allow_any>        <allow_inactive>yes</allow_inactive>        <allow_active>yes</allow_active>      </defaults>  

Then udisksctl mount --block-device /dev/sdn will no longer require authentication and immediately mount the disk to /media/user/Disk-UUID.

Gimp: Image Size Background

Posted: 05 Jun 2021 07:30 AM PDT

I have an image I that is my background on my laptop. But the image is too zoomed in. So half of the image is not showing on my laptop background. How do I fix this? Is this a scale thing? I tried re-sizing to 250*250 and applied the new image to the background but same thing. I am using Fedors 34 Lenovo laptop.

Where is the Linux (beta) option on my Acer Chromebook 15?

Posted: 05 Jun 2021 08:06 AM PDT

I have searched every single video and photo on google, and could not find an answer. Usually the Linux (Beta) option would be in the settings..

Like in this photo:

lok

and sometimes it would be under a developers tab..

Like in this photo:

bro

But for me, there was no Linux(Beta) option, and no developers tab..

So my question is, is there another tab/option that I need to click on to find the Linux (Beta) option? Is it hiding in some section that I don't know about?

Formatting Proof in Groff

Posted: 05 Jun 2021 08:45 AM PDT

Is there a way to append a tombstone symbol (usually a square) to the right at the end of line of a proof similar to LaTeX proof?

SED - address N lines before end of file

Posted: 05 Jun 2021 08:20 AM PDT

Is there a simple way in sed to address a file, N lines before the end of the file?

For example, when trying to insert the contents of a file, I can easily insert at the end with sed -i '$ r file2.txt' file1.txt, and even right before the end with sed -i -e '$ e cat file2.txt' file1.txt, but can't seem to find a way to address some N number of lines before the end of the file. Something like $-5 where 5 is the number lines. I know there's probably some combination of head and tail one could use, but I'm looking for a purely sed way.

Replace many strings by another string

Posted: 05 Jun 2021 07:47 AM PDT

I want to run a shell script while ignoring some of the commands, because they need privileges. Commands like insmod. So I filter the script with this, and it works (those commands are replaced by true):

sed -e 's/command1/true/g' -e 's/command2/true/g' -e 's/command3/true/g' ... -e 's/commandN/true/g'  

Is there a more concise way of expressing that?

With simple caracters, to change 'a', 'b', and 'm' into an 'x' I could do something like:

sed -e 's/[abm]/x/g'  

or

tr abm x  

(or its tr abm '[x*]' POSIX equivalent). But with strings?

Find the longest file name

Posted: 05 Jun 2021 08:03 AM PDT

I have to find the symbolic link which contains the longest folder name in a folder full of symbolic links. So far I have this:

find <folder> -type l -printf "%l\n"  

I was wondering if there's any way to save the folder names while searching, something like this pseudo code:

if [length > max]  {    max = length    var = link  }  

Thanks :)

How can I get my wifi card TP-Link TL-WN722N to work in Kali-Linux VMware 12

Posted: 05 Jun 2021 07:29 AM PDT

**Screenshot of VM ware kali linux wifi**

As shown in the screenshot , i tried lsusb and iwconfig, none of them displayed my wifi adapter. I tried switching the USB ports and restarting VM. Performed the updates and upgrades. Its working on the host OS(windows 8).

curl hangs during http download

Posted: 05 Jun 2021 08:05 AM PDT

I have a VM running CentOS 6. On this Linux box, I run 4 curl download concurrently.

In some case, one of the curl download hangs. ps shows that curl process is still there. And netstat shows the connection's RECV_Q is very long:

tcp   878104      0 10.161.238.20:46130         10.162.220.12:80            ESTABLISHED   

The curl version 7.38.0.

Any idea? Why curl hangs? If increasing TCP buffer would help?

How to Resolve undefined reference to 'RAND_egd'

Posted: 05 Jun 2021 09:01 AM PDT

Debian 8 Jessie, OpenSSL version 1.1.0, cURL version: 7.50.2

I am trying to build curl on a Linux Debian system. All stages go well up until trying to build with make command. The linking stage fails with the following error below:

  CC       ../lib/curl-nonblock.o    CC       ../lib/curl-warnless.o    CCLD     curl  ../lib/.libs/libcurl.so: undefined reference to 'RAND_egd'  collect2: error: ld returned 1 exit status  Makefile:771: recipe for target 'curl' failed  make[2]: *** [curl] Error 1  

RAND_egd function is part of the OpenSSL library so I ran ldd on the libcurl.so file to make sure the OpenSSL library is found, and it is judging by the output from ldd below.

linux-vdso.so.1 (0x00007ffceb5a1000)  libnghttp2.so.14 => /usr/lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007ff9ffc05000)  libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007ff9ff9d1000)  libssh2.so.1 => /usr/lib/x86_64-linux-gnu/libssh2.so.1 (0x00007ff9ff7a8000)  libssl.so.1.1 => /usr/local/lib/libssl.so.1.1 (0x00007ff9ff53a000)  libcrypto.so.1.1 => /usr/local/lib/libcrypto.so.1.1 (0x00007ff9ff0af000)  liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007ff9feea0000)  libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007ff9fec4e000)  libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff9fea33000)  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff9fe688000)  libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007ff9fe3a6000)  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff9fe1a2000)  libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff9fdf85000)  libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007ff9fdd6e000)  libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007ff9fdb52000)  libgnutls-deb0.so.28 => /usr/lib/x86_64-linux-gnu/libgnutls-deb0.so.28 (0x00007ff9fd833000)  /lib64/ld-linux-x86-64.so.2 (0x00007ffa0009e000)  libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007ff9fd621000)  libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007ff9fd3db000)  libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007ff9fd1c7000)  libnettle.so.4 => /usr/lib/x86_64-linux-gnu/libnettle.so.4 (0x00007ff9fcf95000)  libhogweed.so.2 => /usr/lib/x86_64-linux-gnu/libhogweed.so.2 (0x00007ff9fcd66000)  libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007ff9fcae3000)  libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007ff9fc8db000)  

So the library is there. I also checked the rand.h file in the include directory of OpenSSL and of course the function declaration is there, so it should be defined in the library. How can I find the cause of and resolve this error?

How to renumber GPT partitions on an umounted disk?

Posted: 05 Jun 2021 09:39 AM PDT

I tried to sort (renumber) partitions on /dev/sdb via terminal, using gdisk from the operating system (running on /dev/sda) and none of the sdb partitions mounted but the only option I get is [-l] which lists options the option I'm trying to use.

root@arch-bill /home/bill # lsblk  NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT  sda      8:0    0 931.5G  0 disk   |-sda1   8:1    0  15.6G  0 part /  |-sda2   8:2    0 915.9G  0 part /home  `-sda3   8:3    0     2M  0 part   sdb      8:16   0   1.8T  0 disk   |-sdb1   8:17   0     2M  0 part   |-sdb2   8:18   0     4G  0 part   |-sdb3   8:19   0    16G  0 part   |-sdb4   8:20   0    60G  0 part   `-sdb6   8:22   0   1.8T  0 part   sr0     11:0    1  1024M  0 rom    root@arch-bill /home/bill # blkid  /dev/sdb1: PARTUUID="c1073e4b-fc00-4f02-8b81-6f17b8a188c4"   /dev/sdb2: LABEL="var" UUID="62921c0a-5d34-464d-8a7a-2ff46ad8f12b" TYPE="ext4" PARTUUID="c350316a-0bd8-4e82-8597-123553977f99"   /dev/sdb3: LABEL="rootbkp" UUID="c245c20e-d503-4b61-aaaf-060aae1b21d4" TYPE="ext4" PARTUUID="b1f391db-de37-479c-8b44-ff27f3bd6aa5"   /dev/sdb4: LABEL="snapster" UUID="8fef4e0a-efd4-455b-b484-83bd4500161f" TYPE="ext4" PARTUUID="02801cd9-3fe5-4814-9b92-c4c83b86173d"   /dev/sdb6: LABEL="homebkp" UUID="51d73ac7-fd96-4ac1-b4f3-4abf6bc4936b" TYPE="ext4" PARTUUID="481ae7d0-228f-4979-8949-befbd498534b"   /dev/sda1: UUID="91865df2-0841-42f5-80f3-a5133976e70f" TYPE="ext4" PARTUUID="48dc34cb-e791-4838-b9f2-2fe2b2cced33"   /dev/sda2: UUID="e5743a89-13ed-4c96-b39d-78cb6478fb72" TYPE="ext4" PARTUUID="4156cbf2-2a2d-47ae-87cf-99c14cf8f2c2"   /dev/sda3: PARTUUID="8669392a-663e-4e15-bc63-a6a5e95c97ad"     root@arch-bill /home/bill # gdisk -s /dev/sdb  GPT fdisk (gdisk) version 0.8.10    Usage: gdisk [-l] device_file  1   root@arch-bill /home/bill # gdisk -l /dev/sdb                                                                                                                                                                                          :(  GPT fdisk (gdisk) version 0.8.10    Partition table scan:    MBR: protective    BSD: not present    APM: not present    GPT: present    Found valid GPT with protective MBR; using GPT.  Disk /dev/sdb: 3907029168 sectors, 1.8 TiB  Logical sector size: 512 bytes  Disk identifier (GUID): 0645408C-0374-4357-8663-D2A3512E07BD  Partition table holds up to 128 entries  First usable sector is 34, last usable sector is 3907029134  Partitions will be aligned on 2048-sector boundaries  Total free space is 4204653 sectors (2.0 GiB)    Number  Start (sector)    End (sector)  Size       Code  Name     1            2048            6143   2.0 MiB     EF02       2            8192         8396799   4.0 GiB     0700       3         8398848        41953279   16.0 GiB    0700       4        41955328       167786495   60.0 GiB    0700       6       167788544      3902834687   1.7 TiB     0700    1 root@arch-bill /home/bill #

Functions defined in .zshrc not found when running script

Posted: 05 Jun 2021 09:39 AM PDT

I have a function in .zshrc that mostly updates the PATH:

my_function()  {          PATH=...  }  

and some scripts that depend on it, e.g. my_script.sh starts with the following lines:

my_function  # do stuff ...  

I then have the following in crontab:

00 02 * * * /path/to/my/zsh /path/to/my_script.sh  

but I have noticed that, even when I run my_script.sh as ./my_script.sh manually (i.e. from my interactive(?) Zsh shell), I get the error:

Command not found: my_function  

even though I can perfectly invoke my_function from the terminal.

Why? I would like a solution that does not require me to add a shebang to my script (for more on this see this)

I found the following diagram. I imagine that in my case, cron launches a non-interactive, non-login shell, which is why none of the init files are run. Is that correct?

enter image description here

No comments:

Post a Comment