Sunday, September 12, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


how to get the evaluated text of bash output

Posted: 12 Sep 2021 10:07 AM PDT

ok so when I run a command line it prints some output, and some of the text is different collors and there is some other formatting going on. When I get the string programmatically It has a bunch of control characters "The 'To' number +18 is not a valid phone number.\x1b[0m\n\n\x1b[37m\x1b[49m" printed directly out you get the text nicely formatted without all those control characters. If you highlight this text in putty and copy to notepad the text looks the same with the formatting removed.

How can I get the evaluated text without the formatting? is there any such program? if you use echo it just reprints out the formatted text and maintains the formatting so that doesn't work.

Thank you in advanced

Can I skip syscalls made by the linker in strace?

Posted: 12 Sep 2021 10:06 AM PDT

When I use strace to examine a program, I often have a hard time finding where the syscalls from the linker end and the syscalls from the program begin.

The output from strace ./hello where hello a simple hello world C program is 36 lines. Here's a sample:

execve("./hello", ["./hello"], 0x7fffb38f4a30 /* 73 vars */) = 0  brk(NULL)                               = 0x1304000  arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe6715fe60) = -1 EINVAL (Invalid argument)  access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)  openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3  newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=92340, ...}, AT_EMPTY_PATH) = 0  mmap(NULL, 92340, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f78d9fbd000  close(3)                                = 0  openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3  read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260|\2\0\0\0\0\0"..., 832) = 832  pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784  pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48  

Is there a way to ignore the linker syscalls?

Incrontab to monitor a folder and email the file

Posted: 12 Sep 2021 09:14 AM PDT

I am trying to monitor one folder and want to be emailed the newly created file. Below is what I have. The mailFile.sh script works well independently, but I am not getting the files emailed.

Code to email me a file:

$nano mailFile.sh  #/bin/bash  echo -e "TEST" | mailx -s "$1" -A "$1" myEmail@example.com  

Incrontab to monitor the folder

$ incrontab -e    /home/pi/folder1/ IN_CREATE /home/pi/mailFile.sh $#  

Any suggestions?

I have added port to firewalld but can not connect from outside

Posted: 12 Sep 2021 09:03 AM PDT

I'm working on Centos7 VPS and I have added port 9200 to firewalld, but can not access it to from outside

my firewall status

> firewall-cmd --list-all  public    target: default    icmp-block-inversion: no    interfaces:     sources:     services: dhcpv6-client ssh    ports: 8420/tcp 9200/tcp    protocols:     masquerade: yes    forward-ports:     source-ports:     icmp-blocks:     rich rules:   

active zones status

> firewall-cmd --get-active-zones    

default zones

> firewall-cmd --get-default-zone  public  

if u notice my interfaces which is on above lines ,u can see that is empty, is this ok?

When writing an ISO image to USB flash drive with dd, how do I know I can remove the stick?

Posted: 12 Sep 2021 09:01 AM PDT

When writing an ISO image to USB flash drive with dd, how do I know I can remove the stick? Obviously I'll wait until the command completes and I'm back at the terminal prompt. But even then the device might still be busy from a cache/buffer. Because I'm writing to the device itself, nothing is mounted, so I also don't call umount and cannot see if the device is still busy.

I've seen dd ... && sync a few times. But doesn't that block until buffers for all media have been written? Not only the one flash drive that I used dd with. So if I have lots of other write processes, wouldn't that block?

Would the conv= argument for dd help? But which one of conv=sync, conv=fsync, conv=fdatasync, ...?

Use value variable with double quotes as command parameter, but without having single quotes

Posted: 12 Sep 2021 08:25 AM PDT

I need to run something like mycommand -f "a","b"

But I need to run it inside this kind of bash script:

p="\"a\",\"b\""    mycommand -f "$p"  

But if I run this script the command that start is

mycommand -f '"a","b"'  

and not

mycommand -f "a","b"  

How to have $p as parameter without the single quote?

gateway sends packets (L3) without data link layer (L2) connection

Posted: 12 Sep 2021 08:12 AM PDT

pretty straightforward question:

#tcpdump -i wlp2s0   [..]    16:33:37.328154 IP 185.29.43.134.https > achille.43692: Flags [FP.], seq 2980347197:2980347221, ack 988779763, win 63, options [nop,nop,TS val 4014285248 ecr 1087607705], length 24  16:33:42.345323 ARP, Request who-has achille tell _gateway, length 28  16:33:43.267564 ARP, Request who-has achille tell _gateway, length 28  16:33:44.291484 ARP, Request who-has achille tell _gateway, length 28  16:33:52.893459 IP 185.108.33.7.https > achille.33164: Flags [P.], seq 1790963150:1790965634, ack 3659102388, win 31, options [nop,nop,TS val 2212917620 ecr 1216687482], length 2484  16:33:52.893487 IP 185.108.33.7.https > achille.33164: Flags [P.], seq 2484:2515, ack 1, win 31, options [nop,nop,TS val 2212917620 ecr 1216687482], length 31  16:33:53.812781 ARP, Request who-has achille tell _gateway, length 28  

at 16:33:42 my gateway (on my 3g router) looks unuable to contact my machine (achille) because I have flushed arp table, I keep flushing it so there is no updates sent to the gw. There is no routing to the gw neither (this should prevent my machine broadcasting arp requests?). So the gw is yelling through arp broadcasts but how could she send me 2 packets on port 443 at 16:33:52 (knowing that there is no complete data-link layer connection?

thanx folks!!

gedit External Tools & Csound

Posted: 12 Sep 2021 08:34 AM PDT

I am a newbie at Linux and so far so good my workflow of studying music with Csound is adding a new tool under the External Tools Gedit plugin doing this,

#!/bin/sh  csound '/home/ye53b/Desktop/TC4R37A7B/music/csound'  

which is a text file containing the Csound syntax that later is interpreted as noise...

There is any way to identify the path of the file I am in, instead of using a main text file every time ('/home/ye53b/Desktop/TC4R37A7B/music/csound')?

when using rsync, how to delete target file that is not complete?

Posted: 12 Sep 2021 08:07 AM PDT

I have a hard drive with a few tb capacity and want to distribute all files to multiple smaller disks. So for example 8 tb -> 4 * 2 tb. I thought using rsync with remove-from-source, so successfull transfers are deleted, so I can always see how much is left to copy. When a drive runs full, rsync will eventually stop, I change the drive, and start rsync again, rsync only copies the files that failed previously.

But in my tests I noticed that if a file is transfered that is bigger than the space left, the partial file stills stays there. It is not removed on the origin, but it still exists on the target. That could get confusing later if I have the same file with different sizes.

Can rsync remove the partial failed file from the target? I looked at all the delete options, but none of them seem to do what I want.

Thanks.

Extract first block of consecutively matching lines from a file?

Posted: 12 Sep 2021 08:33 AM PDT

So I have a file like this:

echo 'this line is added for demo purpose'  echo 'do not extract this line and the line above'    #!/usr/bin/env bash  # header: add, replace, and delete header lines.  #   # Example usage:  # $ seq 10 | header -a 'values'  # $ seq 10 | header -a 'VALUES' | header -e 'tr "[:upper:]" "[:lower:]"'  # $ seq 10 | header -a 'values' | header -d  # $ seq 10 | header -a 'multi\nline' | header -n 2 -e "paste -sd_"  #  # See also: body  #    # Author: http://jeroenjanssens.com    usage () {  cat << EOF  header: add, replace, and delete header lines.    usage: header OPTIONS    OPTIONS:  ...  }    # i don't want  # these comments    # even if   # these lines match  

And I want to extract all the lines matching regex ^(#.*)|(\s*)$, from the first line in the file that matches, consecutively to the last line that matches.

The desired result of extraction should be

  #!/usr/bin/env bash  # header: add, replace, and delete header lines.  #   # Example usage:  # $ seq 10 | header -a 'values'  # $ seq 10 | header -a 'VALUES' | header -e 'tr "[:upper:]" "[:lower:]"'  # $ seq 10 | header -a 'values' | header -d  # $ seq 10 | header -a 'multi\nline' | header -n 2 -e "paste -sd_"  #  # see also: body  #  # Author: http://jeroenjanssens.com    

How do I do this?

I think I can extract all consecutively matching lines with regex in multiline mode, but I only want the first part of the match.

Update:

I want regex ^(#.*)|(\s*)$ to match

  • comments with a # at the beginning of the lines
  • empty lines (like the one after # Author)
  • lines only contain empty spaces

File manager that shows the actual path in the location bar after following a link

Posted: 12 Sep 2021 07:00 AM PDT

I'm looking for a Linux file manager that shows the "actual" path (as printed by pwd) in its location/address bar when following a link.

When I open links on my desktop (say in thunar), the location bar shows: /home/Username/Desktop/MyFolder although the linked folder is actually located at: /home/Username/Some/Long/Path/MyFolder

Consequently, the "Open parent folder" button of the file manager, takes me to the desktop rather than to the actual parent folder (/home/Username/Some/Long/Path). I'm looking for a file manager that uses the actual location in its location bar, so that "Open parent folder" takes me to the real parent directory.

I would really appreciate if someone could tell which which (if any) file managers have this feature. I've looked at quite a few but never found what I was looking for. I use various Debian flavours and Fedora, but would be willing to switch to any distribution if required.

Thanks for your help :)

There is no *BSD partition on /dev/sdb. The device (null) does not contain BSD disklabel

Posted: 12 Sep 2021 06:35 AM PDT

I want to add files to my Debian setup USB flash drive and am trying to follow the steps from this answer: https://unix.stackexchange.com/a/559371

However, after successfully writing the image with dd bs=4M if=debian-11.0.0-amd64-netinst.iso of=/dev/sdb conv=fdatasync status=progress && sync, when I want to add the partition with fdisk and then b, I get the following error:

Command (m for help): b  There is no *BSD partition on /dev/sdb.    The device (null) does not contain BSD disklabel.  

This is what the stick looks like:

$ sudo fdisk -l /dev/sdb  Disk /dev/sdb: 7,8 GiB, 8352956416 bytes, 16314368 sectors  Disk model: Flash Disk        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: 0x31114a24    Device     Boot Start     End Sectors  Size Id Type  /dev/sdb1  *        0 6305695 6305696    3G  0 Empty  /dev/sdb2        1476    6701    5226  2,6M ef EFI (FAT-12/16/32)  

What does the error message mean? Where am I doing wrong? How can I add the partition instead?

How to create windows task scheduler in Linux/Unix

Posted: 12 Sep 2021 06:32 AM PDT

I have created a windows batch file script for checking a service & starting it if its in stopped mode than I mapped that script with Windows task scheduler to run in every 5 min with system privileges on that machine.

Below is the batch script.

@Echo Off  Set ServiceName=MYSERVICENAME    SC queryex "%ServiceName%"|Find "STATE"|Find /v "RUNNING">Nul&&(     Net start "%ServiceName%">nul||(                     exit /b 1      )        exit /b 0  )||(      exit /b 0  )  

I dont have much knowledge on Linux/Unix however we can do this by creating some shell script & mapping that script with crontab hence I am looking some help here to create linux/unix script which look for a specific process & if its not running try restating it, also sometime process is not starting because of "processname dead but subsys locked" if we can also include that in script to handle and after that adding script to crontab for running in every 5 min.

Renaming the files and folders using text files

Posted: 12 Sep 2021 10:05 AM PDT

I am trying to rename the files and directories using a text file separated by space.

The files.txt looks like this:

dir1-1 dir1_1  dir2-1 dir223_1  

My command is as follows:

xargs -r -a **files.txt** -L1 mv  

The files look like this (in directory 1):

dir1-1.txt dir1-1.gzip dir1-1-something.text  

The output for the files should look like this (in the dir1-1):

dir1_1.txt dir1_1.gzip dir1_1-something.text  

The files in directory (dir2) looks like this:

dir2-1.py dir2-1.txt dir2-1.text  

The output should look like this:

dir223_1.py dir223_1.txt dir223_1.text  

This command can rename only folders from dir1-1 to dir1_1 and dir2-1to dir223_1so on but it doesn't rename the files in the subdirectories. The files in the corresponding directories also have these prefix of these directories. (like dir1-1.txt dir1-1.gzip dir1-1.csv)

It will be somewhat similar like: Script for renaming files using text file containing alternate file names

Looking forward for the assistance.

How to add files to bootable linux setup ISO image copied to USB flash drive?

Posted: 12 Sep 2021 06:20 AM PDT

I use

dd bs=4M if=debian-11.0.0-amd64-netinst.iso of=/dev/sdc conv=fdatasync status=progress && sync  

to write the debian-11.0.0-amd64-netinst.iso ISO file to my USB flash drive and then I can boot from it and start the setup. However, I want to add some files to the USB flash drive to make them available during setup. How do I do that? The stick is somehow marked read-only and /dev/sdc1 gets mounted as -t iso9660.

# fdisk -l debian-11.0.0-amd64-netinst.iso   Disk debian-11.0.0-amd64-netinst.iso: 377 MiB, 395313152 bytes, 772096 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: 0x3c15dbf8    Device                           Boot Start    End Sectors  Size Id Type  debian-11.0.0-amd64-netinst.iso1 *        0 772095  772096  377M  0 Empty  debian-11.0.0-amd64-netinst.iso2       4060   9243    5184  2,5M ef EFI (FAT-12/16/32)  

Deal with nbsp character in shell

Posted: 12 Sep 2021 08:04 AM PDT

When I use an "alt-gr" character followed by a 'space' character often I miss my input in typing in place of it the "non breaking space character" aka nbsp.

Example with piped commands : mount |<space>tail vs mount |<nbsp>tail The last command will trigger an error ..." tail" command unfindable... (notice the visual space before the tail command's name which is in fact a nbsp character).

So I found a solution which works perfectly in my case, to simply neutralizing the nbsp character :

setxkbmap -option "nbsp:none"  

But this changement gains instantly the whole system and for the proof, in LibreOffice Writer if I want to add a nbsp character between two words which must stay grouped, this does not working.

From past, I lost a lot of time to determine what was the cause of a non working command or a script or a service which does not start, because of that damn character.

So I asked to myself if there is a solution to make the neutralisation limited only to the shell (console, terminal, vty, tty, and so) ? In bash or other shell ...

Could you give me what role this damn nbsp character have in shell ? Where and when using it and for what ? What we loose to not using it ?

Another suggestion : instead of neutralize it can we reveal it by a graphic character with color ?


So based on Kamil's suggestion, I disabled nbsp character from all X environment with setxkbmap because this functionnality do not serve me in nearly 95% of time and for the 5% remaining, I will have to implement a distinct patch for all the applications which need it.

For Libre Office Writer I propose to use the Ctrl-Shift-space to do the replace.

So for the macro (Available here : Tools → Macros → Organize Macros → LOdev Basic → My macros > Standard > Module1 > Edit) :

REM  *****  BASIC  *****    ' Based on : https://ask.libreoffice.org/t/special-characters/1089/3  Sub InsertNBSP          Dim oDoc as variant              oDoc = ThisComponent          Dim oCurrentController as variant              oCurrentController = oDoc.getCurrentController()          Dim oTextViewCursor as variant              oTextViewCursor = oCurrentController.getViewCursor()          Dim oText as variant          If IsEmpty(oTextViewCursor.Cell) Then              oText=oTextViewCursor.Text          Else              oText=oTextViewCursor.Cell.Text          End If          ' NBSP unicode : https://www.compart.com/en/unicode/U+00A0          oText.insertString(oTextViewCursor,chr(clng(&quot;&amp;H00A0&quot;)),false)  End Sub  

Nota : notice that the NBSP unicode code is U+00A0 and furthermore in my case the resulting code is written at $HOME/.config/libreoffice/4/user/basic/Standard/Module1.xba

And for the key bindding (Tools → Customize… → Keyboard), we will use Ctrl-Shift-space to bind with the macro's function named InsertNBSP

Nota : in my case the resulting association is written at $HOME/.config/libreoffice/4/user/registrymodifications.xcu

Start a service when a user log in

Posted: 12 Sep 2021 09:41 AM PDT

I use Jellyfin (a mediacenter like kody). It works as service. But, I don't need it to run everytime.

I created a kid account with custom desktop to make it as safe as possible and I want to start Jellyfin service (as root) ONLY when kid user log in, and stop it when user log out.

I don't want to start service when system start, but only for this user.

I found lots of topics about how to start service AS another user, but not WHEN a user log in.

Many thanks ! :)


Update #1

I can run script when kid user log by editing this file /home/kid/.profile :

[...]    systemctl start jellyfin  

But I have a perms problem. Can I chmod a service to be started by everyone?

Impossible to set A2DP profile on bluetooth headset on Ubuntu 20.04

Posted: 12 Sep 2021 07:06 AM PDT

I know this was asked a lot of times, but honestly I've tried everything that I could find over the internet and still couldn't resolve this.

I am a beginner user of Ubuntu 20.04 and I am having issues setting A2DP profile for a pair of bluetooth headset, and the quality is very bad.

  • I have paired, trusted and connected the headphones via terminal bluetoothctl then pair, trust, connect, didn't work
  • also installed Blueman and did the same process there again with no luck

After this I've tried to:

  • set the profile A2DP firstly from OS GUI that didn't work
  • then I've tried from Blueman but no success here either -> (Failed to change profile to a2dp_sink)
  • installed pavucontrol and tried again from there - in pavucontrol I go to Config tab and in headphone's profile dropdown I can see High Fidelity Playback (A2DP Sink)(unavailable) so of course, I cannot set it here also

I have also checked pacmd list-cards, checked the index of headphones, then pacmd set-card-profile <index> a2dp_sink but I get Failed to set card profile to 'a2dp_sink'.. I've also tried to sudo pacmd set-card-profile <index> a2dp_sink and now I get No PulseAudio daemon running, or not running as session daemon. PulseAudio is installed, I've checked with pulseaudio --version pulseaudio 13.99.1.

I've edited the /etc/bluetooth/audio.conf file and added this line in the end of it: Disable=Headset, this didn't work. I've also tried to add same line in main.conf - no success.

With bluez installed, I've also enabled this line Name = BlueZ in /etc/bluetooth/main.conf, again nothing.

In /etc/bluetooth/main.conf I've also uncommented #MultiProfile = off and changed it to MultiProfile = multiple, nothing happened.

So after mixing all the steps above and restarted bluetooth and re paired headphone a million times, I gave up and I'm writing for help.

Please give any hint on what could be the issue.

Thanks

How to configure an email-forwarding system, usable as "MX" record in DNS

Posted: 12 Sep 2021 09:27 AM PDT

Context: let's say I have the domain example.com, but the registrar doesn't provide an "email forward" system.

How can I configure postfix (or even a simple Python script would be better, because I could customize certain forwarding rules) to use my server of IP 1.2.3.4 as a server that only redirects every mail incoming to *@example.com ("catch-all") to myadress@gmail.com ?

The DNS record would probably be something like:

mx.example.com                   MX     mailforwarder.example.com  mailforwarder.example.com        A      1.2.3.4  

redirecting find standard output as an argument to tar command

Posted: 12 Sep 2021 09:46 AM PDT

$ find playground -name "file_a"  | tar cf - --files-from=- | gzip > playground.tgz  

can't understand why we used both - in cf - alongside with --files-from=-

isn't - rediredting all the standard output to tar cf already ?

Disabling vbox services to decrease boot time

Posted: 12 Sep 2021 08:19 AM PDT

I did a systemd-analyze critical-chain at boot on my system, vanilla Arch running on i3wm.

Now, I also have Virtualbox installed on my system. Therefore, the output from systemd-analyze critical-chain looks like this:

graphical.target @45.620s  └─multi-user.target @45.620s    └─vboxweb-service.service @45.609s +10ms      └─vboxdrv.service @1.645s +43.956s        └─basic.target @1.637s          └─sockets.target @1.637s            └─dbus.socket @1.637s              └─sysinit.target @1.637s                └─sys-fs-fuse-connections.mount @6.422s +3ms                  └─systemd-modules-load.service @348ms +36ms                    └─systemd-journald.socket @340ms                      └─system.slice @327ms                        └─-.slice @327ms  

Note that `vboxdrv.service' takes the longest time, around 43 seconds, which is almost 90% of the total boot time.

My question is: Is it safe to disable both of these services with: systemd disable vboxdrv.service? Then, say whenever I want to run virtualbox, I can just do: systemd start vboxdrv.service?

Why are some Intel family 6 CPU models (Core 2, Pentium M) not supported by intel_idle?

Posted: 12 Sep 2021 10:18 AM PDT

I've been tuning my Linux kernel for Intel Core 2 Quad (Yorkfield) processors, and I noticed the following messages from dmesg:

[    0.019526] cpuidle: using governor menu  [    0.531691] clocksource: acpi_pm: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 2085701024 ns  [    0.550918] intel_idle: does not run on family 6 model 23  [    0.554415] tsc: Marking TSC unstable due to TSC halts in idle  

PowerTop shows only states C1, C2 and C3 being used for the package and individual cores:

          Package   |            CPU 0  POLL        0.0%    | POLL        0.0%    0.1 ms  C1          0.0%    | C1          0.0%    0.0 ms  C2          8.2%    | C2          9.9%    0.4 ms  C3         84.9%    | C3         82.5%    0.9 ms                        |            CPU 1                      | POLL        0.1%    1.6 ms                      | C1          0.0%    1.5 ms                      | C2          9.6%    0.4 ms                      | C3         82.7%    1.0 ms                        |            CPU 2                      | POLL        0.0%    0.1 ms                      | C1          0.0%    0.0 ms                      | C2          7.2%    0.3 ms                      | C3         86.5%    1.0 ms                        |            CPU 3                      | POLL        0.0%    0.1 ms                      | C1          0.0%    0.0 ms                      | C2          5.9%    0.3 ms                      | C3         87.7%    1.0 ms  

Curious, I queried sysfs and found that the legacy acpi_idle driver was in use (I expected to see the intel_idle driver):

cat /sys/devices/system/cpu/cpuidle/current_driver  

acpi_idle

Looking at the kernel source code, the current intel_idle driver contains a debug message specifically noting that some Intel family 6 models are not supported by the driver:

if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && boot_cpu_data.x86 == 6)      pr_debug("does not run on family %d model %d\n", boot_cpu_data.x86, boot_cpu_data.x86_model);  

An earlier fork (November 22, 2010) of intel_idle.c shows anticipated support for Core 2 processors (model 23 actually covers both Core 2 Duo and Quad):

#ifdef FUTURE_USE      case 0x17:  /* 23 - Core 2 Duo */          lapic_timer_reliable_states = (1 << 2) | (1 << 1); /* C2, C1 */  

No comments:

Post a Comment