Thursday, April 15, 2021

Recent Questions - Unix & Linux Stack Exchange

Recent Questions - Unix & Linux Stack Exchange


Why does moving a directory containing a python venv break that venv?

Posted: 15 Apr 2021 10:11 AM PDT

This seems to consistently happen to me, where if I move a project directory the virtual environment can no longer find pip. Why does this happen? Is this expected? I'm running Arch Linux and Python 3.9.3.

➜  mkdir testdir  ➜  cd testdir   ➜  python -m venv venv  ➜  source ./venv/bin/activate  (venv) ➜  pip install beautifulsoup4  Collecting beautifulsoup4    Using cached beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)  Collecting soupsieve>1.2; python_version >= "3.0"    Using cached soupsieve-2.2.1-py3-none-any.whl (33 kB)  Installing collected packages: soupsieve, beautifulsoup4  Successfully installed beautifulsoup4-4.9.3 soupsieve-2.2.1  WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available.  You should consider upgrading via the '/home/mas/testdir/venv/bin/python -m pip install --upgrade pip' command.  (venv) ➜  deactivate  ➜  cd ..  ➜  mv  testdir movedir    renamed 'testdir' -> 'movedir'  ➜  cd movedir   ➜  source ./venv/bin/activate  (venv) ➜  pip install requests  zsh: command not found: pip  

How to fix Could not contact SSH agent: ssh: unmarshal error for field Format of type wireKey

Posted: 15 Apr 2021 10:09 AM PDT

Using Ubuntu 18, I'm not able to connect to a remote cloud service (SymfonyCloud) either to export a psql database or to connect to the remote database (via a CLI tool). When running the required command, I still get the following error:

ceo@iSTech:~/projects/guesbook$ symfony db:dump > database.sql 15/04 17:51:12 ERROR ssh Could not contact SSH agent: ssh: unmarshal error for field Format of type wireKey

I use to do some ssh configuration - please notice that I really don't master it well - in the past in order to use ssh authentication with my GitLab account; I don't know whether I missbehave when doing this configuration... I don't know how to discard every thing or I fear to make it become worest.

Why doesn't GNOME have a hibernate button?

Posted: 15 Apr 2021 09:58 AM PDT

What justification is there for GNOME refusing to implement a hibernation button in the power menu the same way that other desktop environments such as plasma have done? I know you can install an extension to add a hibernate button or simply hibernate from the terminal but I feel that such a basic function should be part of the desktop environment.

Am I really being that unreasonable?

Are there any plans in place for mainstream distributions (e.g., Ubuntu, CentOs, etc.) to switch /bin/python to point to /bin/python3?

Posted: 15 Apr 2021 09:40 AM PDT

I use Arch so it's kind of a pain point when mucking around in servers (not a big deal, obviously, just something I have to keep in mind) and now that Python2 is no longer maintained, I've been doing a bit of research about whether there's any broad movement to deprecate the use of /bin/python to point to /bin/python2.

I've found this decent answer on askubuntu.com but it's rather out of date and so are the links.

The Ubuntu Python page says nothing about this re-aliasing.

Debian's Wiki says

NOTE: Debian testing (bullseye) has removed the "python" package and the '/usr/bin/python' symlink due to the deprecation of Python 2. No packaged scripts should depend on the existence of '/usr/bin/python': if they do, that is a bug that should be reported to Debian. You can use the 'python-is-python3' or 'python-is-python2' packages to restore an appropriate '/usr/bin/python' symlink for third-party or legacy scripts.

I'm not running Debian currently so I can't check, has Debian transitioned but Ubuntu hasn't? (As of 20.04 python -V still says 2.7). I will admit I'm a bit fuzzy on the difference between /usr/bin and /bin and have found this decent explanation that I will shortly be reading.

The (considerably out of date) Ubuntu Python/3 page says that there is an ongoing project to make make python3 the default, but that /bin/python will not change to /bin/python3 until there is a PEP that updates PEP 394. (I believe that might answer my question about Debian.)

The most recent update on the subject I can find is from an LWN article from 2/2019 titled Revisiting PEP 394

The eventual intent, at least according to a comment by Guido van Rossum on an earlier PR, is that python won't actually point anywhere because it won't exist; users will need to explicitly choose either python2 or python3. That is part of what Viktorin's PR is aiming for as well. He wants to make two changes to the PEP: allow installing a "python" (or, an "unversioned Python", as he calls it) to be optional for a distribution and to recommend that scripts supporting both Python 2 and Python 3 use python3 in their shebang lines. That last is a bit counterintuitive, since it means that those scripts will really only run under Python 3, regardless of their ability to run under either version. It is, Viktorin said, "the least bad option".

...

As he did at the language summit, Matthias Klose represented the Debian and Ubuntu Python packagers in the thread. He described the plans for unversioned Python; for Debian, python is never planned to point to Python 3, while Ubuntu has not made a final decision, but it currently does not install an unversioned Python. Debian will continue to have python point to Python 2 until it no longer ships Python 2, then remove it entirely. Klose is trying to ensure that, for upcoming distribution releases starting in 2020 or 2021, Python scripts in both Debian and Ubuntu packages use explicit shebang lines.

This says that Rossum is aiming to suggest deprecating /bin/python altogether, and the plan for Debian is to wait until Debian drops Python2 altogether (what's the status on that?) and then just deprecate /bin/python (or am I misunderstanding, because it also says Debian never plans to point python to python3). The suggestion that Ubuntu doesn't ship an unversioned Python doesn't make sense to me (I can definitely type python -V and have it print 2.7 without doing anything special.

I'm hoping there's some community members with a bit more insight than this 2+ year old article, though I grant it seems this is a very slow moving issue. It just seems crazy to me that in 2021, Python2 being EOLed for over a year now, we're still treating it as the default on most systems. Most new users are probably surprised that typing python on most systems would mean they were using deprecated software.

I do understand that this is a very difficult change, considering the insane number of legacy scripts that must be in operation on servers (obviously) not running Arch Linux. It's a simple fix to change #!/bin/python to #!/bin/python2 but judging from how most companies treat legacy software I imagine it's a bit more onerous than popping a script open in an editor and adding a 3.

Checking if a command would be allowed by a sudoers file

Posted: 15 Apr 2021 09:19 AM PDT

I have some slightly tricky requirements for commands that should and shouldn't be allowed by sudo. I would like to check a prospective sudoers file against a test vector of should-be-allowed/disallowed commands. How can I do this most simply, ideally without touching the host machine's configuration or needing superuser?

Manjaro Gnome version 40.0.0 Post Upgrade Persistence problem

Posted: 15 Apr 2021 08:55 AM PDT

Manjaro updated itself as usual a few Days ago and from that moment onward all persistence is gone.

I leave my Laptop and return and wake the Machine from it's Automatic sleep to find everything (unsaved Work), has disappeared and any YouTube videos I was watching have also gone. It's as though I have restarted with a new Boot up. I am unable to pickup where I left off.

I've done loads of differently worded searches on DuckDuckGo which return the same unhelpful results about creating a Bootable USB Stick without any of the Persistence related information I am looking for.

I did searches on my Local Machine that turned up a big list of files marked "Persistence".

My question is:

Which one of these files found needs some kind of adjustment and how do I safely adjust the file without Bricking my Machine?

I have no clue what I'm looking at or what to do.

Am I even asking the correct question?

I even looked at the Power Management Settings, no hints there either.

Has anybody else experienced this problem and found a solution? Thanks.

Yeah, I know, I'm thick as two short planks. I might be looking at this problem from the wrong direction.

Encryption- Binary [closed]

Posted: 15 Apr 2021 08:36 AM PDT

The following text is encoded in binary.

001000100100010001101111001000000110111101101110011001010010000001110100011010000110100101101110011001110010000001110100011010000110000101110100001000000111001101100011011000010111001001100101011100110010000001111001011011110111010100100000011001010111011001100101011100100111100100100000011001000110000101111001001000100010000000101101001000000100010101101100011001010110000101101110011011110111001000100000010100100110111101101111011100110110010101110110011001010110110001110100

please help me decide it and show me how to..

How to add to *argv for execv? [migrated]

Posted: 15 Apr 2021 08:32 AM PDT

Let's say I want to remove something with execv, but I don't know what to remove yet.

char *argv[] = {"rm", "-r"};  

Now, I do! How do I add to the argv? How to end it with a NULL? Thanks!

/usr/bin/script doesn't echo any command

Posted: 15 Apr 2021 09:47 AM PDT

I'm trying to use /usr/bin/script

script makes a typescript of everything on your terminal session. The terminal data are stored in raw form to the log file and information about timing to another (optional) structured log file.

it works fine on my personal machine.

with our linux server, nothing happens (it lools like my commands are not sent to the underlying shell)

$ which script  /usr/bin/script    $ /usr/bin/script -V  script from util-linux 2.23.2    $ /usr/bin/script test.script  Script started, file is test.script    ls    echo azdadazd    # CTRL-D doesn't work  # CTRL-C here  ^C/usr/bin/lua: /usr/share/lmod/lmod/libexec/../tools/base64.lua:34: interrupted!  stack traceback:      /usr/share/lmod/lmod/libexec/../tools/base64.lua:28: in function 'bit'      /usr/share/lmod/lmod/libexec/../tools/base64.lua:34: in function 'lor'      /usr/share/lmod/lmod/libexec/../tools/base64.lua:58: in function 'encode64'      /usr/share/lmod/lmod/libexec/utils.lua:159: in function 'build_MT_envT'      /usr/share/lmod/lmod/libexec/../shells/BaseShell.lua:182: in function 'expandMT'      /usr/share/lmod/lmod/libexec/../shells/BaseShell.lua:163: in function 'expand'      /usr/share/lmod/lmod/libexec/lmod:553: in function 'main'      /usr/share/lmod/lmod/libexec/lmod:570: in main chunk      [C]: ?  

what could be the cause of this ?

Thousands of packages to update

Posted: 15 Apr 2021 08:46 AM PDT

Normally I use aptitude upgrade or aptitude full-upgrade to get my system up to date. Since I am fiddling around with Vbox installation, I followed https://wiki.debian.org/VirtualBox strictly and added deb http://httpredir.debian.org/debian/ sid main contrib non-free to /etc/apt/sources.list and ran apt update, which apparently gives much more information about the installation process than aptitude including a lot of Error messages. So I started fixing these (e.g. NO_PUBKEY, superfluous cdrom entries, etc.). While searching the web to solve a few issues, I see the plasma update icon "Updates available" popping up. Okay, taking a look ... it shows "2584 packages to update" with more than 2 GiB to download ... and the count and volume are steadily growing as I write this question!

All seem to be not system relevant, just applications like Activity Pager, Akregator, and so on which I don't remember to have ever installed.

What did I do wrong? How to fix this? And why do I get updates for packages I don't recall to have ever installed?

I am running Debian Buster with KDE Plasma.

UPDATE: if the Sid line in sources.list is commented out, then the update request disappears; however something starts downloading from the internet (not sure yet what and why) whenever the network is connected

How to alphabetically sort lines by a letter that is not at the beginning?

Posted: 15 Apr 2021 09:42 AM PDT

I need to alphabetically sort something like this

https://www.youtube.com/feeds/videos.xml?channel_id=ABC "~foo" Youtube  https://www.youtube.com/feeds/videos.xml?channel_id=XYZ "~bar" Youtube  

and etc. I need it to take the characters after that tilde and sort it that way, and not by the channel ID that it normally would. Would anyone have an idea how to do this? Thanks in advance.

Edit: To clarify, I need them sorted a-z and only "foo", "bar" parts (and not the Youtube tag), and uppercase/lowercase differences should be ignored and I only have to deal with english characters. So how it is expected to look is

https://www.youtube.com/feeds/videos.xml?channel_id=XYZ "~bar" Youtube  https://www.youtube.com/feeds/videos.xml?channel_id=ABC "~foo" Youtube  

Delete files with filename date older than 7 days

Posted: 15 Apr 2021 10:27 AM PDT

so all my files on my backup server are named archive-2021-03-18.zip, archive-2021-03-19.zip, etc. I want to set up a cronjob to delete files where the name is older than 7 days.

Would someone be able to assist me please?

How do I get a self encrypting NVMe SSD partition to show up in /dev after unlocking it?

Posted: 15 Apr 2021 07:37 AM PDT

I've been spending some time working with self encrypting SSDs recently, and I am stuck on how to access drive contents after I've unlocked it.

Normally with this drive, you would load a Preboot Authentication image on startup that would unlock a partition containing the OS, and you would see the unlocked partition in /dev when the OS boots. However, I'm using the drive for secondary storage, and would like to be able to unlock it after the OS boots. Here's the behavior I'm looking to achieve:

  1. /dev/nvme0 is present in the /dev directory, but you can't see any partitions because it's locked. Exactly what I'd expect!
  2. Issue TCG Opal commands to unlock the drive. Confirm that the drive is unlocked using TCG Identify command. Success!
  3. ??? <----- This is where I'm stuck
  4. /dev/nvme0n1p* for each partition on the drive is present in /dev

What do I need to do for step 3 in order to force a reread of the device so that I can see the partition after it's unlocked? And is this something I can do programmatically, or would I have to invoke a script of some sort?

How to setup a .local Wifi hostname to SSH in a Linux system?

Posted: 15 Apr 2021 08:24 AM PDT

I SSH to my Raspberry Pi's wifi via ssh raspberrypi.local, simply done by adding the following code in a file named wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev  update_config=1  country=US    network={   ssid="Welcome Home"   psk="Thanhlich267"   priority=1  }  

I am trying to learn to do the same thing with other Linux Embedded system (Google Coral Board, BeagleBone), but I did not know how to accomplish this. Can someone please advise me?

Thanks,

Why my test command wouldn't show error?

Posted: 15 Apr 2021 07:37 AM PDT

I have a book that stated:

"....For example, if the shell variable symbol contains an equal sign,

look at what happens if you try to test it for zero length:

$ echo $symbol  =   $ test -z "$symbol"   sh: test: argument expected   

The = operator has higher precedence than the -z operator ...."

But when I try it on my Ubuntu (running in a virtual machine):

jackson@jackson-VirtualBox:/$ symbol="="  jackson@jackson-VirtualBox:/$ echo $symbol   =  jackson@jackson-VirtualBox:/$ test -z "$symbol"  jackson@jackson-VirtualBox:/$  

Why is my test command's result not sh: test:argument expected?

Is the book wrong?

How to delete duplicate line within a bracket preferably using one-liner?

Posted: 15 Apr 2021 07:54 AM PDT

My intention is to remove duplicate Param within each test. There is multiple tests that might have duplicate Param and I want to remove the 2nd Param duplicate within each test. My file is as below:

Test 1  {    Param1 = "1";    Param2 = "A";    Param1 = "-1";  }  Test 2  {    Param1 = "-1";    Param3 = "B";  }  

Expected output:

Test 1  {    Param1 = "1";    Param2 = "A";  }  Test 2  {    Param1 = "-1";    Param3 = "B";  }  

Arduino: avrdude: ser_open(): can't open device "/dev/ttyACM1": Input/output error

Posted: 15 Apr 2021 08:55 AM PDT

I use arduino ide on arch linux with arduino uno connected via USB. I am sure that I choosed right port and board in ide menu.

when I run ls -l /dev/ttyACM* I get:

crw-rw---- 1 root uucp 166, 0 14. dub 12.44 /dev/ttyACM0  crw-rw-rw- 1 root uucp 166, 1 14. dub 12.54 /dev/ttyACM1  

but when I click upload I get this error:

Sketch uses 440 bytes (1%) of program storage space. Maximum is 32256 bytes.  Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.  avrdude: ser_open(): can't open device "/dev/ttyACM1": Input/output error  avrdude: ser_open(): can't open device "/dev/ttyACM1": Input/output error  

Error remains on newest linux kernel and LTS.

How can I fix this ?
Thank you for help

PS: If you need any more information, comment below and I will add it soon as possible.

Debian HC4 NAS can't resolve any host

Posted: 15 Apr 2021 08:05 AM PDT

new to stackoverflow and linux usage, have a NAS setup on HC4 currently trying to set up a steam cache, after installing docker I was trying to install network-manager which lead me down a rabbit hole because it returned errors such as :

W: Failed to fetch http://deb.debian.org/debian/dists/stable/InRelease  Could not resolve 'deb.debian.org'  W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Could not resolve 'deb.debian.org'  W: Failed to fetch http://deb.debian.org/debian-security/dists/buster/updates/InRelease  Could not resolve 'deb.debian.org'  W: Failed to fetch http://ftp.debian.org/debian/dists/buster-backports/InRelease  Could not resolve 'ftp.debian.org'  W: Failed to fetch https://download.docker.com/linux/debian/dists/buster/InRelease  Could not resolve 'download.docker.com'  W: Failed to fetch http://packages.openmediavault.org/public/dists/erasmus/InRelease  Could not resolve 'packages.openmediavault.org'  W: Failed to fetch https://openmediavault-plugin-developers.github.io/packages/debian/dists/usul/InRelease  Could not resolve 'openmediavault-plugin-developers.github.io'  W: Failed to fetch http://packages.openmediavault.org/public/dists/usul/InRelease  Could not resolve 'packages.openmediavault.org'  W: Failed to fetch http://ppa.linuxfactory.or.kr/dists/buster/InRelease  Could not resolve 'ppa.linuxfactory.or.kr'  W: Some index files failed to download. They have been ignored, or old ones used instead.  W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list.d/docker.list:1  W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list.d/docker.list:1  W: Target Packages (stable/binary-arm64/Packages) is configured multiple times in /etc/apt/sources.list.d/docker.list:1 and /etc/apt/sources.list.d/omvextras.list:2  W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list.d/omvextras.list:2  W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:24 and /etc/apt/sources.list.d/omvextras.list:2  

now I get those errors with apt-get update, and apt-get install network-manager returns

Reading package lists... Done  Building dependency tree  Reading state information... Done  Package network-manager is not available, but is referred to by another package.  This may mean that the package is missing, has been obsoleted, or  is only available from another source    E: Package 'network-manager' has no installation candidate  

and because I messed with this a lot, here is my sources.list:

  #------------------------------------------------------------------------------#  #                   OFFICIAL DEBIAN REPOS  #------------------------------------------------------------------------------#    ###### Debian Main Repos  deb http://deb.debian.org/debian stable main  deb-src http://deb.debian.org/debian stable main    deb http://deb.debian.org/debian buster-updates main  deb-src http://deb.debian.org/debian buster-updates main    deb http://deb.debian.org/debian-security/ buster/updates main  deb-src http://deb.debian.org/debian-security/ buster/updates main    deb http://ftp.debian.org/debian buster-backports main  deb-src http://ftp.debian.org/debian buster-backports main    #------------------------------------------------------------------------------#  #                      UNOFFICIAL  REPOS  #------------------------------------------------------------------------------#    ###### 3rd Party Binary Repos  ###Docker CE  deb [arch=amd64] https://download.docker.com/linux/debian buster stable    ###openmediavault  deb http://packages.openmediavault.org/public erasmus main  deb-src http://packages.openmediavault.org/public erasmus main  

any help or a direction to point me in would be greatly appreciated

Installing bitcoin-core in Arch Linux (VirtualBox) returns: unknown location(0): fatal error: in runtime error: _S_create_c_locale name not valid

Posted: 15 Apr 2021 08:13 AM PDT

I'd like to maintain a BTC node / wallet on a VM within VirtualBox. For this I installed Arch Linux, manually. The process wasn't the smoothest experience, but I got it working, eventually. Then I used this guide to install yay, successfully.

I went ahead and tried to install bitcoin-core by running yay -Sa bitcoin-core --answerclean y --answerdiff n.

The installation takes long and fails, eventually. After a lot of lines starting with CXX I got these lines:

==> Starting check()...    -> Testing ...  Making check in src  make[1]: Entering directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0/src'  make[2]: Entering directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0/src'  make[3]: Entering directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0'  make[3]: Leaving directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0'  make  check-TESTS check-local  ...  make[4]: Entering directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0/src'  ==================================================================================  Running tests: arith_uint256_tests from test/arith_uint256_tests.cpp  Running 11 test cases...  Entering test module "Bitcoin Core Test Suite"  test/arith_uint356_tests.cpp(18): Entering test suite "arith_uint256_tests"  test/arith_uint256_tests.cpp(68(: Entering test case "basics"  2021-04-12T19:57:00 Seed: Setting random seed for current tests to RANDOM_CTX_SEED=........  2021-04-12T19:57:00 [test] Bitcoin Core version v0.21.0.0-d79e0e2 (release build)  2021-04-12T19:57:00 [test] Assuming ancestors of block .....................  unknown location(0): fatal error: in "arith_uint356_tests/basics": std::runtime_error: locale::facet::_S_create_c_locale name not valid  test/arith_uint256_tests.cpp(68): last checkpoint: "basics" fiture ctor  test/arith_uint256_tests.cpp(68): Leaving test case "basics"; testing time 789us  test/arith_uint256_tests.cpp(157): Entering test case "shifts"  test_bitcoin: util/system.cpp:519: void ArgsManager::AddArg(const string&, const string&, unsighed int, const OptionsCategory&): Assertion 'ret.second' failed.  make[3]: *** [Makefile:21241: test/aerith_uint256_tests.cpp.test] Error 1  make[3]: Leaving directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0/src'  make[2]: *** [Makefile:19663: test/aerith_uint256_tests.cpp.test] Error 1  make[2]: Leaving directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0/src'  make[1]: *** [Makefile:19348: test/aerith_uint256_tests.cpp.test] Error 1  make[1]: Leaving directory '/home/user/.cache/yay/bitcoin-core/src/bitcoin-0.21.0/src'  make: *** [Makefile:803: check-recursive] Error 1  ==> ERROR: A failure occurred in check().      Aborting...  

The relevant line seems to be unknown location(0): fatal error: in "arith_uint356_tests/basics": std::runtime_error: locale::facet::_S_create_c_locale name not valid.

The only similar issue I found was from this question and the solution makes sense. However, the contents of my /etc/locale.conf are:

  LANG=en_US.UTF-8    

I also run locale-gen before and edited my /etc/locale.gen to only have en_US.UTF-8 UTF-8 active (not commented).

How can I get past this issue?

Can't compile any c program (/usr/bin/ld: 1: Syntax error: newline unexpected)

Posted: 15 Apr 2021 10:06 AM PDT

Hello everyone,

I have a serious issue, i can't compile any c program, i get the following error :

/usr/bin/ld: 1: Syntax error: newline unexpected  collect2: ld returned 2 exit status  

I have found on the net this solution but it doesn't work for me :

sudo apt-get autoremove binutils      sudo apt-get install binutils  

Any tips for this please ?

EDIT :

I was doing some FairThreads in C, so i got to use the lib -lfthread. And i used a make file which has his LIB_DIR at usr/bin/ld

I runned a make command and that was probably what caused all this... This is what the make file contains :

INCL_DIR = ../include LIB_DIR = ../lib ##Here it was usr/bin/ld ##############################################################   MAKE = make CC = gcc AR = ar RANLIB = ranlib  

I can normally execute files which are already compiled, but i can't compile anything.

eg :

#include <stdio.h>  int main(void) {printf("Hello world");  return 0;}  

when i compile this program by the command :

gcc -o hello hello.c   

I get the same error :

/usr/bin/ld: 2: /usr/bin/ld: Syntax error: newline unexpected  collect2: error: ld returned 2 exit status  

This is the make file responsible for all this :

INCL_DIR    = ../include  LIB_DIR     = usr/bin/ld    ##############################################################  MAKE        = make  CC      = gcc  AR      = ar  RANLIB      = ranlib    ##############################################################  LIBS        = -lfthread -lpthread  #LIBS       = -lposix4 -lfthread -lpthread # for solaris    ##############################################################  ##############################################################  CFLAGS      = -Wall -O3 -D_REENTRANT    ############ Basic libraries #################################  LIB_NAME    = fthread  LIBFT           = lib$(LIB_NAME).a    ############ C code to executable code ########################  .c.o :      $(CC) $(CFLAGS) -c $<    ############ The h files ######################################  HFILES        = fthread.h fthread_internal.h \                  event.h thread.h scheduler.h \                  broadcastlist.h locklist.h threadlist.h \                  environment.h trace.h verify.h    ############ The C files ######################################  CFILES        = event.c thread.c scheduler.c \                  broadcastlist.c locklist.c threadlist.c \                  environment.c automaton.c instruction.c    ############ The object files ##################################  OBJS          = event.o thread.o scheduler.o \                  broadcastlist.o locklist.o threadlist.o \                  environment.o automaton.o instruction.o    ############ Make entries ######################################  all: lib    lib: $(HFILE) $(OBJS)      $(AR) r $(LIBFT) $(OBJS)      - $(RANLIB) $(LIBFT)    install: lib      cp $(LIBFT) $(LIB_DIR)      cp fthread.h $(INCL_DIR)    clean:      - rm -rf *.o *~ $(LIBFT) a.out    ############ Auxiliary ########################################  TEST        = test.c    lines:      wc -l $(CFILES) $(HFILES)    test:all      $(CC) $(CFLAGS) -I. -L. $(TEST) $(LIBS)      a.out    ############ Dependencies ########################################  $(OBJS): $(HFILE)    ############ end of makefile #####################################  

How to run cronjob as non root user in docker container for alpine linux?

Posted: 15 Apr 2021 07:55 AM PDT

I have built the container using Dockerfile, in which I am using php-fpm alpine linux image. I need to run a cron job inside this container periodically. Once the application file is copied to the /var/www directory, created an user group and user as www, then switch to that user. At the entry point script I am starting crond using the command crond -fbS -d 8 -L. Then I added the docker-entrypoint as php-fpm. I am trying to execute command * * * * * php /var/www/artisan schedule:run >> /tmp/mycommand.log 2>> /var/tmp/cronjob.log as cronjob. And there is a startup_script.sh as entrypoint. Below is my Dockerfile.

FROM php:7.3-fpm-alpine  RUN mkdir -p /etc/cron.d  WORKDIR /var/www    RUN apk update && apk add \   rsyslog\   openrc \   busybox-suid \   postgresql-dev \   build-base \   freetype-dev \   libjpeg-turbo-dev \   libpng-dev \   libzip-dev \   zip \   jpegoptim optipng pngquant gifsicle \   vim \   unzip \   git \  curl \  busybox-initscripts  RUN docker-php-ext-install pdo_pgsql pdo_mysql mbstring zip exif    pcntl  RUN docker-php-ext-configure gd --with-gd --with-freetype-    dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-    dir=/usr/include/  RUN docker-php-ext-install gd        RUN addgroup -g 8877 -S www && \   adduser -u 8877 -S www -G www    COPY /src/crontab /etc/crontabs/www  COPY /src/cron.allow /etc/cron.d  USER www    COPY --chown=www:www ./src /var/www      CMD ./start_script.sh    EXPOSE 9000  

And below is my start_script.sh which will start the cronjob

  #!/bin/sh      # turn on bash's job control    set -m    # Start the primary process and put it in the background      #php-fpm &    #php artisan schedule:run      echo "TEST" >> /var/tmp/cronjob.log    crond -fbS -d 8 -L /var/tmp/cronjob.log &    docker-php-entrypoint php-fpm    # Start the helper process    #php artisan migrate --force    # the my_helper_process might need to know how to wait on the    # primary process to start before it does its work and returns    #su www    #chown -R www:www /var/www/*      # now we bring the primary process back into the foreground    # and leave it there    fg %1  

Docker container is perfectly build and running but when the cron tries to execute the cronjob in crontabs its getting the error root:permission denied. Along with this group can't permit the operation.

zip file with fat format (on linux)

Posted: 15 Apr 2021 08:03 AM PDT

I am trying to import contacts from micro-SD to (non Android) Nokia phone. So I first exported current contacts on micro-SD card in hope that i will be able to modify the exported file and then import it.

Exported file type is Nokia backup file .NBF. it seem it is actually an ordinary zip file.

I can unzip exported .NBF file and modify it (contacts are stored in .vcf - vcard).

However when I zip it and try to import it the phone says file is corrupted.

 

i checked zip files with zipinfo:

Unmodified file:

$ zipinfo Backup001.NBF  Archive:  Backup001.NBF  Zip file size: 3031 bytes, number of entries: 10  -rw-a--     0.0 fat     1160 b- stor 20-Mar-30 11:31 predefhiddenfolder/predefisasettings/usersettings/user_settings.wbxml  dr-x-hs     0.0 fat        0 b- stor 10-Jan-01 00:00 predefhiddenfolder/predefisasettings/usersettings  dr-xahs     0.0 fat        0 b- stor 07-Jan-01 00:00 predefhiddenfolder/predefisasettings  dr-xahs     0.0 fat        0 b- stor 07-Jan-01 00:00 predefhiddenfolder  -rw-a--     0.0 fat      214 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/F01  drwxa--     0.0 fat        0 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP  drwxa--     0.0 fat        0 b- defN 10-Jan-01 00:00 predefhiddenfolder/backup  -rw-a--     0.0 fat      256 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/32/contacts/1.vcf  drwxa--     0.0 fat        0 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/32/contacts  drwxa--     0.0 fat        0 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/32  10 files, 1630 bytes uncompressed, 1409 bytes compressed:  13.6%  

then i modify 1.vcf and update Backup001.NBF with:

zip Backup001.NBF -f -r predefhiddenfolder/backup/WIP/32/contacts/1.vcf

Modified:

$ zipinfo Backup001.NBF  Archive:  Backup001.NBF  Zip file size: 2958 bytes, number of entries: 10  -rw-a--     0.0 fat     1160 b- stor 20-Mar-30 11:31 predefhiddenfolder/predefisasettings/usersettings/user_settings.wbxml  dr-x-hs     0.0 fat        0 b- stor 10-Jan-01 00:00 predefhiddenfolder/predefisasettings/usersettings  dr-xahs     0.0 fat        0 b- stor 07-Jan-01 00:00 predefhiddenfolder/predefisasettings  dr-xahs     0.0 fat        0 b- stor 07-Jan-01 00:00 predefhiddenfolder  -rw-a--     0.0 fat      214 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/F01  drwxa--     0.0 fat        0 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP  drwxa--     0.0 fat        0 b- defN 10-Jan-01 00:00 predefhiddenfolder/backup  -rw-r--r--  3.0 unx      208 tx defN 20-Apr-03 01:04 predefhiddenfolder/backup/WIP/32/contacts/1.vcf  drwxa--     0.0 fat        0 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/32/contacts  drwxa--     0.0 fat        0 b- defN 20-Mar-30 11:31 predefhiddenfolder/backup/WIP/32  10 files, 1582 bytes uncompressed, 1366 bytes compressed:  13.7%  

in this line: -rw-r--r-- 3.0 unx 208 tx defN 20-Apr-03 01:04 predefhiddenfolder/backup/WIP/32/contacts/1.vcf it says that format is 3.0 unx.

is there any way to zip it so format will be 0.0 fat?

 

Edit: added some clarification

Edit: I tried using -k flag as sugessted by @FennecTECH

it looks better but still doesn't work.

$ zipinfo Backup000.NBF  Archive:  Backup000.NBF  Zip file size: 2501 bytes, number of entries: 10  drwx---     2.0 fat        0 bx stor 20-Apr-03 00:37 PREDEFHI/  drwx---     2.0 fat        0 bx stor 20-Apr-03 00:36 PREDEFHI/PREDEFIS/  drwx---     2.0 fat        0 bx stor 20-Apr-03 00:36 PREDEFHI/PREDEFIS/USERSETT/  -rw----     2.0 fat     1160 bx defN 20-Mar-30 11:31 PREDEFHI/PREDEFIS/USERSETT/USER_SET.WBX  drwx---     2.0 fat        0 bx stor 20-Apr-03 00:37 PREDEFHI/BACKUP/  drwx---     2.0 fat        0 bx stor 20-Apr-03 00:37 PREDEFHI/BACKUP/WIP/  drwx---     2.0 fat        0 bx stor 20-Apr-03 00:37 PREDEFHI/BACKUP/WIP/32/  drwx---     2.0 fat        0 bx stor 20-Apr-03 01:04 PREDEFHI/BACKUP/WIP/32/CONTACTS/  -rw----     2.0 fat      208 tx defN 20-Apr-03 01:04 PREDEFHI/BACKUP/WIP/32/CONTACTS/1.VCF  -rw----     2.0 fat      214 bx defN 20-Mar-30 11:31 PREDEFHI/BACKUP/WIP/F01    

similar question that didn't solve the problem: https://stackoverflow.com/questions/15033646/compression-method-for-xlsx-with-7z

Append strings to multiple space-separated values in a variable

Posted: 15 Apr 2021 10:03 AM PDT

I have a variable VAR="XYZ YZA ZAB" declared and I would like to append some strings next to all the words in that variable.

For example: I want to append .file1 to each space-separate substring in XYZ YZA ZAB.

The output of variable should be as below without any for loop or anything.

VAR="XYZ.file1 YZA.file1 ZAB.file1"  

I am sure awk can be used, but I am not aware of how to use it for this purpose.

grub2 using wrong /boot partition

Posted: 15 Apr 2021 08:25 AM PDT

I recently installed Ubuntu 18.04 from a USB. I did everything the same way I'd done when upgrading from 14 to 16, and 16 to 17, and it worked every time until now. I selected "erase ubuntu 17 and install ubuntu 18" while running 18 from a USB image. Here is my issue: Grub2 loads, but seems to be using the wrong config file in the wrong partition. In order to run ubuntu I have to set the root dir to /dev/sda8 and set the proper linux and initrd files which live in /dev/sda8/boot(this is also where the grub.cfg file I want to use lives). I can see there is a grub.cfg file on dev/sda1/EFI/ubuntu/grub.cfg that just points to /dev/sda5 which is the BIOS partition. My question is, how can I get grub to use the config file I have updated from ubuntu (the one at /dev/sda8/boot)? I am worried that if I change the one on /dev/sda1, I will seriously break something, but if not, would it suffice to use the contents of the cfg file on sda8?

Here is the terminal output of fdisk -l for reference:

Device         Start       End   Sectors   Size Type  /dev/sda1       2048    206847    204800   100M EFI System  /dev/sda2     206848    468991    262144   128M Microsoft reserved  /dev/sda3     468992 816990982 816521991 389.4G Microsoft basic data  /dev/sda4  816992256 818726911   1734656   847M Windows recovery environment  /dev/sda5  818726912 818728959      2048     1M BIOS boot  /dev/sda6  935913472 939819007   3905536   1.9G Linux swap  /dev/sda7  942651392 976773119  34121728  16.3G Microsoft basic data  /dev/sda8  818728960 935913471 117184512  55.9G Linux filesystem  

The file /dev/sda1/EFI/ubuntu/grub.cfg has the following contents, note that (hd0,5) is the BIOS partition:

search.fs_uuid 7e076866-97b4-4d3c-b864-491137212645 root hd0,gpt5  set prefix=($root)'/boot/grub'  configfile $prefix/grub.cfg  

Shrink disk image

Posted: 15 Apr 2021 08:43 AM PDT

I have several disk images stored at my fileserver at the moment, these are mainly system images created with dd. The reason for why I have created these images is because I needed the harddrive for something else, so I have created a image that I can later restore at the harddrive when it's available.

The problem is that the disk images are pretty size consuming, and there is a lot of free space inside of the images, so is it possible to shrink the images to only contain the actual content of the disk? Let me show you a example, I did mount one of the images to get an example.

Disk.img (500GB)  Disk.imgp1 (Total:1GB/Free:920MB) ext2 /boot  Disk.imgp2 (Total:4GB/Free:4GB) swap swap  Disk.imgp3 (Total:495GB/Free:390GB) ext4 /  

As you guys can see, there is lot of free space but still the images takes up 500GB. Is there away to shrink it ~106GB, and then grow it back before restoring it on the harddrive again? Mainly I have images with GPT and DOS tables with EXT and NTFS partitions (Some of the partitions are encrypted with LUKS).

How to replace a text in a shell executable file (.sh) using Python?

Posted: 15 Apr 2021 08:51 AM PDT

I have xxx.sh file which content is:

setsid ./start-meteor.sh >> /home/farah/StudioInstallation/Studio/bricks/platform/log/databricksastro.log 2>&1 < /dev/null &  

I want to change the above content to something like:

setsid ./start-meteor.sh >> /home/rose/validation/Studio/bricks/platform/log/databricksastro.log 2>&1 < /dev/null &  

I need a Python code to do so.

Create torrent with files from different directories from CLI

Posted: 15 Apr 2021 08:55 AM PDT

I have a directory structure that looks like:

dirA     fileA1     fileA2     ...  dirB     fileB1     fileB2     ...  

I would like to create a torrent using CLI utilities that contains:

dirA/fileA1  dirB/fileB1  

(Note: this is a simplified example. In reality, there are four directories and thousands of files in each, and I would like to select ~100 files out of each directory. So solutions that involve simply excluding specific files won't work.)

So far I have tried:

  • ctorrent only lets you specify a single file or directory
  • mktorrent only lets you specify a single file or directory
  • transmission-create only lets you specify a single file or directory
  • py3torrentcreator only lets you specify a single file or directory. It does allow you to specify a pattern of files to exclude, but there are way too many other files to exclude them individually.

I also tried using the Python bindings for libtorrent, but their add_files method strips out the directory names:

>>> import libtorrent as lt  >>> fs = lt.file_storage()  >>> lt.add_files(fs, 'dirA/fileA1')  >>> lt.add_files(fs, 'dirB/fileB1')  >>> print fs.at(0).path  fileA1  >>> t = lt.create_torrent(fs)  >>> lt.set_piece_hashes(t, '.')  Traceback (most recent call last):    File "<stdin>", line 1, in <module>  RuntimeError: No such file or directory  

Is there any way to accomplish this?

How do I find where Apache keeps the log files?

Posted: 15 Apr 2021 08:10 AM PDT

I need to find where Apache is keeping the access and error logs for a site.

I have root access to a server where dozens of sites are hosted. I'm trying to debug one of those sites. When I browse the site, it doesn't show up on /var/logs/apache2/access.log or /var/logs/apache2/error.log. (The files are there, and other sites gets logged on those. In fact, there are hundreds of different log files).

Neither locate httpd.log nor find . -iname httpd.log performed at / issue any results.

The apache configuration for the site is:

ServerName REDACTED.com.br  DocumentRoot /var/www/xyz/wiki  AssignUserId xyz_wiki xyz_wiki    <Directory /var/www/xyz/wiki/data>  order allow,deny  deny from all  </Directory>  <Directory /var/www/xyz/wiki/conf>  order allow,deny  deny from all  </Directory>  <Directory /var/www/xyz/wiki/bin>  order allow,deny  deny from all  </Directory>  <Directory /var/www/xyz/wiki/inc>  order allow,deny  deny from all  </Directory>    php_admin_value open_basedir /var/www/xyz/wiki/:/mnt/vdImagem/www/xyz/wiki/  

Sorting the output of "find"?

Posted: 15 Apr 2021 07:38 AM PDT

I need to be able to alphabetically sort the output of find before piping it to a command. Entering | sort | between didn't work, so what could I do?

find folder1 folder2 -name "*.txt" -print0 | xargs -0 myCommand  

Show all the file up to the match

Posted: 15 Apr 2021 07:33 AM PDT

grep --before-context 5 shows 5 lines before the match.

I want to show everything before the match.
Doing grep --before-context 99999999 would work but it is not very... professional.

How to show all the file up to the match?

No comments:

Post a Comment