Tuesday, April 26, 2022

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Include csv headers in sed

Posted: 26 Apr 2022 05:23 AM PDT

I am building a document script.sed that executes different sed expressions like this:

s/ESP/Spain/g    s/DEN/Denmark/g    s/NED/Netherlands/g  

I run the sed script through:

sed -f script.sed "file.csv"  

The output does not include the csv headers. I have tried with different expressions without success. Is there a way to print them in a sed expression without making any modification?

Thank you

xfce, xfwm and .Desktop shortcut

Posted: 26 Apr 2022 05:12 AM PDT

I started using a Debian distro and I'm new with it. I'm trying to customize shortcut and I don't get the differences between xfce and xfwm. Why there are "two type of shortcut"? (located in the relative menu). In addition, which is the difference between them and .Desktop shortcut (the one generated by writing a .Desktop file). Thanks

Cheers

executing local script on remote server with local input

Posted: 26 Apr 2022 04:55 AM PDT

I have a python script and input data that the python script takes. I want to execute the python script on remote server without copying python script and data to the remote server.

I tried the script:

ssh dong@xxx.27.35.xxx "cd /home/dong/fold python -u -" <  script.py arg1  

It execute the script but the arg1(which is input data) python script doesn't take from local machine but when the input data present in remote server it works.

I hope experts may show some way to overcoming this problem.

Using ntfs-3g, how to parse Windows extended attributes?

Posted: 26 Apr 2022 04:46 AM PDT

Using xattrs, one can access Windows extended attributes using the following command

getfattr -h -n system.ntfs_ea Ntfs_Mount_Point/some_file  

The problem is instead of an attribute list, it returns a raw single binary value encoded as base64 or hex containing everything.
I know how to get a parsed result using ntfsinfo, but it requires the volume to be unmounted and I m looking for a file copy based on xattr data which means I need the volume to be mounted.

So for example (since I know the attitude name I m needing), how to get the value of $LXATTRB from Ntfs_Mount_Point/some_file?

Linux (Mint) eats all my RAM

Posted: 26 Apr 2022 04:44 AM PDT

I know, there are plenty of "Linux eat my RAM" threads all over the internet, but they can't help me to solve my problem. (I had a try with this question on askubuntu but I'm off-chart with Mint)

At home my workstation is a Mint19/Ubuntu18.04/Cinnamon box, used for Java/BigData development.

Some time, not every day, after some hours of work, my Intellij IDE becomes laggy, due to missing RAM.

If I look the "top", I see that only some Mo of the 16G RAM are available and that system is swapping.

I can't understand where the +10G RAM are used for. Some time ago, this happened. To have a better understanding, I CTRL-F1 to a non graphical sessions, then I stopped the LightDM X-Server.

So all the RAM eating graphical apps (skype, slack, chrome etc...) are off. And only the system daemons are alive. After this purge "free" gives me :

Mem:       16130044    11507836     3615496         704     1006712     4287260  Swap:    15625212      541820    15083392  

So, the XServer stop made me recover ~4G, but 11G are always missing /proc/meminfo looks like :

MemTotal:       16130044 kB  MemFree:         3613360 kB  MemAvailable:    4285680 kB  Buffers:          109512 kB  Cached:           744668 kB  SwapCached:        31984 kB  Active:           433228 kB  Inactive:         492328 kB  Active(anon):      39192 kB  Inactive(anon):    32920 kB  Active(file):     394036 kB  Inactive(file):   459408 kB  Unevictable:           0 kB  Mlocked:               0 kB  SwapTotal:      15625212 kB  SwapFree:       15083392 kB  Dirty:               220 kB  Writeback:             0 kB  AnonPages:         66456 kB  Mapped:            75056 kB  Shmem:               704 kB  Slab:             583976 kB  SReclaimable:     153108 kB  SUnreclaim:       430868 kB  KernelStack:        8624 kB  PageTables:        16852 kB  NFS_Unstable:          0 kB  Bounce:                0 kB  WritebackTmp:          0 kB  CommitLimit:    23690232 kB  Committed_AS:    3990300 kB  VmallocTotal:   34359738367 kB  VmallocUsed:           0 kB  VmallocChunk:          0 kB  HardwareCorrupted:     0 kB  AnonHugePages:         0 kB  ShmemHugePages:        0 kB  ShmemPmdMapped:        0 kB  CmaTotal:              0 kB  CmaFree:               0 kB  HugePages_Total:       0  HugePages_Free:        0  HugePages_Rsvd:        0  HugePages_Surp:        0  Hugepagesize:       2048 kB  DirectMap4k:     8152580 kB  DirectMap2M:     8331264 kB  DirectMap1G:     1048576 kB  

Missing RAM is not in SLAB (there are some threads about that)

I tried several things :

  • various versions of sync; echo 3 > /proc/sys/vm/drop_caches
  • kernel upgrade (actually on 4.15.0-173)
  • Rootkit analysis...

But nothing helped

Any idea ?

How to display the paths to all files that have a size greater than the specified limit

Posted: 26 Apr 2022 05:05 AM PDT

I need to output the paths to all files that have a size greater than the specified limit (declared as a variable).

I've done it using find script:

FILESIZE = "+10M";  find "$1" -maxlimit 1 -size "$FILESIZE" -type f -exec echo "put {}" \;  

And it give me 2 errors:

/mnt/d/Lab1_z2.sh: line 1: FILESIZE: command not found    find: unknown predicate `-maxlimit'   

How to solve that?

How to escape folder name for touch command?

Posted: 26 Apr 2022 05:01 AM PDT

I've created two scripts. The first reads the mtime timestamps of all folders and writes it line by line to time_old.txt:

for d in */ ; do      time_old=$(stat --format %Y "$d")      escaped=$(printf %q "$d")      echo "$time_old $escaped" >> time_old.txt  done  

The second reads those lines back and runs touch with the old timestamps on the folders:

input="time_old.txt"  while IFS= read -r line  do    echo "$line"    touch_output=$(touch -m -d @$line)    echo "$touch_output"  done < "$input"  

This works for folders like Folder1, Folder2 but not for folders named Foo & Bar.

Where's my mistake?

How to get overlay filesystem working on Debian

Posted: 26 Apr 2022 05:29 AM PDT

I asked this question and got a great reply on how to install overlayroot-chroot on Debian 11.

I followed the answer and now have overlayroot-chroot:

$ sudo which overlayroot-chroot  /usr/sbin/overlayroot-chroot  

I then changed /etc/overlayroot.conf to:

overlayroot_cfgdisk="disabled"  overlayroot="tmpfs:swap=1,recurse=0"  

Restarted, but if I perform: df / I see the / is still /dev/sda2 instead of overlay

I found out maybe the following is required (tried it, even though on Ubuntu one didnt have, but maybe for Debian its required):

Append overlay to a new file /etc/initramfs-tools/modules, then run the command:

sudo update-initramfs  

Rebooted the computer, but overlay FS is still not enabled.

Does Ubuntu perform some other magic behind the scenes? What else could I try?

Update: I resinstalled the OS on my PC to Ubuntu, and looked at /etc/initramfs-tools/modules and it does not have overlay in it, so now I am not sure how Ubuntu is mounting the overlay root fs.

It seems that overlayroot is bundled with cloud-initramfs-tools, which I have installed, so I aam not sure why overlayroot is not using /etc/overlayroot.conf

Matching lines in file, with 2 lists of strings in order

Posted: 26 Apr 2022 04:44 AM PDT

I am trying to match access-list lines in a file where certain environments (list A) are destination, and other environments (list B) are the source. And vice versa.

This is on an Ubuntu server.

Problem is that these lists are both around ~15 lines, which makes for quite a bit of combinations, and a very long grep command. And the file being searched in is around ~3000 lines total.

I know i can match lines in a file with lines in a file via grep -f, but i haven't been able to find a solution to my specific search requirements, where i am searching from 2 lists, and the order matters.

Example of what i would want to do (the parentheses are intentional, since i am searching in a file that has relevant environment appended to IP addresses per line):

List A contents:  (One)  Two  Three    List B contents:  (Four)  (Five)  (Six)    File that is being searched in:  access-list src (One) dst Two  access-list src (One) dst (Four)  access-list src (Four) dst Three  access-list src (Six) dst (One)  access-list src (Five) dst (Five)    Desired output (List A as destination):  access-list src (Six) dst (One)  access-list src (Four) dst (Three)    Desired output (List B as destination):  access-list src (One) dst (Four)  

I am open to any commands usable on ubuntu or even a python script.

Right now my grep search look something like this (for matching lines where List B is destination, and List A is source)

grep -iE '\(One\).*\(Four\)|Two.*\(Four\)|Three.*\(Four\)|\(One\).*\(Five\) and so on... '  

Any help is appreciated, so i hopefully can reduce my current script from the 15000 characters :)

Kitty Terminal Automatically deselects text?

Posted: 26 Apr 2022 03:42 AM PDT

Every time I highlight text to copy from the terminal it automatically deselects it. Creating a situation where I cannot copy from the terminal.

What might be causing this behaviour?

Logging input and output on terminal with script command, can I do this more elegantly?

Posted: 26 Apr 2022 03:20 AM PDT

Goal: to create a log of an entire terminal session, commands used and their output, including time and date.

I have attempted to achieve this with the script command, which is commonly used in conjunction with scriptreplay. I have also looked into ttyrec and asciinema, but have yet to find a satisfying solution.

Script doesn't seem to have a parameter for adding time and date in front of the commands, but rather has an option to create a secondary timestamp file for use with scriptreplay. Not what I want.

script -f >(awk '{print strftime("%F %T ") $0}' >> session.log)    *stuff is done in terminal*    ctrl+d is pressed to stop script from recording any more.  

This allows me to create the time and date for each entry. A bit hacky.

Simpler is better. What are my other options?

Ubuntu WSL disappeard from my Windows terminal?

Posted: 26 Apr 2022 03:44 AM PDT

Hi I am using WSL Ubuntu 20.04. on my Windows Terminal and I wanted to change my font color. But when I copy code to my .json file Ubuntu disappeard from my Windows terminal. My code in .json file looks like this:

{          "$help": "https://aka.ms/terminal-documentation",          "$schema": "https://aka.ms/terminal-profiles-schema",          "actions": [],          "alwaysShowNotificationIcon": false,          "defaultProfile": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",          "firstWindowPreference": "defaultProfile",          "profiles":           {              "defaults":               {                  "colorScheme": "xcad_tdl",                  "font":                   {                      "face": "Consolas",                      "size": 11                  },                  "historySize": 12000,                  "opacity": 95,                  "scrollbarState": "visible",                  "useAcrylic": false              },              "list":               [                  {                      "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",                      "hidden": false,                      "icon": "%userprofile%\\WindowsTerminalIcons\\ubuntu.png",                      "name": "Ubuntu Linux",                      "source": "Windows.Terminal.Wsl",                      "startingDirectory": "\\\\wsl$\\Ubuntu-20.04\\home\\xcad"                  },                  {                      "backgroundImage": "desktopWallpaper",                      "font":                       {                          "face": "Consolas"                      },                      "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",                      "icon": "%userprofile%\\WindowsTerminalIcons\\cmd.png",                      "name": "Commandline"                  },                  {                      "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",                      "hidden": true,                      "icon": "%userprofile%\\WindowsTerminalIcons\\azure.png",                      "name": "Azure Cloud Shell",                      "source": "Windows.Terminal.Azure"                  }              ]          },           "schemes":                   [          {              "name": "Campbell",              "foreground": "#A7B191",               "background": "#0C0C0C",              "colors": [                  "#0C0C0C",                  "#C50F1F",                  "#13A10E",                  "#C19C00",                  "#0037DA",                  "#881798",                  "#3A96DD",                  "#CCCCCC",                  "#767676",                  "#E74856",                  "#16C60C",                  "#F9F1A5",                  "#3B78FF",                  "#B4009E",                  "#61D6D6",                  "#F2F2F2"              ]          },          {              "background": "#012456",              "black": "#0C0C0C",              "blue": "#0037DA",              "brightBlack": "#767676",              "brightBlue": "#3B78FF",              "brightCyan": "#61D6D6",              "brightGreen": "#16C60C",              "brightPurple": "#B4009E",              "brightRed": "#E74856",              "brightWhite": "#F2F2F2",              "brightYellow": "#F9F1A5",              "cursorColor": "#FFFFFF",              "cyan": "#3A96DD",              "foreground": "#CCCCCC",              "green": "#13A10E",              "name": "Campbell Powershell",              "purple": "#881798",              "red": "#C50F1F",              "selectionBackground": "#FFFFFF",              "white": "#CCCCCC",              "yellow": "#C19C00"          },          {              "background": "#282C34",              "black": "#282C34",              "blue": "#61AFEF",              "brightBlack": "#5A6374",              "brightBlue": "#61AFEF",              "brightCyan": "#56B6C2",              "brightGreen": "#98C379",              "brightPurple": "#C678DD",              "brightRed": "#E06C75",              "brightWhite": "#DCDFE4",              "brightYellow": "#E5C07B",              "cursorColor": "#FFFFFF",              "cyan": "#56B6C2",              "foreground": "#DCDFE4",              "green": "#98C379",              "name": "One Half Dark",              "purple": "#C678DD",              "red": "#E06C75",              "selectionBackground": "#FFFFFF",              "white": "#DCDFE4",              "yellow": "#E5C07B"          },          {              "background": "#FAFAFA",              "black": "#383A42",              "blue": "#0184BC",              "brightBlack": "#4F525D",              "brightBlue": "#61AFEF",              "brightCyan": "#56B5C1",              "brightGreen": "#98C379",              "brightPurple": "#C577DD",              "brightRed": "#DF6C75",              "brightWhite": "#FFFFFF",              "brightYellow": "#E4C07A",              "cursorColor": "#4F525D",              "cyan": "#0997B3",              "foreground": "#383A42",              "green": "#50A14F",              "name": "One Half Light",              "purple": "#A626A4",              "red": "#E45649",              "selectionBackground": "#FFFFFF",              "white": "#FAFAFA",              "yellow": "#C18301"          },          {              "background": "#002B36",              "black": "#002B36",              "blue": "#268BD2",              "brightBlack": "#073642",              "brightBlue": "#839496",              "brightCyan": "#93A1A1",              "brightGreen": "#586E75",              "brightPurple": "#6C71C4",              "brightRed": "#CB4B16",              "brightWhite": "#FDF6E3",              "brightYellow": "#657B83",              "cursorColor": "#FFFFFF",              "cyan": "#2AA198",              "foreground": "#839496",              "green": "#859900",              "name": "Solarized Dark",              "purple": "#D33682",              "red": "#DC322F",              "selectionBackground": "#FFFFFF",              "white": "#EEE8D5",              "yellow": "#B58900"          },          {              "background": "#FDF6E3",              "black": "#002B36",              "blue": "#268BD2",              "brightBlack": "#073642",              "brightBlue": "#839496",              "brightCyan": "#93A1A1",              "brightGreen": "#586E75",              "brightPurple": "#6C71C4",              "brightRed": "#CB4B16",              "brightWhite": "#FDF6E3",              "brightYellow": "#657B83",              "cursorColor": "#002B36",              "cyan": "#2AA198",              "foreground": "#657B83",              "green": "#859900",              "name": "Solarized Light",              "purple": "#D33682",              "red": "#DC322F",              "selectionBackground": "#FFFFFF",              "white": "#EEE8D5",              "yellow": "#B58900"          },          {              "background": "#000000",              "black": "#000000",              "blue": "#3465A4",              "brightBlack": "#555753",              "brightBlue": "#729FCF",              "brightCyan": "#34E2E2",              "brightGreen": "#8AE234",              "brightPurple": "#AD7FA8",              "brightRed": "#EF2929",              "brightWhite": "#EEEEEC",              "brightYellow": "#FCE94F",              "cursorColor": "#FFFFFF",              "cyan": "#06989A",              "foreground": "#D3D7CF",              "green": "#4E9A06",              "name": "Tango Dark",              "purple": "#75507B",              "red": "#CC0000",              "selectionBackground": "#FFFFFF",              "white": "#D3D7CF",              "yellow": "#C4A000"          },          {              "background": "#FFFFFF",              "black": "#000000",              "blue": "#3465A4",              "brightBlack": "#555753",              "brightBlue": "#729FCF",              "brightCyan": "#34E2E2",              "brightGreen": "#8AE234",              "brightPurple": "#AD7FA8",              "brightRed": "#EF2929",              "brightWhite": "#EEEEEC",              "brightYellow": "#FCE94F",              "cursorColor": "#000000",              "cyan": "#06989A",              "foreground": "#555753",              "green": "#4E9A06",              "name": "Tango Light",              "purple": "#75507B",              "red": "#CC0000",              "selectionBackground": "#FFFFFF",              "white": "#D3D7CF",              "yellow": "#C4A000"          },          {              "background": "#000000",              "black": "#000000",              "blue": "#000080",              "brightBlack": "#808080",              "brightBlue": "#0000FF",              "brightCyan": "#00FFFF",              "brightGreen": "#00FF00",              "brightPurple": "#FF00FF",              "brightRed": "#FF0000",              "brightWhite": "#FFFFFF",              "brightYellow": "#FFFF00",              "cursorColor": "#FFFFFF",              "cyan": "#008080",              "foreground": "#C0C0C0",              "green": "#008000",              "name": "Vintage",              "purple": "#800080",              "red": "#800000",              "selectionBackground": "#FFFFFF",              "white": "#C0C0C0",              "yellow": "#808000"          },          {              "background": "#111927",              "black": "#000000",              "blue": "#004CFF",              "brightBlack": "#666666",              "brightBlue": "#5CB2FF",              "brightCyan": "#5CECC6",              "brightGreen": "#C5F467",              "brightPurple": "#AE81FF",              "brightRed": "#FF8484",              "brightWhite": "#FFFFFF",              "brightYellow": "#FFCC5C",              "cursorColor": "#FFFFFF",              "cyan": "#2EE7B6",              "foreground": "#D4D4D4",              "green": "#9FEF00",              "name": "xcad_hackthebox",              "purple": "#BC3FBC",              "red": "#FF3E3E",              "selectionBackground": "#FFFFFF",              "white": "#FFFFFF",              "yellow": "#FFAF00"          },          {              "background": "#1A1A1A",              "black": "#121212",              "blue": "#2B4FFF",              "brightBlack": "#2F2F2F",              "brightBlue": "#5C78FF",              "brightCyan": "#5AC8FF",              "brightGreen": "#905AFF",              "brightPurple": "#5EA2FF",              "brightRed": "#BA5AFF",              "brightWhite": "#FFFFFF",              "brightYellow": "#685AFF",              "cursorColor": "#FFFFFF",              "cyan": "#28B9FF",              "foreground": "#F1F1F1",              "green": "#7129FF",              "name": "xcad_tdl",              "purple": "#2883FF",              "red": "#A52AFF",              "selectionBackground": "#FFFFFF",              "white": "#F1F1F1",              "yellow": "#3D2AFF"          },          {              "background": "#0F0F0F",              "black": "#000000",              "blue": "#2878FF",              "brightBlack": "#2F2F2F",              "brightBlue": "#5E99FF",              "brightCyan": "#5AD6FF",              "brightGreen": "#FFB15A",              "brightPurple": "#935CFF",              "brightRed": "#FF755A",              "brightWhite": "#FFFFFF",              "brightYellow": "#FFD25A",              "cursorColor": "#FFFFFF",              "cyan": "#28C8FF",              "foreground": "#F1F1F1",              "green": "#FF9A28",              "name": "xcad_tdl_colorful",              "purple": "#732BFF",              "red": "#FF4C27",              "selectionBackground": "#FFFFFF",              "white": "#F1F1F1",              "yellow": "#FFC72A"          },          {              "background": "#0F0F0F",              "black": "#000000",              "blue": "#184AE8",              "brightBlack": "#5F5F5F",              "brightBlue": "#4771F5",              "brightCyan": "#31C1FF",              "brightGreen": "#FFD631",              "brightPurple": "#7631FF",              "brightRed": "#FF3190",              "brightWhite": "#FFFFFF",              "brightYellow": "#FF9731",              "cursorColor": "#FFFFFF",              "cyan": "#008DCB",              "foreground": "#D9D9D9",              "green": "#CBA300",              "name": "xcad_tdl_old",              "purple": "#4300CB",              "red": "#CB005F",              "selectionBackground": "#FFFFFF",              "white": "#CFCFCF",              "yellow": "#CB6600"          },          {              "background": "#282C34",              "black": "#000000",              "blue": "#007ACC",              "brightBlack": "#75715E",              "brightBlue": "#11A8CD",              "brightCyan": "#11A8CD",              "brightGreen": "#0DBC79",              "brightPurple": "#AE81FF",              "brightRed": "#DD6B65",              "brightWhite": "#F8F8F2",              "brightYellow": "#E6DB74",              "cursorColor": "#FFFFFF",              "cyan": "#11A8CD",              "foreground": "#D4D4D4",              "green": "#0DBC79",              "name": "xcad_vscode",              "purple": "#BC3FBC",              "red": "#F4423A",              "selectionBackground": "#FFFFFF",              "white": "#F8F8F2",              "yellow": "#E5E510"          }      ],      "showTabsInTitlebar": true,      "tabSwitcherMode": "inOrder",      "theme": "system",      "useAcrylicInTabRow": true  }  

When I click on settings it gave me warning :

[{      "resource": "/C:/Users/janlu/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json",      "owner": "_generated_diagnostic_collection_name_#0",      "code": "768",      "severity": 4,      "message": "Draft 2020-12 schemas are not yet fully supported.",      "startLineNumber": 1,      "startColumn": 1,      "endLineNumber": 1,      "endColumn": 2  }]  

and also when I launch my Windows terminal it says

Settings could not be loaded from file. Check for syntax errors, including trailing commas.  * Line 2, Column 5    Missing '}' or object member name    Temporarily using the Windows Terminal default settings.  

Do you know how can I make my WSL work again but with a new font color? I wanted to make it look more like this https://github.com/xcad2k/dotfiles/blob/main/Windows/WindowsTerminal/settings.json but with a background of my pc. Thank you for your answers and advices.

How to increment a persistant, inter-process counter in bash/shell

Posted: 26 Apr 2022 03:08 AM PDT

Here is a minimal example of what I am trying to do:

# If it does not exist, create a file to persist the unique identifier  if [ ! -f ~/.uid ]; then     echo 0 > ~/.uid  fi    # Increment the unique identifier in the ~/.uid file  echo 1 + $(<~/.uid) | bc > ~/.uid    # Launch expensive computation that uses this unique identifier  uid=$(<~/.uid)  do_something_long $uid  

Except, multiple instances of this script could be running at the same time, and do_something_long should be invoked with an unique identifier (preferably human-readable, so starting from 0 or 1).

I tried to use flock(1) for acquiring a lock, but most safe examples use a subshell to bind to a file descriptor, which prevent me to access the unique identifier in the parent shell. And I don't want do_something_long in the subshell, as it would hog the lock for too long.

FreeBSD - get timezone in Continent/Region format

Posted: 26 Apr 2022 05:11 AM PDT

I have a Linux (bash) script to generate a login message (motd). One of the things it displays is the timezone, using the command timedatectl | grep Time | awk {'print $3'}. The command returns something like America/Chicago which is the format I am seeking.

Naturally, since there is no timedatectl under FreeBSD, this command does not work and I am seeking an alternative.

The closest I have managed is using date +'%z %Z', but that is still quite different.

Is there a way to display the system's timezone in Continent/Region format under FreeBSD?

Thanks!

Running a script on every tty

Posted: 26 Apr 2022 03:11 AM PDT

I have a shell script that i want to run on every tty

echo "Hello!"  

i tried adding it to my .bashrc but it only works after you login and it executes even if the terminal isnt a tty

Why there is a sound from speakers and earphones simultaneously at a time?

Posted: 26 Apr 2022 03:47 AM PDT

I have a earphone(fine) and a new laptop dell inspiron-3501 with ubuntu 22.04 with kernel 5.15.0-25-generic. But I have a audio problem. Normally speakers works fine. But when I plugin earphone then the laptop does not recognize earphone. With alsamixer command if I increase the volume of headphone then sound in earphone works but speakers also plays simultaneously along with earphone. Also next time alsamixer always has volume 0 for headphones.

This is my alsamixer screenshot.

enter image description here

Sed to replace text that comes after match

Posted: 26 Apr 2022 05:44 AM PDT

I was working it with awk, and keying on $1 $2 fields, but awk would act differently depending on whether the FieldSeperator ($match) starts the line, or had a blank before it, or didn't have a blank before it.

I'm thinking that sed is my best choice for this particular task, but need some help. I thought that I would be able to get this with a few simple searches, and although I've seen plenty of examples to replace the entire line, I haven't been able to find what I need to do below. I would appreciate if someone is able to help me out.

I want to specify a variable ($match) that is set to the match I want to find (password=). This will actually be in a batch script where I will loop through various patterns.

I want to print: -only lines containing the match. Ignore lines that do not have the match. -print up to and including the 1st match value on the line -if there is any value after the match, replace it with 'masked' -if there is nothing after the match, print line as is (or replace with 'empty') -case insensitive search for the match.

infile.txt

dummy line    mypassword=123    PASSWORD=1234    secret password=2345  2ndpassword=99485    password=    nothing to see move along  end of file  

Desired Output

mypassword=masked    PASSWORD=masked    secret password=masked    password=   

New installed Kali linux is not connecting to internet

Posted: 26 Apr 2022 03:00 AM PDT

When I was installing Kali linux on my pc, I realized DHCP can't be configured so I skipped that part. After installation I used ifconfig and saw wlan0 was there but after opening a website I get this error that in which I have no internet connection.I had this problem with different kernel versions. any ideas with this problem?

What is the equivalent of "freebsd-update" on OpenBSD?

Posted: 26 Apr 2022 04:00 AM PDT

I have been using FreeBSD for quite some time. Now I want to dive into OpenBSD some more. Currently I'm trying to figure out what is the "recommended" way to keep my system up-to-date.

On FreeBSD, we use the command pkg upgrade to update all the installed packages to the latest version. And we use the command freebsd-update to fetch/install the latest patches for the "base" system (kernel). So, I think with pkg upgrade && freebsd-update I'm pretty much safe.

Now: What is the equivalent procedure on OpenBSD? I think that pkg_add -u on OpenBSD does pretty much the same as pkg upgrade on FreeBSD, i.e. it updates all the installed packages to the latest version. But what about an equivalent to freebsd-update ? So far I found sysupgrade on OpenBSD, but it is giving me "404 Not Found" errors every time. I think this is OpenBSD's way of telling me that, at this time, there is no newer release that I can upgrade to. Fair enough!

But how to get security patches for the "base" system of the OpenBSD release that I'm currently running? Does such thing even exist for OpenBSD, or do I have to wait for new release? 😲

Thank you!

How to use an Android device as additional display on Linux

Posted: 26 Apr 2022 04:35 AM PDT

Can anyone please tell how to use an Android device as a second monitor to extend the display?

I found an app called "spacedesk", but it is only available for windows.

Can anyone suggest a method to do so or install the app?

unable to chmod inside shared folder of virtualbox

Posted: 26 Apr 2022 04:03 AM PDT

I have shared a folder from Windows on to my virtual machine. The shared folder is being mounted correctly, and I am able to read write within the folder, but unable to change permissions of any file within the shared folder.

Below are the mount options of the shared folder

myVM on /media/sf_myVM type vboxsf (rw,nodev,relatime,ttl=0,iocharset=utf8,uid=0,gid=999,dmode=0770,fmode=0770,tag=VBoxAutomounter)  

user is already part of vboxsf group

uid=1000(vmuser) gid=1000(vmuser) groups=1000(vmuser),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare),999(vboxsf),1001(sftp)  

Below error is thrown when try to change permissions using chmod for any files inside shared folder.

chmod: changing permissions of 'perm.txt': Operation not permitted  

Delete line if next line is the same

Posted: 26 Apr 2022 04:48 AM PDT

What sed/awk command can I use? Just sort -u will remove all instances

Input:

abc  abc  def  abc  abc  def  

Expected output:

abc  def  abc  def  

What is the difference between tiling and snapping windows on Linux Mint cinnamon

Posted: 26 Apr 2022 05:13 AM PDT

I am using Linux Mint 19.1.

When I enter window tiling settings it is described as...

Enable Window Tiling and Snapping

In addition is has the settings....

Show snap on-screen display

Show tile heads-up-display

As well, when I hover the window near the edge is says...

Hold ctrl to enter snap mode

But I can not for the life of me figure out what is different between these two concepts. Holding ctrl to enter snap mode just turns the tiling boxes green.

Then only behaviour I see is windows being tiled to full, half and quarter sizes.

wpa_supplicant not connecting, because SSL3 is unsupported

Posted: 26 Apr 2022 02:52 AM PDT

I've a laptop running Debian GNU/Linux Unstable with Network Manager. Since an update of OpenSSL (1.1.1 I think), I can't connect to a Wi-Fi network using WPA2 Enterprise with PEAP (MSCHAPv2). In /var/log/syslog, it says that SSL3 is unsupported:

Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: SME: Trying to authenticate with [REDACTED] (SSID='Hotspot' freq=2412 MHz)  Oct 30 10:52:18 wb9688-b50 kernel: [    9.195724] wlp4s0: authenticate with [REDACTED]  Oct 30 10:52:18 wb9688-b50 NetworkManager[505]: <info>  [1540893138.8304] device (wlp4s0): supplicant interface state: scanning -> authenticating  Oct 30 10:52:18 wb9688-b50 kernel: [    9.216389] wlp4s0: send auth to [REDACTED] (try 1/3)  Oct 30 10:52:18 wb9688-b50 kernel: [    9.218779] wlp4s0: authenticated  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: Trying to associate with [REDACTED] (SSID='Hotspot' freq=2412 MHz)  Oct 30 10:52:18 wb9688-b50 kernel: [    9.228045] wlp4s0: associate with [REDACTED] (try 1/3)  Oct 30 10:52:18 wb9688-b50 kernel: [    9.233930] wlp4s0: RX AssocResp from [REDACTED] (capab=0x431 status=0 aid=4)  Oct 30 10:52:18 wb9688-b50 kernel: [    9.234023] wlp4s0: associated  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: Associated with [REDACTED]  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-EAP-STARTED EAP authentication started  Oct 30 10:52:18 wb9688-b50 NetworkManager[505]: <info>  [1540893138.8600] device (wlp4s0): supplicant interface state: authenticating -> associating  Oct 30 10:52:18 wb9688-b50 NetworkManager[505]: <info>  [1540893138.8605] device (wlp4s0): supplicant interface state: associating -> associated  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=25  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-EAP-METHOD EAP vendor 0 method 25 (PEAP) selected  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=NL  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259127] ath: EEPROM regdomain: 0x8210  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259130] ath: EEPROM indicates we should expect a country code  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259131] ath: doing EEPROM country->regdmn map search  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259132] ath: country maps to regdmn code: 0x37  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259133] ath: Country alpha2 being used: NL  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259134] ath: Regpair used: 0x37  Oct 30 10:52:18 wb9688-b50 kernel: [    9.259136] ath: regdomain 0x8210 dynamically updated by country element  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: SSL: SSL3 alert: write (local SSL3 detected an error):fatal:protocol version  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: OpenSSL: openssl_handshake - SSL_connect error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol  Oct 30 10:52:18 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-EAP-FAILURE EAP authentication failed  Oct 30 10:52:20 wb9688-b50 kernel: [   11.335881] wlp4s0: deauthenticating from [REDACTED] by local choice (Reason: 3=DEAUTH_LEAVING)  Oct 30 10:52:20 wb9688-b50 wpa_supplicant[502]: wlp4s0: Authentication with [REDACTED] timed out.  Oct 30 10:52:21 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-DISCONNECTED bssid=[REDACTED] reason=3 locally_generated=1  Oct 30 10:52:21 wb9688-b50 wpa_supplicant[502]: wlp4s0: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid="Hotspot" auth_failures=1 duration=10 reason=AUTH_FAILED  Oct 30 10:52:21 wb9688-b50 NetworkManager[505]: <warn>  [1540893141.3677] sup-iface[0x5617eb7458b0,wlp4s0]: connection disconnected (reason -3)  Oct 30 10:52:21 wb9688-b50 NetworkManager[505]: <info>  [1540893141.3704] device (wlp4s0): supplicant interface state: associated -> disconnected  

Downgrading OpenSSL fixes it of course, but then I can't use things that are compiled to newer versions of OpenSSL. Is there any way to connect to the Wi-Fi network?

Why is the ssh utility considered a pty?

Posted: 26 Apr 2022 02:53 AM PDT

I've read here that ssh is considered a pty. Why? If I run an ssh command in my console (say, in a Debian server), where comes the "pty" aspect of ssh here? For me, it's like I'm using any other utility like cat or sed, so where comes the "pty" aspect here?

In screen or tmux it would seem more plausible to use this term (even though I think it's quite uncommon and these should be named "multiplexers").

Unable to run pvcreate command

Posted: 26 Apr 2022 03:03 AM PDT

Is it possible to run pvcreate command choosing a USB flash drive as a device? When I executed pvcreate command on Ubuntu:

sudo pvcreate /dev/sdc # */sdc* is a USB device  

I got the error :

Device /dev/sdc not found (or ignored by filtering).  

Here are the device properties

    Disk /dev/sdc: 14.7 GiB, 15728640000 bytes, 30720000 sectors  Units: sectors of 1 * 512 = 512 bytes  Sector size (logical/physical): 512 bytes / 512 bytes  I/O size (minimum/optimal): 512 bytes / 512 bytes  Disklabel type: dos  Disk identifier: 0xcad4ebea  Device     Boot Start      End  Sectors  Size Id Type  /dev/sdc4  *      256 30719999 30719744 14.7G  c W95 FAT32 (LBA)  

Shell Script: Want to delete two consecutive lines matching pattern from specific line

Posted: 26 Apr 2022 05:03 AM PDT

I want to delete specific two consecutive lines matching patterns from specific line from a file.

For e.g. file contents are like below.

Line1: a  Line2: b  Line3: c  Line4: Name: 123  Line5:  xyz  Line6: Name: 456  Line7:  abc  

I want to find the lines starting from line 4, matching 1st line pattern starting with "Name: " and matching 2nd line pattern starting with whitespace and delete the two consecutive lines.

Any efficient way to do this in shell using sed or something else?

To be a bit more clear, I want to remove signing/checksum information from the MANIFEST.MF.

Sample MANIFEST.MF like below: From the below manifest file, I want to remove the entry "Name: ". where "Name: " entry can be in one line or 2(or more) lines.

Initially my solution was like find the first "Name: " entry followed by "SHA-256-Digest: " entry and delete to the end of the file. Unfortunately this solution has a problem of removing one needed entry in the middle. For e.g. "NetBeans-Simply-Convertible: " is also being removed.

So, now I want to remove "Name: " entry if available in 1 line or entry spanned across 2 or more lines. But I should not lose entries like "NetBeans-Simply-Convertible: " while removing "Name: " entries.

Already I am removing "SHA-256-Digest: " entries with the below command on file with sed -i "/^\SHA-256-Digest: /d" $manifest_file


Manifest-Version: 1.0
Version-Info: ....

Name: com/abc/xyz/pqr/client/relationship/message/notifier/Relati
 onshipUpdateNotifierFactory.class
SHA-256-Digest: cSSyk6Y2L2F9N6FPtswUkxjF2kelMkGe4bFprcQ+3uY=

Name: com/abc/xyz/pqr/client/relationship/ui/BaseRelationshipView
 $5.class
SHA-256-Digest: w9HgRjDuP024U4CyxeKPYFe6rzuzxZF3b+9LVG36XP8=

Name: com/abc/xyz/pqr/client/impl/MofRelationshipAgentImpl.class
SHA-256-Digest: GwIBIU+UdPtjyRhayAVM90Eo+SwCT/kP65dI59adEnM=

Name: com/abc/xyz/pqr/client/settings/ConvertibleProperties.class
NetBeans-Simply-Convertible: {com/abc/xyz/pqr/client/settings}Con
 vertibleProperties
SHA-256-Digest: 5FszAtfpPXcLx/6FBWbfeg6E4fwFMRozV+Q+3rReATc= ...

Expected Output:

Manifest-Version: 1.0
Version-Info: ....


NetBeans-Simply-Convertible: {com/abc/xyz/pqr/client/settings}Con
 vertibleProperties

...

How much RAM should an SSH connection typically use?

Posted: 26 Apr 2022 02:58 AM PDT

I'd like to ask about how much memory an SSH connection should take typically. Here is how I'm finding out how much of a RAM hit is incurred:

Kindly don't get vehement that I'm using a GoDaddy shared hosting plan or cPanel. When nothing is running, cPanel reports 0 MB of RAM in use. When I SSH into my (1GB, 2 CPU) shared hosting, cPanel suddenly reports around 490 MB of RAM in use.

(Also, I literally obliterated all PHP files in the public folder to eliminate the chance this is due to robot crawling. I read https://serverfault.com/questions/449296/why-is-linux-reporting-free-memory-strangely, but it doesn't help.)

No connections:

No SSH

After SSH'ing into my account:

SSH'ing

ps aux output:

login as: user123  user123@xxxx.com's password:  user123@a2plcpnl0490 [~]$ ps aux  USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND  user123   675171  0.0  0.0 138652  1492 ?        S    11:09   0:00 pure-ftpd (ID  user123   678698  0.0  0.0 191408  9132 ?        S    11:25   0:00 /usr/bin/php  user123   679664  0.0  0.0 104632  1832 ?        S    11:29   0:00 sshd: user123@  user123   679666  0.0  0.0  11476  1636 pts/0    Ss   11:29   0:00 -bash  user123   679759  0.0  0.0  13380  1028 pts/0    R+   11:30   0:00 ps aux  user123@a2plcpnl0490 [~]$  

My question is, how much RAM should an SSH connection take? Is around 500 MB typical?

GoDaddy support says, "That's the way it is. Get VPS." Is that really right??

How to unfreeze after accidentally pressing Ctrl-S in a terminal?

Posted: 26 Apr 2022 03:25 AM PDT

It's a situation that has happened quite often to me: after I press (with a different intention) Ctrl-S in a terminal, the interaction (input or output) with it is frozen. It's probably a kind of "scroll lock" or whatever.

How do I unfreeze the terminal after this?

(This time, I have been working with apt-shell inside a bash inside urxvt--not sure which of them is responsible for the special handling of Ctrl-S: I was searching the history of commands backwards with C-r, as usual for readline, but then I wanted to go "back" forwards through the history with the usual--at least in Emacs--C-s (1, 2, 3), but that caused the terminal to freeze. Well, scrolling/paging to view past things still works in the terminal, but no interaction with the processes run there.)

No comments:

Post a Comment