Sunday, August 1, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Can I force router changes from linux CLI, like port forwarding with UPNP?

Posted: 01 Aug 2021 10:18 AM PDT

I have seen that I can use miniupnp to apply port forwarding on my router, and I would like to find another tool to apply DNS and/or DHCP settings on the router. Is this possible?

My goal is to have a script that once executed, it configures a VPN and DNS on my server, and also configures the router accordingly ( VPN port forward and DNS pointing to my LAN server ) without any user intervention.

Thank you for your help!

how to make average independent in java project

Posted: 01 Aug 2021 10:14 AM PDT

i have many project in mysql, i am calucalting avera and average of first product affect all product,

ResultSet rs = localStat.executeQuery("SELECT * FROM (SELECT * FROM tablename ORDER BY id DESC) AS data GROUP BY productname ");          while (rs.next()) {      String str4 = rs.getString("productname ");      int i = rs.getInt("Tradata");      int t = rs.getInt("tra_tot");                 ResultSet rs1 = localStat2.executeQuery("SELECT productname,avg(Tradata) as average FROM (SELECT * FROM tablename ORDER BY id DESC) AS data GROUP BY productname");        while (rs1.next()) {          j = rs1.getInt("average");       }                   int k = 1;      if (i < j) {          k = j - i;             }        ResultSet rs3 = localStatement2.executeQuery("SELECT * FROM (SELECT * FROM talename ORDER BY id DESC) AS data GROUP BY productname  ");      int m = 1;      int n = 0;      int i1 = 0;      while (rs3.next()) {          n += 1;      }        rs3 = localStatement2.executeQuery("SELECT * FROM (SELECT * FROM talename ORDER BY id DESC) AS data GROUP BY productname ");               while (rs3.next()) {          if (m == n / 2) {              i1 = rs3.getInt("Tradata");          }            if (m == n / 2 + 1) {              i1 = i1 + rs3.getInt("Tradata");          }          m += 1;        }               k = i1 - i;              if (i < i1) {          System.out.println(localSimpleDateFormat.format(data) + "data decreasing "+((k * 100) / i1) + "%  (" + k + ") average(" + i1 + ") in " + str4);      }  }  

output of this code is:

data decreasing 99%  (303) average(305)  data decreasing 91%  (278) average(305)   data decreasing 8%  (27) average(305)   data decreasing 100%  (305) average(305)   data decreasing 100%  (305) average(305)   

please someone may help me.

Pop!_OS not recognising partitions and how to solve this without formatting

Posted: 01 Aug 2021 09:40 AM PDT

I am trying to dual boot pop!_os with windows 10 but the pop os is not recognising the partitions. I have also turned the sata mode from rst with optane to AHCI. This is the error message it gives "Could not stat device /dev/mapper/isw: untested metadata version 1.4.01 found on /dev/sda - No such file or directory" I have made a 50 gb partition already. I have seen a similar question to this one but that you had to format the disk but i already have important data on my harddisk. So is there a way to do this without formatting the whole hard disk.

debugfs not working | file not found by ext2_lookup

Posted: 01 Aug 2021 08:57 AM PDT

$sudo blkid  /dev/sda1: UUID="F959-61DE" TYPE="vfat" PARTUUID="950b18a0-1501-48b4-92ef-ba1dd15aaf21"  /dev/sda2: UUID="6dfcfc23-b076-4eeb-8fba-a1261b4ea399" TYPE="ext4" PARTUUID="ddc69ee8-40b0-49c9-9dcb-0b9064caca7d"  /dev/sda3: UUID="fec0af18-d28e-4f2a-acb7-6380ddee3dc2" TYPE="ext4" PARTUUID="e19628dc-c04a-4c9d-a3c6-469511e89480"  /dev/sda4: UUID="a6f7669b-6e86-432a-b91c-f39780c849ac" TYPE="swap" PARTUUID="e45cf647-3d78-4fea-a950-022a3ae9b4e0"  /dev/sda5: UUID="5a75937f-8a83-44a9-b5c5-502b7e3884f2" TYPE="ext4" PARTUUID="3e086aff-105f-48b3-a384-1eb1d18c6fb3"  /dev/sda6: UUID="04460cd2-a1bb-4a3e-94df-1ad10080f356" TYPE="ext4" PARTUUID="d37fdea8-a386-4f6f-8016-fa2764a71b60"  

$pwd  /home/milad  

$touch a  $ls -i a  3935203 a  

$sudo /sbin/debugfs/ -R 'stat 3935203' /dev/sda6  debugfs 1.44.5 (15-Dec-2018)  3935203: File not found by ext2_lookup   

How to get birth date my file in ext4 partition drive?

Thanks for helping

how to print the files name of a folder as file in tabulary way

Posted: 01 Aug 2021 09:57 AM PDT

i have some files in a folder and i want to print thier names in one file.txt in tabulary way like a text not one under one , is there any command for that ?

dd1.txt dd2.txt dd3.txt dd5.txt  

xfs uses more space than it has stored in files

Posted: 01 Aug 2021 08:19 AM PDT

Why do I see more "used" space in df than in du?

$ grep bk0092 /etc/fstab  UUID=c614803f-49da-4eda-aeb1-c9b3e0056e73   /repo/bk0092  xfs   defaults  0 0    $ df -h /repo/bk0092/  Filesystem      Size  Used Avail Use% Mounted on  /dev/sdb1       1.0T   12G 1012G   2% /repo/bk0092    $ du -sh /repo/bk0092/                       7.8G    /repo/bk0092/  

This filesystem has reflinks active, they also seem to work. As I understood, in this case, it should show up less used space in df than in du, because reflinks saved space which is not used on disk. But files are still "full-sized", and du should see that.

What is wrong? Or how can I see where this space is consumed?

IP forwarding in linux namespaces

Posted: 01 Aug 2021 10:13 AM PDT

I am currently trying to simulate a network using network namespaces under Linux. I have already set up the nodes and connected them, and they can ping each other, one hop at a time. But I am really struggling trying to enable IP forwarding.

I am using Ubuntu Server 21.04 and networking on my system is controlled by systemd-networkd. systemd's version is 247.3-3ubuntu3.4. net.ipv6.conf.all.forwarding and net.ipv4.ip_forward are already enabled. Because networkd is used, forwarding has to be enabled in configuration files additionally. For one of my namespaces, this looks as follows:

/etc/systemd/network/router1i.network:

[Match]  Name=router1i    [Network]  IPForward=yes  

and /etc/systemd/network/router1i2.network:

[Match]  Name=router1i2    [Network]  IPForward=yes  

Those (router1i and router1i2) are both veth interfaces and the only 2 interfaces in the namespace.

If I use the command ip -6 route get to fe80::1:0:200 iif router1i2 in the namespace, I get the correct answer fe80::1:0:200 from :: dev router1i2 proto kernel metric 256 iif router1i2 pref medium, because the route doesn't involve forwarding. If I use the similar command ip -6 route get to fe80::1:0:200 iif router1i, that starts from the other interface, the answer suddenly is RNETLINK answers: Network is unreachable. So apparently, forwarding isn't enabled.

I already tried to get networkd to update by using networkctl reconfigure router1i from within the namespace, but it says Failed to reconfigure network interface router1i: No such device or address. This is strange, because when I use networkctl status router1i, it lists all the information correctly. A full reload using networkctl reload was also already tried and doesn't change anything.

I'm honestly pretty much at my wit's end. I don't even necessarily need to get it to work with networkd. Any idea or workaround would be very much appreciated.

VirtualBox WSL2 file sharing from Debian

Posted: 01 Aug 2021 07:48 AM PDT

I have Windows 10 as a primary OS and there is installed VirtualBox with Debian Buster.

I use WSL2 and I would like to see files from this virtual PC in folder \\wsl$. It works automatically when I use Debian from Windows Store. Is it even possible to use it like this for VirtualBox?

Thank you.

Different ways to download and install an application in Fedora

Posted: 01 Aug 2021 08:05 AM PDT

I want to know what are the different ways to install an application in Fedora based systems. One is downloading a .rpm package of the application from its site and double clicking will install it.

There are various other ways to download/install using terminal and I'm a new user of Linux ,using Fedora 34. Please help.

/etc/localtime is not a symbolic link

Posted: 01 Aug 2021 07:42 AM PDT

According to localtime from Linux manual page:

It should be an absolute or relative symbolic link pointing to /usr/share/zoneinfo/, followed by a timezone identifier such as "Europe/Berlin" or "Etc/UTC".

It's the output of ls -la /etc/localtime in my environment:

-rw-r--r--. 1 root root 724 Apr  3  2012 /etc/localtime  

and for cat /etc/localtime

TZif2їԒazpҹӂ­𔘺ԣ౗<¿ֆfpם����𛽦܈̰ݠYݪ𝱳ߵdp𿼅ᖗ𡝸⸋p⿬㮠p䠱咥p悤鴘𪤘                                                      따                                                        셀촿𮸼𰗯퉰  ݉   ν𒙐S𾿁~pCDTCSTTZif2)                     ÿÿÿÿtϰÿÿÿÿїԿÿÿÿѡzpÿÿÿÿҹÿÿÿÿӂ­����ÿԚ:ÿÿÿÿԣ౿ÿÿÿռ¿ÿÿÿÿֆfpÿÿÿÿם����ÿÿڧ����ÿۿ&ÿÿÿÿ܈̰ÿÿÿÿݠYÿÿÿÿݪ����ÿݲsÿÿÿÿߵdpÿÿÿÿ𿼅ÿÿÿÿᖗ����ÿ᝸ÿÿÿÿ⸋pÿÿÿÿ⿬ÿÿÿÿ㮠pÿÿÿÿ䠱ÿÿÿÿ咥pÿÿÿÿ悤ÿÿÿÿ鴘����ÿꤘÿÿÿÿ      따ÿÿÿÿ            셀ÿÿÿÿ촿����ÿÿÿÿÿ����ÿ𐗯ÿÿÿÿ퉰 ݉   ν𒙐S𿿂q羐LMTCDTCST  CST-8  

My environment is Fedora 17 running on VirtualBox.

I copied the entire image from someone else. In other words, I didn't build the environment from scratch.

I'm afraid of that it's a truly mistake, or it's made for some reason.

Find XML file with specific path

Posted: 01 Aug 2021 08:27 AM PDT

I'm working with XML files, each of which could be dozens of lines long. There are literally hundreds of these files, all over a directory structure. Yes, it is Magento.

I need to find the file that has the <foo><bar><boom><bang> element. A <boom><bang> tag could be defined under other tags, so I need to search for the full path not just the end tag or tags. There could be dozens of lines between each tag, and other tags between them:

<foo>    <hello_world>  ... 50 lines ....    </hello_world>    <bar>      <giraffe>  ... 50 lines ....      </giraffe>      <boom>        <bang>Vital information here</bang>      </boom>    </bar>  </foo>  

What is the elegant, *nix way of searching for the file that defines <foo><bar><boom><bang>? I'm currently on an up-to-date Debian-derived distro.

This is my current solution, which is far from eloquent:

$ grep -rA 100 foo * | grep -A 100 bar | grep -A 100 boom | grep bang | grep -E 'foo|bar|boom|bang'  

Finding files and matching patterns with printed filename in bash

Posted: 01 Aug 2021 08:24 AM PDT

I have the following code that lists matches far a pattern ptrn, with the filename being printed before the listing (which uses the context option -C NUM)

find "$fdir" "${isufx[*]}" -type f -exec bash -c  \    "grep --color -l '$ptrn' '{}'; grep --color -ni ${ictx[*]} '$ptrn' '{}'" \;  

I agree it's a monster. I decided to remove the bash -c call, resulting in

  OFS=$IFS    IFS=$'\n'    for f in $(find "$fdir" ${isufx[*]} -type f); do      grep -l "$ptrn" "$f" && grep -ni ${ictx[*]} "$ptrn" "$f"    done    IFS=$OFS  

Any suggestions on the above? I would like to print the filename before the listing, enclosed between ==> and <==, with an empty line above and below the filename.

After suggestions about avoiding looping over find's output, I have:

  find "$fdir" ${isufx[*]} -type f |      while read f; do        grep -l "$ptrn" "$f" && grep -ni ${ictx[*]} "$ptrn" "$f"      done  

sequence output

Posted: 01 Aug 2021 08:17 AM PDT

#!/bin/ksh  for i in `seq 1 10` ; do    n=`expr $RANDOM`;    (      for (( k=1; k<=10; k++ ))      do        echo -n "$k"      done    )    echo   "$k, $n"  done  

I have written this script, but not getting exact output

12345678910, 17517  12345678910, 3695  12345678910, 8841  12345678910, 11553  12345678910, 2019  12345678910, 3503  12345678910, 25789  12345678910, 24825  12345678910, 8039  12345678910, 30532  

while i need it as 1-10 with side by side random number

How do I install the driver of Medaitek RT3070 in Debian Linux?

Posted: 01 Aug 2021 07:33 AM PDT

I didn't understand the build instructions and the "make" command returns errors:

┌──(**mohammedmehditber㉿DESKTOP-U9KKGTJ**)-[**~/Downloads/DPO_RT5572_LinuxSTA_2.6.1.3**  _20121022]   └─**$** sudo make **&&** sudo make install   make -C tools   make[1]: Entering directory '/home/mohammedmehditber/Downloads/DPO_RT5572_LinuxS  TA_2.6.1.3_20121022/tools'   gcc -g bin2h.c -o bin2h   make[1]: Leaving directory '/home/mohammedmehditber/Downloads/DPO_RT5572_LinuxST  A_2.6.1.3_20121022/tools'   /home/mohammedmehditber/Downloads/DPO_RT5572_LinuxSTA_2.6.1.3_20121022/tools/bin  2h   cp -f os/linux/Makefile.6 /home/mohammedmehditber/Downloads/DPO_RT5572_LinuxSTA_  2.6.1.3_20121022/os/linux/Makefile   make -C /lib/modules/5.10.0-kali9-amd64/build SUBDIRS=/home/mohammedmehditber/Do  wnloads/DPO_RT5572_LinuxSTA_2.6.1.3_20121022/os/linux modules   make[1]: Entering directory '/usr/src/linux-headers-5.10.0-kali9-amd64'   /usr/src/linux-headers-5.10.0-kali9-common/Makefile:225: =============== ERROR =  =============   /usr/src/linux-headers-5.10.0-kali9-common/Makefile:226: 'SUBDIRS' was removed i  n Linux 5.3   /usr/src/linux-headers-5.10.0-kali9-common/Makefile:227: Use 'M=' or 'KBUILD_EXT  MOD=' instead   /usr/src/linux-headers-5.10.0-kali9-common/Makefile:228: =======================  =============   /usr/src/linux-headers-5.10.0-kali9-common/Makefile:229: *** .. Stop.   make[1]: *** [/usr/src/linux-headers-5.10.0-kali9-common/Makefile:185: __sub-mak  e] Error 2   make[1]: Leaving directory '/usr/src/linux-headers-5.10.0-kali9-amd64'   make: *** [Makefile:389: LINUX] Error 2  

How can I verify the clocksource in my system?

Posted: 01 Aug 2021 07:27 AM PDT

According to the kernel code, timekeeping will initialize the clocksource as jiffies.

/*   * timekeeping_init - Initializes the clocksource and common timekeeping values   */  void __init timekeeping_init(void)  {  ...  clock = clocksource_default_clock();  ...  }    struct clocksource * __init __weak clocksource_default_clock(void)  {      return &clocksource_jiffies;  }  

But it also says that once a new clocksource detected, timekeeping will replace it.

/**   * timekeeping_notify - Install a new clock source   * @clock:      pointer to the clock source   *   * This function is called from clocksource.c after a new, better clock   * source has been registered. The caller holds the clocksource_mutex.   */  

Now I know that when I input command "date" it will eventually get the system time from clocksource. I want know that which clocksource am I using then, is that jiffies?

How to expand code snippets in GNU nano?

Posted: 01 Aug 2021 08:17 AM PDT

In most text editors, it is possible have "code snippets" you can expand by typing a keyword and pressing the tabulation key.

As an example, a snippet for LaTeX might look like

\begin{$1}      $2  \end{$1}  

However I found nothing in the nano man page nor on the web. Is there some hacky way to achieve that? One idea might be to have some bash function nano-latex-begin or something taking two arguments and then to ask GNU nano to execute it but the process would be rather slow.

Getting Specific Ethernet Statistics

Posted: 01 Aug 2021 08:50 AM PDT

Is there any way to get rx_broadcast value from /sys/class/net/<intf>/..?

I am using the following commands ETHTOOL_GSTATS and SIOCETHTOOL for IOCTL to get the ethernet statistics, but I am interested in some script which reads the values from /sys/class/net

I looked into /sys/class/net/..., but could not find any entry.

How to align the output generated in a shell "for" loop by columns

Posted: 01 Aug 2021 07:25 AM PDT

I'm trying to align output from a bash for loop.

Currently, I'm getting output from my loop that looks like so:

Directory:  /some/long/directory/path  Remote:  some-remote  Directory:  /some/dir/path  Remote:  other-remote  

Which I'm trying to align like so:

Directory:  /some/long/directory/path  Remote:  some-remote  Directory:  /some/dir/path             Remote:  other-remote  

The current, basic loop that generates this output looks something like this:

for dir in $(find /some/path -type d -name .git); do      cd $dir      remote=$(git remote)      printf "Directory: $dir\tRemote: $remote\n  done  

I've tried using:

  • column (which formats each line separately, as it's a for loop)
  • printf (printf "Directory: %s Remote: %s\n" "$dir" "$remote")
  • awk (echo "Directory: $dir Remote: $remote" | awk '{printf ("%s-20s %s-20s %s-20s %s-20s",$1 $2 $3 $4)}')

Among many other variations of these commands.

I'm probably missing something basic (I tried my best at looking at other examples online and reading the man pages), but I couldn't get it to work.

I'd really appreciate any pointers as to what I'm doing wrong.

Automating the splitting of a large mp3 file with FFmpeg into multiple files in different time points provided in a text file

Posted: 01 Aug 2021 07:22 AM PDT

I have a large mp3 file; I want to split it into 480 mp3 files in different time points. I want to know if there is an easy way to do it other than splitting it one by one. Can I provide the different splitting times in a text file and just execute one command in FFmpeg?

Sun Type 7 Keyboard + KDE shortcuts: Why does the control center ignore most of the function keys on the left edge?

Posted: 01 Aug 2021 09:29 AM PDT

I've recently equipped my OpenSuSE 15.2 with KDE 5 with a Sun Type 7 keyboard and now would like to use the function keys on its left edge for a variety of system-wide shortcuts. The only issue is that in the shortcut list of KDE's control center, some of these keys are simply ignored:

Shortcut key selector

The Help, Cut, Copy, Paste, and Open keys are recognised as such, whereas Cancel, Redo, Undo, Properties, Foreground, and Find are not, and I don't know why. All of them emit their own scancodes, and xkb maps them to the corresponding key symbols. Here is, for instance, what the Properties key emits (output from xev):

KeyPress event, serial 40, synthetic NO, window 0x7800001,      root 0x561, subw 0x0, time 3103717, (-256,541), root:(1374,570),      state 0x10, keycode 138 (keysym 0x1005ff70, SunProps), same_screen YES,      XLookupString gives 0 bytes:       XmbLookupString gives 0 bytes:       XFilterEvent returns: False  

What's wrong with these keys? Here is my xkb config for your reference:

╭─jacek@epica ~    ╰─➤  setxkbmap -verbose 10  Setting verbose level to 10  locale is C  Trying to load rules file ./rules/evdev...  Trying to load rules file /usr/share/X11/xkb/rules/evdev...  Success.  Applied rules from evdev:  rules:      evdev  model:      pc102  layout:     de  variant:    pl  options:    terminate:ctrl_alt_bksp,altwin:meta_win,lv3:ralt_switch,compose:menu  Trying to build keymap using the following components:  keycodes:   evdev+aliases(qwertz)  types:      complete  compat:     complete  symbols:    pc+de(pl)+inet(evdev)+terminate(ctrl_alt_bksp)+altwin(meta_win)+level3(ralt_switch)+compose(menu)+terminate(ctrl_alt_bksp)  geometry:   pc(pc102)  

UPDATE: I've looked into the current xkb config to find out that in the symbols/inet file, there is a complete block devoted to the proprietary Sun Type 6/7 function keys:

partial alphanumeric_keys  xkb_symbols "evdev" {      key <MUTE>   {      [ XF86AudioMute         ]       };      key <VOL->   {      [ XF86AudioLowerVolume  ]       };      key <VOL+>   {      [ XF86AudioRaiseVolume  ]       };      key <POWR>   {      [ XF86PowerOff          ]       };      key <STOP>   {      [ Cancel                ]       }; // KDE ignores me!      key <AGAI>   {      [ Redo                  ]       }; // KDE ignores me!      key <PROP>   {      [ SunProps              ]       }; // KDE ignores me!      key <UNDO>   {      [ Undo                  ]       }; // KDE ignores me!      key <FRNT>   {      [ SunFront              ]       }; // KDE ignores me!      key <COPY>   {      [ XF86Copy              ]       };      key <OPEN>   {      [ XF86Open              ]       };      key <PAST>   {      [ XF86Paste             ]       };      key <FIND>   {      [ Find                  ]       };      key <CUT>    {      [ XF86Cut               ]       };      key <HELP>   {      [ Help                  ]       };      key <LNFD>   {      [ Linefeed              ]       };  };  

This means that the keycodes and symbols are registered in xkb the right way, but unfortunately, it's KDE's control center, which ignores the Sun-specific keysyms (see the comments above). Does that mean that I'll have to file a ticket with the KDE guys?

recompile wpasupplicant Debian package with IPv6 disabled

Posted: 01 Aug 2021 07:25 AM PDT

I have a related question, but was asked to open a new one.

I would like to recompile the Debian package wpasupplicant with IPv6 disabled. I know basics of Debian package compilation, ie:

apt-get source wpasupplicant  dpkg-buildpackage --build=binary --no-sign  

What do I have to change, to disable IPv6 completely?

Also, this particular package seems to want to compile some qt versions of wpasuplicant, because the compialtion dependencies ask for qtbase5-dev .

Can I compile only the pure/commandline version of wpasupplicant, without any gui versions? I don't want to install additional unnecessary dependencies.

I am using Debian 10.

wpa_supplicant: disable IPv6

Posted: 01 Aug 2021 07:23 AM PDT

I don't have support for IPv6 on my system, and I am only using IPv4. My wpa_supplicant logs are flooded with following error messages:

wpa_supplicant[3370]:  nl80211: Failed to open /proc/sys/net/ipv6/conf/wlan0/drop_unicast_in_l2_multicast: No such file or directory  wpa_supplicant[3370]:  nl80211: Failed to set IPv6 unicast in multicast filter  

which in itself would be harmless, but makes it difficult to actually find other useful messages.

How can I tell wpa_supplicant to only use IPv4 and not try to configure IPv6?

move boot partition of proxmox (or debian) to USB flash, installed on two disk zfs-raid-1 non-bootable nvme

Posted: 01 Aug 2021 07:58 AM PDT

I am trying to setup proxmox on Dell r720xd, which does have UEFI boot option but can not boot from PCIe nvme drives.

If I install proxmox (or any os) on a usb flash, it boots fine.

For testing, I installed CentOS with advanced partitioning, and used USB flash as /boot partition, and nvme for all other partitions and that too works flawlessly.

With proxmox, there is no custom partitioning option during the setup, so I was unable to set usb key as /boot partition during install.

Other option listed in proxmox forums are

  • use clover as bootloader on a USB key, described here
  • install debian first with custom partition and then install proxmox over it and remove debian kernel.

Obviously clover is adding a boot partition on usb and then forwarding the control to nvme.

My question is, how to install proxmox on nvme and then migrate the /boot partition to the usb flash?

Seems like a very straight forward process and I followed this guide to handle it, however, I could not get it to work. grub2 always complained with messages like

  • not matching UUID
  • you need to load kernel first
  • and so on

any hints please. P.S. I also tried to edit the centos /boot installed on flash drive, by using grub2-mkconfig which found the proxmox and updated the grub.cfg but still got errors during boot like

  • error: cant't find command linux
  • error: cant't find command initrd fixed these errors (ref) by linuxefi and initrdefi but then it could not find the drive with given UUID

Save cached video on firefox?

Posted: 01 Aug 2021 09:03 AM PDT

I found a script on the internet that allows me to save cached flash files.

https://github.com/janosgyerik/shellscripts/blob/master/bash/save-flash-linux.sh

This would allow me to run the command saveflash in a terminal to list flash videos and filesizes. And then I could run something like saveflash -n 2 nameofvideo.mp4 to save it. I even added the capability to demux the audio out of the video.

I'm trying to do the same for non-flash videos that are cached by firefox. I would like a command, or set of commands that I can run to list the video files and then save them.

It's a little more convoluted. I have to use lsof to list open files, find ones that have a suitable filesize and then get the proc and fd to use for the copy command.

Right now, I do it manually, running a command like this:

lsof -c firefox | grep -i deleted  

The lsof command takes a few seconds to complete. And then I have to manually put together the copy command based on what the lsof command says that the pid and fd of the file is, then I would do a command like:

cp /proc/3164/fd/55 "~/Videos/Name of Video.mp4"  

What's the best way to speed up/simplify this process? I'd like to make it into a script eventually.

how to use lynx to "print" a web page? WYSIWYG

Posted: 01 Aug 2021 10:00 AM PDT

When I printed a page, as per the manual:

Printing, Mailing, and Saving rendered files to disk.

Rendered HTML documents, and plain text files, may be printed using the 'p' command while viewing the document. After pressing the 'p' key a menu of Print Options will be displayed.

It displayed quite differently when viewed again, from how lynx rendered it when browsing. The page is served from an IP phone, a Cisco/Linksys SPA 942 hard phone, which displays its settings through a web interface.

I just want to grab/crawl/scrape the settings page in the easiest way possible from lynx. I'm after, in particular, the settings for one of the extensions, so I have to click a few links to get to the right setting.

I tried the "print" option, but the formatting was very wrong. It's a simple web page, just forms. The print option jumbled everything together.

I could do a screen print from Firefox, but thought lynx might have some special capability here? Or, perhaps, just save page in Firefox, or some variant...

The page is quite long, so copying one "page" at a time from the terminal is clumsy. All in all, between the different settings, there are probably twenty pages, each twenty lynx "pages" long in the terminal.

Some version of dump with crawl to output them to file?

Printing to the "printer attached to the vt100 terminal" actually did quite well. As literally as possible "printed" to the terminal with just a small hiccup that it had trouble going past some empty fields -- but "page down" seemed (?) to work. Unfortunately, not able to print the actual page I'm after, can't seem to "click" a specific link...

dd script with timings

Posted: 01 Aug 2021 08:06 AM PDT

Trying to figure out the best approach to a script that will do the following:

  1. Create a loop script that creates a 10GB file using dd where, upon completion, removes the file, then repeats 25 times or if CTRL+C is typed before the script gets the chance to exit.
  2. At the end of each operation, i.e. dd, then rm, time it so we know exactly how long dd and rm took

So far, I'm thinking something along these lines:

for i in {1..25}    do      time sh -c "dd if=/dev/zero of=/user/home/test.img bs=10G count=1" >> /tmp/dd_timed.txt && time sh -c "rm -f /user/home/test.img" >> rm_timed.txt  done  

Anyone have a better solution or could maybe tweak this a bit?

blockdev --setro doesn't work (for me at least)

Posted: 01 Aug 2021 08:15 AM PDT

I'm sure I don't understood how blockdev works.

I have mounted a flash drive and it was mapped to /dev/sdb1. Then I type in a terminal (as root):

root# blockdev --setro /dev/sdb1  root# blockdev --report  

the report was:

enter image description here

as you can see, the report said that /dev/sdb1 is set to read-only (ro). But I'm still able to create files and folders in the flash drive.

What I'm missing?

Unix/Linux undelete/recover deleted files

Posted: 01 Aug 2021 09:35 AM PDT

Is there a command to recover/undelete deleted files by rm?

$ rm -rf /path/to/myfile  

How can I recover myfile? If there is such a tool how can I use it?

How to make Fedora user a sudoer?

Posted: 01 Aug 2021 10:03 AM PDT

I want to give a Fedora user sudo privileges. How do I do that?

No comments:

Post a Comment