#unix
1 messages · Page 54 of 1
Wow vim?
ye
Can u give me ur plugins?
yeah, 1 sec
so, if you load this .vimrc, it'll auto install
Thank u
once pasted into .vimrc, execute :source % then execute :PlugInstall and voila.
your vim is the same as mine.
nice lets see
I would give u tomorrow i am on phone
have u mounted the drive?
ok cool
How?
it'll be a few command line arguments
so uhm, what unix are u running?
remove your usb, show me the output of lsblk
then plug in and show the output of lsblk
i use linux not unix
😒
what distro are u using
look if you don't want help then don't ask, simples.
or sort it yourself idk
this is without usb ```
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 55.5M 1 loop /snap/core18/2074
loop1 7:1 0 77.2M 1 loop /snap/discord/128
loop2 7:2 0 162.9M 1 loop /snap/gnome-3-28-1804/145
loop3 7:3 0 65.1M 1 loop /snap/gtk-common-themes/1515
loop4 7:4 0 32.3M 1 loop /snap/snapd/12398
sda 8:0 0 76.3G 0 disk
├─sda1 8:1 0 100M 0 part
└─sda2 8:2 0 76.2G 0 part
sdb 8:16 0 465.8G 0 disk
├─sdb1 8:17 0 512M 0 part /boot/efi
├─sdb2 8:18 0 1K 0 part
└─sdb5 8:21 0 465.3G 0 part /
k and with usb
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 55.5M 1 loop /snap/core18/2074
loop1 7:1 0 77.2M 1 loop /snap/discord/128
loop2 7:2 0 162.9M 1 loop /snap/gnome-3-28-1804/145
loop3 7:3 0 65.1M 1 loop /snap/gtk-common-themes/1515
loop4 7:4 0 32.3M 1 loop /snap/snapd/12398
sda 8:0 0 76.3G 0 disk
├─sda1 8:1 0 100M 0 part
└─sda2 8:2 0 76.2G 0 part
sdb 8:16 0 465.8G 0 disk
├─sdb1 8:17 0 512M 0 part /boot/efi
├─sdb2 8:18 0 1K 0 part
└─sdb5 8:21 0 465.3G 0 part /
sdc 8:32 1 7.2G 0 disk
cool, so our device name is sdc ye?
now mkdir /mnt/usbstick
or sudo mkdir /mnt/usbstick/
then, mount sdc /mnt/usbstick/ or sudo mount sdc /mnt/usbstick/
sudo mount sdc /mnt/usbstick
mount: /mnt/usbstick: special device sdc does not exist.
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ sudo mount /dev/sdc /mnt/usbstick
mount: /mnt/usbstick: wrong fs type, bad option, bad superblock on /dev/sdc, missing codepage or helper program, or other error.
ok, we need to specify the filesystem type with the -t argument
do u know what filesystem type that usb is
i dunno how we'd check
i don't know
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ lsblk --fs
NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
loop0
squash 0 100% /snap/core
loop1
squash 0 100% /snap/disc
loop2
squash 0 100% /snap/gnom
loop3
squash 0 100% /snap/gtk-
loop4
squash 0 100% /snap/snap
sda
├─sda1
│ ntfs BE2CC4812CC435E5
└─sda2
ntfs 54D8C691D8C670B2
sdb
├─sdb1
│ vfat 3C09-F5DE 511M 0% /boot/efi
├─sdb2
│
└─sdb5
ext4 9506d0cf-5cc1-4466-9bcb-21185660512d 420.5G 3% /
nothing happens
hmmm
let's just assume it's fat32
sudo mount -t vfat /dev/sdc /mnt/usbstick/
if not let's try ext4
and then i'm rlly out of ideas
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ sudo mount -t vfat /dev/sdc /mnt/usbstick/
mount: /mnt/usbstick: wrong fs type, bad option, bad superblock on /dev/sdc, missing codepage or helper program, or other error.
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$
and ext4?
i replace vfat with ext4?
wait before that
hmmmm
actually yeah tfry that
i was thinking maybe sdc was partitioned
or something
then try mount -t msdos /dev/sdc /mnt/usbstick
hold on bro
is this usb stick empty?
?
like is it a new usb stick or something?
it's not empty
ok it's got things in it
last time i used the usb i burned iso file in it
it's weird because theres no partition at all
normally you'd have like /dev/sdc has partition sdc1 or whatever
have u tried both -t vfat and -t msdos yet?
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ mount -t vfat /dev/sdc /mnt/usbstick
mount: only root can use "--types" option
yes
so msdos doesn't work?
sudo mount -t msdos /dev/sdc /mnt/usbstick/
run that pls
u need to remember sudo
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ sudo mount -t msdos /dev/sdc /mnt/usbstick/
mount: /mnt/usbstick: wrong fs type, bad option, bad superblock on /dev/sdc, missing codepage or helper program, or other error.
ok, pls can u send a screenshot of the output of lsblk -l
dmesg | tail -20 and screenshot pls
sudo dmesg | tail -20
oh yeah and finally, this definitely isn't gonna work but can u at least try in sequential order, see if one works.
sudo mount /dev/sdc1 /mnt/usbstick/
sudo mount -t msdos /dev/sdc1 /mnt/usbstick/
sudo mount -t vfat /dev/sdc1 /mnt/usbstick/
let's just guess it does have a partition even though it's not showing on lsblk for some reason.
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ sudo mount /dev/sdc1 /mnt/usbstick/
mount: /mnt/usbstick: special device /dev/sdc1 does not exist.
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ sudo mount -t msdos /dev/sdc1 /mnt/usbstick/
mount: /mnt/usbstick: special device /dev/sdc1 does not exist.
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$ sudo mount -t vfat /dev/sdc1 /mnt/usbstick/
mount: /mnt/usbstick: special device /dev/sdc1 does not exist.
ahmed@ahmed-HP-Compaq-dx2420-Microtower:~$
ok, damn.
i have no idea what else to do now apart from reformat that usb stick.
we'd reformat it, make a partition and then mount it
How to do that
Distro name?
Theme?
Anyone using WSL v2 Kali, so they can test a quick bug I keep getting?
If I ever double tap the physical escape key twice on my terminal windows it freezes the window temporarily.
Ok well it seems like a Kali/Bash issue with Bash v5.1.4
Edit:
Figured out the issue, double escape in bash does tab complete and then also causes the entire bash window you cache my path. Causing a delay based on the size of my drives and etc....
When we do man ascii, we get:
So is it right to say ascii value of A is 65?
and if we wanted to store the numerical value of 65 to a variable instead of using 65 as a magic number, would the following make sense
ascii_of_A = 65
yes, but i would probably use ASCII_OF_A because it would be a constant
maybe even omit the "of" entirely
Good point!! I will make use of all uppercase! Thanks
hey there, can anybody give me a hand? I'm having trouble with aliases/function definitions and execution/fallback directories for aliases too...
ik I sound like someone who hasn't even read the manual, but I have and I don't understand much
It would be great if anyone knew a tutorial other than the official one for this topic
hey there! i hope this is the right channel to ask but how do i install python modules on arch linux? (please ping me)
How do we convert octal o hexadecimal directly? does anyone know?
yes
echo "obase=16; ibase=8; 17" | bc
example of converting base 8 number 17 to hexadecimal
check if you have python (which you should)
i do
then do python -m pip install XXX
ill try that
[captain8771@CapOS ~]$ python -m pip install discord
/usr/bin/python: No module named pip
[captain8771@CapOS ~]$
bruh moment

Oh-
I meant without python
Ik this is a python server
that is not python
shell script
Are you familiar with shell? (e.g. bash, zsh)
anyway shell has bc which is a calculator language
so you can use bc to convert any number in any base to a number in a base of your choice
if you want to learn more just type man bc in your terminal
im not....
not unless you're referring to "windows cmd" and "windows powershell"
hmm
well
this channel isn't for windows-exclusive users
since windows isn't a UNIX-based OS
again, it's not recommended to mess with the built-in Python version :c
Typically you'd use pyenv
or install another version
I don't understand the point you're trying to make
Built-in Python doesn't come with pip
Python is used internally by certain programs
You don't want to install python-pip, and you don't want to use it as a global interpreter
That's up to you, but generally I don't think people should be using the built-in interpreter
it's only there as a dependency, and if something breaks... I don't expect it to be an easy fix
If you look hard enough, you'll see staff making the same recommendation throughout this server
I'd also like to caution against the use of pacman -S, while we're here
Always upgrade (with
pacman -Syu) before installing a package.
https://wiki.archlinux.org/title/System_maintenance#Partial_upgrades_are_unsupported
um that's exactly what you're not supposed to do
that's like... the worst thing you could do in this context
That's what you imply
If you say "update the repos", that doesn't imply pacman -Syu because that's a complete distribution upgrade
This is a bit of a fault on the wiki's part, the partial upgrades stuff is not explained here
but they do however expect you to read the system maintenance page
which does explain that you should perform a distribution upgrade before installing a package
and in the case of Arch, it's good habit to always just do sudo pacman -Syu <package>
updating the repos is what sudo pacman -Sy would do
sudo pacman -Syu actually updates packages and upgrades your system
That was not an assumption that I made, I was going solely based off of what you had said
Updating the repos is pacman -Sy, if you asked someone "How do I update the pacman repositories?", they would not respond with sudo pacman -Syu
I don't even use Arch
I... really don't see a need to delete every message
because now this looks incredibly one-sided and spammy
It was a one-sided conversation 🙂 you were right all along!
I sincerely apologise, i clearly know nothing
I only saw you use -S, unless you edited it.
Clearly my suggestion was wrong, you should know better and use what Phycereal suggested.
Never use pacman -S!
https://wiki.archlinux.org/title/Pacman#Installing_packages -S looks fine, unless the wiki is wrong or I am misreading it. -Sy isn't.
According to Phycereal -S is not okay (#unix message). In fact Archwiki is in the wrong for not explaining it properly (#unix message)
so I'm going to listen to the expert advice and not use -S
If the wiki is wrong why hasn't it been updated for something so important
Clearly the wiki authors do not know what they are talking about :)
The people who maintain Arch and Pacman
ghastly, openSUSE users know better
🙂
i guess i was just super lucky using -S for the last couple years
like one in a trillion lucky
I am an apt user, so not familiar with pacman, but through reading the wiki and an understanding of package managers, my interpretation is -S will install old packages and not the most up to date.
depends, if you have run -Syu sometime that day then it may as well be the newest available. -S doesn't imply "download not the latest one"
The most recent version in the cache
Is it easier to break Arch due to being a rolling release?
i think the main issue is stability, since it heavily prides itself on bleeding edge updates
at least from personal experience
they are normally a trade off
I go for stability
So with Arch installing pip with -Syu and then using a virtual env would be best
i use debian for my home server
python-pip is one of the dependencies for python in the official repositories
and yes, venvs for project-specific stuff i suppose
No, typically you just don't want to acknowledge the preinstalled Python at all... Which is where pyenv comes in handy, letting you use a different Python "globally" without interfering with the inbuilt one
I never said -S is not okay, I said
I'd also like to caution against the use of
pacman -S, while we're here
and I find that completely fair. A fair bunch of people that I've seen who use Arch don't have a clue what the difference between -S, -Sy, and -Syu might be. I don't understand what you're arguing, when it seems like you agree with me...
ArchWiki says to perform a system upgrade before installing a package, and the easiest way to do that would be sudo pacman -Syu <package>
I totally agree with you
I'm not implying you are wrong
I don't know why you are getting that impression, I have totally submitted to your opinions
I don't understand the sarcasm
You keep saying things like
ghastly, openSUSE users know better
— I can't help but take offense to that
Personally I would install pipenv globally with pip and then only use pipenv. They both ultimately get it done. Though this done on Ubuntu so results may vary.
I think you're confusing pyenv for virtual environments
or am I not understanding what you're talking about lol
you generally just want to leave the preinstalled interpreter completely alone
nope not confused
pipenv requires messing with the base interpreter
and that would also require you to activate a venv for things like IPython
which I mean to have to go around and do
cd ~/Documents/base-venv
source venv/activate.sh
ipython
is quite annoying lol
Stuff like Jupyter I'll run in Docker or pipenv. Dev I'll use pipenv or Docker. I am already in the dir and can run pipenv run dev. Python applications I'll normally install with apt.
pipenv run dev will normally run something like ls *.py | entr -r python main.py
anybody knows how to run code in VS?
Visual Studio, Python?
how do you run code
There is a couple of ways, you can user the terminal or tasks
I use the terminal normally and don't use task.
Ctrl ~ (~ is above tab next to 1) will open a terminal
type python3 and see if it works
Terminal->New Terminal from the top menu will get you one as well
Also what os are you on?
this is probably best in #editors-ides
I suppose I've not used pipenv enough to understand how this works, but I'd assume it's much easier just not dealing with a virtual environment and the system interpreter to begin with
because with pyenv you can just do like pyenv global 3.9.5 and be on your way, worry free
my dream was to have a linux system but i din't get one
pipenv is a good tool. It is quite new. It's pip + virtualenv
How's that compare to poetry?
might be the wrong channel for this, if you'd prefer we move then you can ping me in a relevant channel
I figure #tools-and-devops
Yeah
Used that for piping output of a script. anyone know what does this do exactly? >
>(tee -a stdout.log) \
2> >(tee -a stderr.log >&2)
@untold abyss like this?
cmd \
1> >(tee -a stdout.log) \
2> >(tee -a stderr.log >&2)
it emits stdout to both stdout.log and stdout, and it emits stderr to both stderr.log and stderr
>() is "process substitution"
Process Substitution (Bash Reference Manual)
thanks a lot! 🚀
Im getting the ertot “chroot is running ,command “start” ignored”
@jagged fjord This is the git server I run https://docs.gitea.io/en-us/install-with-docker/
ok, i will check it out
any thoughts on this
print("PythonOS [0.1] is booting up...")
print("Importing modules...")
import os
print("Setting keys...")
adminpassword = os.environ['adminpassword']
print("All modules and keys are set up!")
def main():
print(" ")
cmd = input("A:/~ ")
if cmd == "help":
print("poweroff - Shutdown system")
print("help - Help command")
return main()
if cmd == "poweroff":
print("Shutting down...")
print(" ")
print("This was PythonOS [0.1].")
else:
print("Invalid command!")
return main()
main()
its a basic "opeating system for me but I know its not" what other commands should i add im planning to add a admin "root" command which is being worked on
I dont think that it is correct chanell your """"""os"""""" does not have eaven unixish paths
lol
OS is something more than simple commands console 
It is definitely a shell though
I have a question it's a good idea to use a recursive function in that "os"?
you don't want to implement arbitrarily long loops in python using recursion
because python doesn't have any optimization for recursive functions and you eventually hit the maximum stack size
that i was thinking
async is probably better
Should i use single quote or double quote to run a python script on linux?
Well, it's not directly on linux terminal. I'm using a run external program on torrent completion on qbittorrent but since it on linux vps, i assume it run bash.
python "/root/nekobot/up.py" -hash "e92f5b4a721c6a5b7f8f257e25e221d0f773c395"
If your current setup is just running the command you showed above, it doesn't matter.
Won't make a single difference.
Hey I'm writing a deamon in python
I've an issue where I've got a class that's in another file
for some reason the daemon starts if the class is in the same file as my driver function. But if I pull it in from another file it fails to start
Any ideas?
i feel like this is more for #async-and-concurrency
rather than here
what is the source command for? and how does it work?
Source is kind of like import. Allows getting custom variables/settings/functions from different files
You're talking about the shell command?
yes like source ~/.bashrc
It just runs the script inside of your current shell.
For example;
Say you have a file named script.sh with this in it:
#!/usr/bin/env bash
echo hi
cookie = cake
If you run source script.sh, it'll print hi to your terminal, and set the value of cookie to cake.
Pretty much what @lavish hill said, just provided an example.
When you run source ~/.bashrc it's just a huge collection of commands and variables entering into your current shell.
The cool thing about it is when you write functions in the script. They become callable, and won't be called by source, just to make that clear. When you source bashrc, you'll want your terminal settings stored in there
Yeah, like you could put something like this in a file:
print_words() {
echo "hi"
echo "hi2"
}
And if you ran source file, you would be able to run the print_words command, which would print hi and hi2.
Is there a certain way you're needing to use it or something?
no, I just wanted to learn how it works. I'm used to run source ~/.bashrc but simply because it is what on most of the tutorials out there but I don't know behind that command.
@runic quarry @lavish hill ,
how it is different to bash command use to run script?
It's different in the way that you're able to use the variables/functions of the file later on.. You're loading it, not directly executing it
Great question:
Try creating a file named file.sh with this in it:
#!/usr/bin/env bash
discord=quack
-
First try running
bash file.sh. If you then runecho $discord, you'll see it's not set to anything. -
Now, run
source file.sh. If you runecho $discordthis time, you'll see that it's set toquack.
Difference is mostly just in that, first one runs in a subprocess, but the second one runs directly inside your shell.
Just fixed the command, still hung up on python variable assignment.
@lavish hill , you mean with source you directly executing it? and with bash is you are loading it for later use? as what @runic quarry example (if I understand the example correctly)?
One actually good example of this:
Inside your bashrc, you can enter this:
PATH=$PATH:$HOME/.local/bin
If you then source ~/.bashrc it tells your terminal that you will later on look for executable files located in ~/.local/bin for your terminal commands. If you just ~/.bashrc, it would only execute, but not be stored in terminal
You aren't storing it for later, but rather just running it in a subprocess (does that make any sense?).
So you'd have your current terminal session, and when you run bash file.sh, it spawns a new process to run the command.
When you run source file.sh though, it runs in your current process.
Another important point of this is that source does not require the file to be executable!
I don't think running bash file.sh does either.
I think it mostly matters just when running something like ./file.sh.
True
yes much better now
Great great
Completely off topic though, I recommend zsh 😂
I'll let you keep your opinion, definitely disagree though.
I'm too lazy to learn zsh. Already stuck learning Python 'cause Bash gets slow as crud real quick when using pipes.
Really liking the speed improvements with Python though.
How come? I feel like zsh is the more beginner friendly version of bash, or more easily configurable, but it just took a while to actually get it done
I started with Bash, and there's all these tiny differences with zsh that's making me not want to learn it.
In zsh's defense I've spent about five minutes trying to learn it.
Was mainly going to use it to make some spinners for a program I write (Bash was being poopoo at it), but Python looks like it'll work lovely.
I mean, you might have the exact functions that I'm talking about in Bash too. I'm just addicted to fzf
That reminds me of why I came on this chat lol! Thanks xD
Do you happen to have a regex pattern to grab between to parentheses?
Between a pair of parenthesis?
Do you want to include the parenthesis, or no?
I just want to get rid of them yeah
You fine using grep?
I know how to keep the parenthesis, and then remove then with sed, not sure much on how to get rid of them with only regex though.
If you're fine keeping them, something like this would work:
\([^)]*\)
Just added an escape, had some issues without it.
Should be able to just run sed or something after to get rid of the parenthesis.
Hmm yeah, probably need to do that.. Just not sure sed is available where I'm going to run this
Will grep be?
Do you need help with the sed statement, or is that covered?
Don't know many places with grep without sed, any recent Linux system would have then anyway.
I'm not too familiar with sed, so it would be helpful, but I can google a bit too. It needs to pipe the output though, currently just looking at the default gateway as an example
So my command atm is:
arp -a | grep gateway | grep -Eo "\((.*?)\)"
Well if you have a string like hi(123), this would work:
echo 'hi(123)' | grep -Eo '\([^)]*\)' | sed -e 's|(||g' -e 's|)||g'
Just tells sed to wipe out any parenthesis.
Neat!
#!/bin/bash
InsidePar(){
echo $@ | grep -Eo '\([^)]*\)' | sed -e 's|(||g' -e 's|)||g'
}
GATEWAY=$(InsidePar $(arp -a | grep gateway))
echo $GATEWAY
@lavish storm Maybe, I figured it was a unix issue since I'm using a double fork to start the background process.
You could use | tr -d "()" here rather than | sed -e 's|(||g' -e 's|)||g'
In fact you could probably skip out on the tr entirely by replacing the grep with something like grep -Po '(?<=\()[^)]*'
Worth noting that this particular pattern won't catch unmatched parens though.
Is it possible to generate a public ssh key without the schacon@mylaptop.local part in the end?
How about -c flag? 
thank you 🙂
👍
!warn 824602496742719498 Please don't post pictures of random people.
:incoming_envelope: :ok_hand: applied warning to @bold fjord.
Why does my discord bot fail, after a while, with the message "Killed"?
This is a graph of the memory available on my ubuntu machine
The dip is where the process shuts down
I have a server and I created a DNS name to point to that server, is there a way that I can check in a script in the server if the DNS name points to the local server?
is anyone willing to help me with an issue i dont see any open help channels. dont really want to get banned by bombing the channel with my problems, if you can shoot me a message, that would be awesome thanks 🙂
There are available channels. The system is explained here #❓|how-to-get-help
If your question is about unix stuff you can just ask here though
no it wasnt, there were no available channels for a little there i was wondering if it just stays like that or... anyways thanks
There definitely were. We have plenty in reserve right now. If there were not any available then we would have gotten an automated alert.
Unless it was being slow to move the channels over or something
strange twice today i have not seen the available help channel, maybe i missed it cause theres no "#"
i see three
yes
i already asked
nice! good job!
🙂
same question
I don’t think so
You need system language like C or Rust
ig we can still add a little bit of python ?
like 90% is c or c++

OS can have a little Python, as a treat
I mean would it count as a bit of Python if you used python like old school 8-bit computers used BASIC?
you didn't use Python for OS development but you gotta do some stuff to make python work with your custom OS
Oh okay gotcha thanks
i believe an OS kernel usually needs a bit of assembly to start itself, and then needs to be written in a language like C (but not necessarily C) in order to have full, precise control over the hardware
once you have a kernel (not a small task) you can write as many python programs as you want... but you will need a python interpreter too
does the base register contain physical address or logical address? when i googled i found that it maybe logical or physical which im not sure if it is right or wrong
any help in this regard would be great
logical anddres since CPU is dealing with it. also i wonder what this question has to do with unix or pythron
I’m here
do uname -a and tell me what it says
I can't do anything
Oh there’s not even a cli ?
Yeah I don’t know try unplugging it then flashing it again if data gets messed up in the process
I’ve never seen that problem, sorry
At the top it says Internal error: Oops: 17 [#11] SMP ARM
Wtf
Do you have more than one kernel to choose from?
Nope
Installed the standard raspPi Debian (I think it's called that)
I now unplugged it.
I'll let it cool dow for a bit
Ok it booted regularly. No need to flash it

alr thanks ^^
Just added ubuntu to the new windows terminal but its pathed as "/mnt/c/Users" when I use it and I cant change drive. The git-bash changes drive with no problems as its not pwd'd as mnt/c and just c/.
well thats beacouse WSL is basicly virual mashine and there is no such thing as c/ a/ b/ etc in unix beacouse it uses mount system
and git-bash is just shell like cmd
I hate wsl just use a gnu/Linux distro instead
you can't always do it for example on work computrer
^thats right
I found that I can still path through my disks just differently thankfully, its path'd as mnt/DRIVE etc.
this chat is MEGA dead
Thanks for the insight
Want to tell us a bit more?
mhm
yeh
genfstab -U /mnt >> /mnt/etc/fstab
say I wanted to execute this (unix like or whatever) command through python with subprocess.call, would i give ">>" as an arg?
no
you'd open /mnt/etc/fstab as a file in append mode and give that to the subprocess stdout
with open('/mnt/etc/fstab', 'ab+') as fstab:
subprocess.run(['genfstab', '-U', '/mnt'], stdout=fstab)
something like this
I have successfully launched a python script using "LXDE-PI" autostart function, however, this script needs to run as root in order to function correctly. How can I do this?
Where would I add "sudo"?
Any way to reboot a remote server via script without losing the current connection or disrupting the script?
Rebooting turns off the machine, so no
i mean if you are just running a script try serverless and use ur remote server normally
you need something like bash -c "genfstab -U /mnt >> /mnt/etc/fstab"
Hey @rich kernel!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
I am getting this error each time I try to create a virtualenv venv python environment on ubuntu:trusty
https://paste.pythondiscord.com/sipeheweto.coffeescript
On local machine, image works fine, but when I attempt to use same docker image in production I get the errors above.
Any tips?
Hello everyone:
I need some help with a small task.
i want to build a script which will be automatically executed at login to the server via ssh.
this script should accept only a few keywords which are basically {projectnames} and run the underneath laying tasks.
my Problem is that im uncappable of creating the SSH part... the script itself (which just rebuilds some docker containers) is already done.
i need a solution to provide both.. Linux Shell login via Putty or MobaXTerm or similar which gives you a python input inside the script and ssh command execution via Command line like
ssh user1@server1 projectname
i know linux bois
Hi guys do i really need to go into bios settings to fix the virtualization issue on my VIrtual machine?
AFAIK it doesnt affect performance much right?
I'm missing memory in /sys/fs/cgroup/ -- what can I do to fix that?
Can I just do mkdir /sys/fs/cgroup/memory?
hm, no, I can't
raspi?
nope, desktop computer with Manjaro, the kernel is 5.10.49-1
$ ls /sys/fs/cgroup/
cgroup.controllers cgroup.subtree_control cpu.stat io.cost.qos memory.stat sys-kernel-debug.mount/
cgroup.max.depth cgroup.threads dev-hugepages.mount/ io.pressure -.mount/ sys-kernel-tracing.mount/
cgroup.max.descendants cpu.pressure dev-mqueue.mount/ io.stat proc-sys-fs-binfmt_misc.mount/ system.slice/
cgroup.procs cpuset.cpus.effective init.scope/ memory.numa_stat sys-fs-fuse-connections.mount/ user.slice/
cgroup.stat cpuset.mems.effective io.cost.model memory.pressure sys-kernel-config.mount/ ```
it doesn't look like it is supposed to be directory
🤔
@woeful dome
$ ls /sys/fs/cgroup/
blkio cpu,cpuacct freezer net_cls perf_event systemd
cpu cpuset hugetlb net_cls,net_prio pids unified
cpuacct devices memory net_prio rdma
I ran it on a vm if that makes a difference
It might be something controlled by a kernel parameter
Though I am not finding anything for that for arch or manjaro
You can check if the memory controller is even enabled with cat /proc/cgroups. It will probably show it as disabled.
#subsys_name hierarchy num_cgroups enabled
cpuset 0 130 1
cpu 0 130 1
cpuacct 0 130 1
blkio 0 130 1
memory 0 130 1
devices 0 130 1
freezer 0 130 1
net_cls 0 130 1
perf_event 0 130 1
net_prio 0 130 1
hugetlb 0 130 1
pids 0 130 1
rdma 0 130 1
This is what I get, seems enabled.
It was there before -- otherwise I wouldn't get confused
Does cgroup2 have it? Or is that not enabled for you?
I think arch started enabling it by default
Thought it may only enable one at a time
Arch Wiki says it's enabled by default, how do I check?
sorry, I'm a giant noob, as you might suspect
If it was enabled, presumably /sys/fs/cgroup2 would be mounted
Well, maybe that's not true. It could be enabled at the kernel level but simply not mounted, perhaps.
I played around with this on my Arch system. It seems like it mounts cgroup2 only under /sys/fs/cgroup, but both v1 and v2 are enabled.
It shows cgroup2 mounted under /sys/fs/cgroup in /etc/mtab
And it shows both fs enabled in /proc/filesystems
Actually, if you look in /etc/mtab, what do you see for the cgroup entry?
This is what I have. You can see "memory" in there ```
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
Oh I misread it
Harder to read in my terminal. memory_recursiveprot is not related
So yeah if you check mtab you will see if it's using v1 or v2. v2 has a different structure, which is probably why you don't see memory anymore
I get cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
alright, the reason I needed /sys/fs/cgroup is that that's the default location for nsjail's memory/CPU limiting stuff
nsjail does support cgroup v2, but I only have experience using it with v1
IIRC there is a switch to enable v2 support
@warped nimbus Another question: is there any disadvantage in using rlimit_... on nsjail instead of cgroups, if I need to just limit RAM and CPU?
I think the biggest difference is how it works for child processes
cgroup operates on groups of processes. From working on snekbox, I know that the limits set via cgroups are shared by all children. I don't think this is the case for rlimit
By shared, I mean that e.g. if you limit memory to 10 megabytes in a cgroup, then all processes in the cgroup can in total use 10 megabytes, where as with rlimit I think each process would get its own 10 megabytes.
Probably, cause I can at least confirm its behaviour.
I am not so sure for rlimit as I don't have as much experience with it
Can you recommend some place to read about cgroups?
IIRC redhat had a good guide for them, but I believe it was for v1. I'll try to find it again
Here it is. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/ch01 but yeah it's for v1
thanks, I'll check it out
This is something I planned to read but never got around to it https://lwn.net/Articles/679786/
After many years, the Linux kernel's control group (cgroup)
infrastructure is undergoing a rewrite that makes changes to the API in a
number of places. Understanding the changes is important to
developers, particularly those working with containerization
projects. This article will look at the new features of cgroups v2, which were
recently de...
Hm, I enabled cgroups v2:
cgroup_mem_max: 53687091200
cgroup_mem_mount: "/sys/fs/cgroup/memory"
cgroup_pids_max: 1
cgroup_pids_mount: "/sys/fs/cgroup/pids"
use_cgroupv2: true
and I'm getting this error:
[E][2021-07-24T04:08:50+0300][5797] bool subproc::initParent(nsjconf_t*, pid_t, int)():392 Couldn't initialize cgroup 2 user namespace for pid=5804
[F][2021-07-24T04:08:50+0300][1] bool subproc::runChild(nsjconf_t*, int, int, int, int)():448 Launching child process failed
I believe this is the issue where you need to create the cgroup manually before launching nsjail
nsjail doesn't do this for you because that'd require root
I did this:
sudo mkdir -p /sys/fs/cgroup/memory/NSJAIL
sudo mkdir -p /sys/fs/cgroup/pids/NSJAIL
sudo chown $USER /sys/fs/cgroup/memory/NSJAIL
sudo chown $USER /sys/fs/cgroup/pids/NSJAIL
That would be correct for v1, but not v2
v2 merges controllers into a single hierarchy, or something like that
You just need to mkdir /sys/fs/cgroup/NSJAIL
Cause the default cgroupv2_mount for nsjail is /sys/fs/cgroup and it appends NSJAIL to that
cgroup2.cc lines 42 to 44
static std::string getCgroupPath(nsjconf_t *nsjconf, pid_t pid) {
return nsjconf->cgroupv2_mount + "/NSJAIL." + std::to_string(pid);
}```
So it seems like it will try to create a new directory with the name like /sys/fs/cgroup/NSJAIL.42069 -- wouldn't that require root access?
I tried running it again, still fails, but with a different error
[F][2021-07-24T04:19:18+0300][1] bool subproc::runChild(nsjconf_t*, int, int, int, int)():448 Launching child process failed
[E][2021-07-24T04:19:18+0300][6496] int nsjail::standaloneMode(nsjconf_t*)():256 Couldn't launch the child process
```,and now I have a few directories like
/NSJAIL.5960
/NSJAIL.5961
/NSJAIL.5962
...
```, on which I get Operation not permitted when deleting, even as root
Oh I didn't notice the PID was not a child path
Try configuring cgroupv2_mount to a cgroup that you create beforehand
like cgroupv2_mount = "/sys/fs/cgroup/NSJAIL" and then it should be creating cgroups under it like /sys/fs/cgroup/NSJAIL/NSJAIL.42069
That's basically how it does it for v1.
Now I get
[E][2021-07-24T04:25:18+0300][7044] bool util::writeBufToFile(const char*, const void*, size_t, int)():100 Couldn't write '4' bytes to file '/sys/fs/cgroup/NSJAIL/NSJAIL.7050/cgroup.procs' (fd='6'): Permission denied
[E][2021-07-24T04:25:18+0300][7044] bool subproc::initParent(nsjconf_t*, pid_t, int)():392 Couldn't initialize cgroup 2 user namespace for pid=7050
[F][2021-07-24T04:25:18+0300][1] bool subproc::runChild(nsjconf_t*, int, int, int, int)():448 Launching child process failed
Also use -v for verbose output for that error
will do
This is the verbose error I get:
https://paste.pythondiscord.com/raw/enuwosifal
@warped nimbus 
The weird thing is that it has permission to create the cgroup, but not to write inside it
yeah, it actually creates those directories
Are they still there?
Can you try to write to cgroup.procs?
"permission denied" might be a misleading error. It may not actually be a file permission thing but more of a "this operation isn't supported" thing
Which still wouldn't make much sense
I tried writing quack in there, wasn't able to
file system is not full, I have 50 GB free
I know that a permission error is given when trying to set memory swap limit but the kernel hasn't been configured for that, for example
What's the ownership/permissions of that file?
Access: (0644/-rw-r--r--) Uid: ( 1000/ df) Gid: ( 1000/ df)
Also, you should try writing an actual number in there, it may reject input if it isn't an actual PID (or at least doesn't look like one)
huh
but... I am the owner of the file, how can I be denied permission?
Does it let you write with sudo?
Yes, it was successful
I'm not sure why
From kernel docs
Delegation
Model of Delegation
A cgroup can be delegated in two ways. First, to a less privileged user by granting write access of the directory and its "cgroup.procs", "cgroup.threads" and "cgroup.subtree_control" files to the user. Second, if the "nsdelegate" mount option is set, automatically to a cgroup namespace on namespace creation. Because the resource control interface files in a given directory control the distribution of the parent's resources, the delegatee shouldn't be allowed to write to them. For the first method, this is achieved by not granting access to these files. For the second, the kernel rejects writes to all files other than "cgroup.procs" and "cgroup.subtree_control" on a namespace root from inside the namespace. The end results are equivalent for both delegation types. Once delegated, the user can build sub-hierarchy under the directory, organize processes inside it as it sees fit and further distribute the resources it received from the parent. The limits and other settings of all resource controllers are hierarchical and regardless of what happens in the delegated sub-hierarchy, nothing can escape the resource restrictions imposed by the parent. Currently, cgroup doesn't impose any restrictions on the number of cgroups in or nesting depth of a delegated sub-hierarchy; however, this may be limited explicitly in the future.
Delegation Containment
A delegated sub-hierarchy is contained in the sense that processes
can't be moved into or out of the sub-hierarchy by the delegatee.For delegations to a less privileged user, this is achieved by
requiring the following conditions for a process with a non-root euid
to migrate a target process into a cgroup by writing its PID to the
"cgroup.procs" file.
The writer must have write access to the "cgroup.procs" file.
The writer must have write access to the "cgroup.procs" file of the
common ancestor of the source and destination cgroups.The above two constraints ensure that while a delegatee may migrate
processes around freely in the delegated sub-hierarchy it can't pull
in from or push out to outside the sub-hierarchy.For an example, let's assume cgroups C0 and C1 have been delegated to
user U0 who created C00, C01 under C0 and C10 under C1 as follows and
all processes under C0 and C1 belong to U0::~~~~~~~~~~~~~ - C0 - C00 ~ cgroup ~ \ C01 ~ hierarchy ~ ~~~~~~~~~~~~~ - C1 - C10Let's also say U0 wants to write the PID of a process which is
currently in C10 into "C00/cgroup.procs". U0 has write access to the
file; however, the common ancestor of the source cgroup C10 and the
destination cgroup C00 is above the points of delegation and U0 would
not have write access to its "cgroup.procs" files and thus the write
will be denied with -EACCES.For delegations to namespaces, containment is achieved by requiring
that both the source and destination cgroups are reachable from the
namespace of the process which is attempting the migration. If either
is not reachable, the migration is rejected with -ENOENT.
I figured pasting here is more convenient since I cannot directly link to that section
But it's from here https://www.kernel.org/doc/Documentation/cgroup-v2.txt
@warped nimbus what does that mean for my case?
oh
my user needs write access to /sys/fs/cgroup/cgroup.procs, right?
no, that can't be right
If you chown those files then you chould be able to write to them, is what I get out of it.
I'm not sure if the containment section applies, since you're note dealing with adding a process that's already in another cgroup
I had done sudo chown -R df /sys/fs/cgroup/NSJAIL, all the files in there already belong to me
Unless it counts a process being in the root cgroup
But that would seem very impractical
@woeful dome maybe you need to do this? https://wiki.archlinux.org/title/cgroups#User_delegation
Honestly this is outside my knowledge at this point
did that, doesn't change the error
I feel like this is so much over my head
maybe I should just pick a different project
Maybe mounting cgroup v1 instead would make your life easier.
But everything I have read leads me to believe that what you're doing should work
I don't see why you cannot write if you own the files.
Maybe the "containment" section does play a role here after all. I don't know.
it's pretty confusing tbh
everything is a file, except some things don't behave as usual files at all
Yeah they have extra semantics
Is there any distros best for prgramming compared to the others?
it will be manjaro though
Ubuntu and Pop os have tools for ML to easily get your graphics card working with tensor flow, Kali Linux has tools for hacking and pen testing, if you want to develop IOS games you should get a Mac. It totally depends on what type of programming.
Imagine developing for apple
how about what's the best disto to run jupyter notebook 24/7 bots on a raspberry pi 4?
trading bots (crypto/stock) & discord bots
raspbian seems like default choice
raspbian is the most sane, yes
jupyter notebook is not a good fit for bots imo
It's better to have an api of sorts running on the raspi
And a frontend on a pc which gets the necessary info from this api
You can avoid unnecessary overhead and the bot will be more responsive
Mint Linux
Is my favorite of all I've tried if your still looking give it a try with Cinnamon been using as daily driver for a few years
having an issue installing python3.9 on Rasbpian buster, read my message in #help-cupcake
message link: #help-cupcake message
@main olive that makes sense. would flask be reasonable choice?
would learning docker be worthwhile for this?
Flask...yes, haven't used it in ages so I don't remember if it has websockets support. Either way, websocket based api would the best option in case of bots and messaging applications. You could also take a look at FastApi.
Docker, in your particular case, most likely won't be required since you'll be only deploying the app on your raspi and don't need it elsewhere
At least not if you need to learn it
that's very helpful. thank you. i'll start looking at fastAPI tutorials. was thinking about docker because there's a chance i'll have to deploy similar bots to different devices but doesn't seem like it'd be super necessary to start with
Yeah, first finalize the code itself before moving to containerize it
Guys idk if the right lounge
but
I delete ubuntu partition on my windows and after extending the partiion
I was abouta go to the Prompt command to do the last command for the boot stuff
my pc got turned off
qfter viewing hella lot of YouTube videos
i was told to download windows 10 on a usb
aka bootable windows 10 usb
after that it led me to this
it's either install now
or repair your pc
what should i do
i want to keep my old files on my windows
so you have deletet ext4 partiton and you want data from it back?
no i deleted it for good my problem is when i power the pc It used to give me a choice of what os you gonna use
i had dual boo
boot
Honestly i dont know and i dont have any means to check right now
im' trying to execute the command
''
bootrec /rebuildbcd
its gives me this
basically means ''add the installation to the boot list ''more or less
it said
''the requested system device could not be found''
hmm usually my old c had 322 why is E there
okk
and this will remove grub
it is fluent
do i run this while being on diskpart?
no outside it
exit first then?
just for precaution i saw the video made this commad and then he typed exit
is it okqy to not write it ?
this one *
oh as far as im concerned you dont need it
after reboot?
aaah i should just turn off the pc ?
yes
oh ok scan os is nesecary
eh go back to shell
and run fixboot
scanos
bootrec rebuit etc... also to make sure
and dont waste time
oh god it didnt let me go to comand prompt
it sent me to this
your's usb is still inside it?
ohhh im stupid it was ment to run on windows booted
not on usb
so grub should be still there
f12 del etc
wathever will let you into bios
boot from ssd/harddrive
to windows and run commands on it
f12 where do it type it ? inside bios ?
cuz rn i can only enter bios
grub rescue is gone
you use it to enter bios...
ah ok then
you should have
something like this
choose your disk
or just remove usb
you should have boot section here. anyways just remove usb from it
and reboot
it will be easier
eh anyways
you shoudl't your's data are safe
just grub is still there
ouuf im safe
just remove usb
i removed it
reboot
and grub will show since im stupid
boot into windows
powershell/cmd as admin
still this...
wtf. go into bios and check if all drives are listed
according to the drives from this pic it seems like they are they aren't they?
ah
you had UEFI and i thought that mbr
but that is strange beacouse you did't had FAT32 prartiton
anyways switch into UEFI
how man ,all i can do is enter this bios or stare at that black window xD
did i f up when i wrote that bootelrec mbr thingy ?
what does pendrive have
oh look
it took me back here
i entered the usb
wait
letme screnn it
this thingy
basically ere
here
ok then go back to cmd
*list vol
ok your windows should be MBR since it does not have 32
and fixmbr acctualy did something
bootsect /nt60 <drive name>: /mbr
oh is it good or bad
yes im waitinf
disk 0 doesnt
and it is your main disk?
done
list volumes again it shoud show drive leters
inside disk 0
check what letter is assigned to main windows
and use bootsect /nt60 letter /mbr
it's c right
ok so well it is C
.
*you saw C and D
on diskpart or outside
outside
ops
with C:
C: Not only C ?
C:
it says Its successful
i dont understand french...
i know only how to reboot like ..normally
not legacy stuff
if you are booting into legacy it does not
if into UEFI it will pioritetize your's USB
and boot into it
it showed me this before
but anyways what shoudl i do now
ooh
i know of a way to fix this
brb
saw it on ytb i should enable legacy something
on bios 'boot options''
you should have this enabled but well worth trying
Look at this
@dapper musk a video sqid i should write down the number shown qnd press enter
ima cry ...
ehh it should work. you can do it also other way
copy files into other drive
install windows
copy them again
ia there a way to backup my current drives?
xc
i really hope i didn't touch any data from the drives
tommorow is shoudl take my pc to fix it
ok good night
gnitr
Anyone know how to merge 2 bin files into one on a mac?
does anyone know what:
ar -p ifplugd_*_armhf.deb data.tar.xz | sudo tar -xJ -C / ./usr/sbin/ifplugd
of the last param for ./usr/sbin/ifplugd does?
I've been stuck at this for days, the base command works well for extracting the binaries from a package deb file and not installing it
but anything outside that breaks root (thankfully I'm doing this on an rpi)
@dusty basalt this is gnu tar, i assume? the man page says:
tar -x [-f ARCHIVE] [OPTIONS] [MEMBER...]
and
-x, --extract, --get
Extract files from an archive. Arguments are optional. When given, they specify names of the archive members to be extracted.
so the ./usr/sbin/ifplugd argument means "extract only usr/sbin/ifplugd from the archive".
not 100% sure what you mean by "anything outside that breaks root", but note that -C means "extract files to /", so maybe you should be using -C ~/ifplugd-extract or otherwise something that isn't /, and then copying files to the right location afterwards
@formal schooner I teased out the problem
you were spot on here @formal schooner
the second argument for tar actually allows you to specify a member of a archive, it wasn't immediately clear that ./usr/sbin.ifplugd refers to the file tree within the archive. One might think that it refers to the file destination path and this was the mistake I made
if you ran ar -p ifplugd_*_armhf.deb data.tar.xz | sudo tar -xJ -C /
this copies the archive files directly to root (bad), and causes all your binaries to be overwritten
I immediately lost access to sudo, ls, basically everything
I couldn't really debug what's wrong when I could not even navigate within the terminal anymore or shutdown ---- this is what I meant by breaking root
I tried writing to a test folder, like -c /home/user/test and it appended to any files within the folder
so I'm not exactly sure what damage is caused by ar -p ifplugd_*_armhf.deb data.tar.xz | sudo tar -xJ -C /
but it was very, very frustrating to learn around this because any small misstep would cause your distribution to break.
Hejhej, i dont want to ask a super easy question but i cant find the right thing to google right now.
I have Windows on my main partition (C) and Ubuntu on D. How can i make it so that i get to choose at the start of the pc what i want to use? at the moment i have to restart the pc everytime. Do i need to get into the bios every time i start my pc?
I used to do dual booting on an old macbook and I found the rEFInd boot manager to work well. It can even be spruced up with custom themes, if you're into that sort of thing. https://www.rodsbooks.com/refind/
Ill look into it! Thanks mark 🙂
@slender rapids, may I ask what you're using Ubuntu for?
Ive been looking into deep learning a bit and ubuntu was recommended. Also i had some weird issues with python and windows
Also i like the idea of an open source product and would use it full time if i didnt like games so much 😅
Well... Canonical (the company managing Ubuntu) is kinda bleh cause they bundled some Amazon app in one of the Ubuntu releases. Sure, that was almost a decade ago, but I have no reason to risk trusting them when there are so many other distros available.
Because I am thinking that WSL might suit your needs.
ive tried wsl but i didnt get vim running on it. Not aas nicely as on unix systems
Ohh I see, alright.
its probably just my incompetence tbh
Say I have a txt file like :
bobby
daniel
john
shortest bobby
mike
fred
taller bobby
And I want to grep for lines with"bobby" but want to exclude any bobby that is preceded (taller bobby etc). How would I do about doing that?
I am thinking this would be done with regex but I can't quite fathom doing it (perhaps with a negative lookbehind?)
in plain Python i'd go with the best regex trick
Describes a regular expressions technique to match a word or pattern except in certain contexts: excluding tags, ignoring contents, word blacklist.
which would bring you to something like \w+ bobby|(bobby)
in grep i would probably just pipe that to another grep -v ' bobby' to exclude lines where there's another word in front of it
✽ It relies on your ability to inspect Group 1 captures (at least in the generic flavor), so it will not work in a non-programming environment, such as a text editor's search-and-replace function or a grep command.
@vagrant fern wow thank you for the website, seems really useful.
I will try piping that to another grep
I'm not sure if this belongs here. But I wrote a program for a not so tech savvy friend using tkinter. But the problem is that he runs Linux Mint on his old laptop and he isn't big on the terminal. So whats the best way to go about making a shortcut that will launch the program when he clicks on it?
I don't know what desktop environment Mint uses, but a general idea I have is to make the file executable with chmod +x and add a shebang at the top. Maybe the DE will recognise that and respect the shebang. If not, maybe you'd have luck doing something similar, but with a shell script that does python3 yourscript.py. Otherwise, you can look up how to create actual shortcuts for whatever DE it uses.
Ah, thanks. Thats what I figured. I was hoping to not have to use chmod. But I'm sure he'd be OK with one line in the terminal.
Hopefully; it's a one-time thing.
interesting situation! try tar -t to see what's in the archive
if they're using the Mate DE, you might need to create a "launcher" desktop entry https://unix.stackexchange.com/a/580847/73256
it's not unlike the "create shortcut" functionality in windows
https://askubuntu.com/a/286651 possibly relevant for Cinnamon
Can someone recommend a way to redirect the output of a python service with systemd? I wanna do what python3 test.py >> output.log does but for a service
StandardOutput=append:/root/output.log didn't do anything
You should be able to hijack stdout to a StringIO and do whatever you want.
How?
I don't wanna modify the .py I just wanna redirect the output to a file like python3 test.py > output.log
normally doesn't it redirect output to journald?
or do you want to also write to a log file? like what tee might do
https://stackoverflow.com/a/43830129/2954547 one possible alternative that sends output to syslog/journald and then configures rsyslog to re-emit the output to a log file
not sure why the StandardOutput=append:/foo option doesn't work
journald was missing the output from the script
what does your unit file look like? maybe you need StandardOutput=syslog although afaik that's the default
[Unit]
Description=Python script as service test
[Service]
ExecStart=python3 /root/test_service.py
Restart=always
[Install]
WantedBy=multi-user.target
Am I missing something?
I've also had StandardOutput=append:/root/output.log in previously but didn't do anything other than creating the file
does the service emit logs to stdout or stderr?
Uh, no idea to be honest, it just does prints, what does that do?
yes that should be stdout
and you put it under the [Service] block? https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=
[Unit]
Description=Python script as service test
[Service]
ExecStart=python3 /root/test_service.py
StandardOutput=append:/root/output.log
StandardError=append:/root/error.log
Restart=always
[Install]
WantedBy=multi-user.target
It was like that
Both were created but stayed empty
All the script does is
from time import sleep
while True:
print("Hello")
sleep(1)
print("Hello again")
sleep(1)
It works with the > redirect but not as a service
Hm idk it's a fresh install on GCP with their Ubuntu distro
do you see anything in journalctl from that service?
and i assume you're running this as root with the system-wide systemctl
as opposed to systemctl --user
or maybe systemctl --user but as root is more appropriate? hard to say
I'm running every command as root yes
This is what the journalctl looks like
Jul 29 16:40:19 gcp-us-c1a-f1-micro-01 systemd[1]: test_service.service: Scheduled restart job, restart counte>
Jul 29 16:40:19 gcp-us-c1a-f1-micro-01 systemd[1]: Stopped Python script as service test.
Jul 29 16:40:19 gcp-us-c1a-f1-micro-01 systemd[1]: Started Python script as service test.
Jul 29 16:40:55 gcp-us-c1a-f1-micro-01 systemd[1]: Stopping Python script as service test...
Jul 29 16:40:55 gcp-us-c1a-f1-micro-01 systemd[1]: test_service.service: Succeeded.
Jul 29 16:40:55 gcp-us-c1a-f1-micro-01 systemd[1]: Stopped Python script as service test.
Looks correct just no print outputs
Which is what I want to redirect to a log file not these status updates btw
root@gcp-us-c1a-f1-micro-01:~# systemctl daemon-reload
root@gcp-us-c1a-f1-micro-01:~# systemctl start test_service
root@gcp-us-c1a-f1-micro-01:~# systemctl status test_service
● test_service.service - Python script as service test
Loaded: loaded (/etc/systemd/system/test_service.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2021-07-29 18:28:12 CEST; 2s ago
Main PID: 102438 (python3)
Tasks: 1 (limit: 677)
Memory: 6.7M
CGroup: /system.slice/test_service.service
└─102438 /usr/bin/python3 /root/test_service.py
Jul 29 18:28:12 gcp-us-c1a-f1-micro-01 systemd[1]: Started Python script as service test.
root@gcp-us-c1a-f1-micro-01:~# l
Geekbench-5.4.0-Linux/ __pycache__/ distributor/ index/ output.log snap/ test_service.py
Geekbench-5.4.0-Linux.tar.gz dask-worker-space/ error.log monitor/ proxy/ test.py
root@gcp-us-c1a-f1-micro-01:~# tail output.log
root@gcp-us-c1a-f1-micro-01:~#
(same with error.log)
Running systemd version 246
I figured it out
I had to add Environment=PYTHONUNBUFFERED=1
ah, that's a fun one
so python simply was never flushing the output buffer
good catch
Yeah, I was lucky to find it here: https://unix.stackexchange.com/questions/408929/systemd-how-to-redirect-stdout-to-logfile
Completely unrelated to python but there's that one guy that saved me from a headache lol
no, this is a python specific thing for sure
Yeah I know I meant the thread was not related to python
PYTHONUNBUFFERED=1 was such an annoying gotcha for me. i wish python was doing that automatically if stdout wasn't a tty or something
Same, it took me half a day to debug
You could add -u to the python3 command line, instead. I'd prefer that over the environment variable, since it's not inherited across forks and therefore is a more focused fix
What does that flag do exactly? I’ll try it in a bit
Exactly the same thing.
It sets Python to unbuffered IO mode, but it only applies to that one run of Python, whereas the environment variable applies to every run of Python from the time you set it onward.
Which could, in theory, break something that expects its IO to be buffered.
Ohh gotcha
Granted it's unlikely to break anything, but I dislike global fixes to local problems
hi how to log python print statement output in log file
i try this python3 /root/filedetect.py >> /var/log/filedetect.log 2>&1
but it log other info but not python print statements.
can someone help.
alright the answer is @summer trail -u
hallo
@final echo can we continue here?
sure
yeah
ubuntu is mostly similar to windows
i can help you with setting up dev environment
okay thanks
so u use vscode right?
but u sure my pc specs dont suck?
ye
I recommend the Debian administrator handbook after you learn some basics
sure they dont
mine is almost same
with no graphics
sure thats a good idea
where do i learn the basics from
@wise valveok so let me teach you the terminal
https://ubuntu.com/tutorials/command-line-for-beginners#1-overview
you can view them here if u have doubts
maybe YouTube videos, on a top of basic commands
okay
@wise valveyou know how to open terminal
okay
sudo apt update && sudo apt update
run this command to update your system
basics
sudo = administrator
apt = ubuntu package manager (the thing where you can install stuff)
update = updating the things
upgrade = applying the update
&& = first do the command on left side then do the one on right
only if the first had a successful exit
kk im downloading
sudo
i typed sudo only
hmhmm
thats weird
Ubuntu comes with it
should i send you a screen shot?
type sudo and look if its like this
yes this appears
@wise valveyou typed sude at the second time
you wrote sude
oh yea
it's sudo
okay cool now it works
nice
done
it might take some time
I think it's something like Superuser do
ok
its basically root acceess
@wise valvenow would you like to install vscode
yes please
ye but maybe like that he can remember better
python is preinstalled right?
ok so we will get your hands wet now
okay
yep
type
python3 --version