Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Ryaath
Apr 8, 2003

my bitter bi rival posted:


Can anyone help me write a sed command that makes sense for this or guide me in a better direction? I'm also using double quotes in the line above because I will eventually want to pass a variable to the command.


Allow me to introduce you to our Lord and savior, jq

Adbot
ADBOT LOVES YOU

Methanar
Sep 26, 2013

by the sex ghost

my bitter bi rival posted:

I'm not sure if this is the right thread for this (hopefully it is) but I am trying to write a sed one liner to find a string which is wrapped in curly braces, and then once its found that string, expand the selection to the leading and trailing curly braces, and then delete everything.

An example of the file I'm working with looks like this:

code:
{
  package => 'package',
  version => '1.0.0',
  commands => [
    ['jslib', '.'],
    ['thing1','thing2'],
    ['other','thing']
  ]
},
{
  package => 'winston',
  version => '1.2.3',
  commands => [
    ['jslib', '.']
  ]
},
{
  package => 'other-thing',
  version => '4.2.0',
  commands => [
    ['thing', '.'],
    ['thing', '.'],
    ['thing', '.']
  ]
},
{
  package => 'wrench',
  version => '1.0.0',
  commands => [
    ['jslib', '.'],
    ['thing','bin']
  ]
},
And what I'm trying to do is to find 'winston' (or any of the other ones) and then delete its top and bottom braces (plus the trailing comma),

Can anyone help me write a sed command that makes sense for this or guide me in a better direction?


Is there any particular reason you're treating this as a regular string and not the structured data that it is?

Can you tell us what you're actually trying to do

Docjowles
Apr 9, 2009

Use jq, or a json parsing lib in your favorite language that isn’t Bash. You can do this super easily in Python or Ruby or whatever.

Or tell us why this has to be bash.

post hole digger
Mar 21, 2011

Ryaath posted:

Allow me to introduce you to our Lord and savior, jq

Thanks, I'll check this out.

Methanar posted:

Is there any particular reason you're treating this as a regular string and not the structured data that it is?

Can you tell us what you're actually trying to do

No, no reason at all. When I started working on this, I did briefly look at jq, but I don't have a ton of experience with JSON and I wasn't sure if something like that would work because of the => symbols. I also wasn't sure if that data actually was in JSON format because of the => symbols. Also, there are some strings at the beginning of this file, and I thought that might affect how the file was read. So I thought sed would be easiest, and then started having the issues which led me to post. Basically just didn't know any better.

As for what I am doing, I am just trying to automate a workflow for myself. I am working on something that requires me to run a few bash commands, then I need to edit this file to delete a reference to the package (the part from my original post), and then run a few more commands that read that file once the string (data object?) has been removed.

Docjowles posted:

Use jq, or a json parsing lib in your favorite language that isn’t Bash. You can do this super easily in Python or Ruby or whatever.

Or tell us why this has to be bash.

It doesn't have to be in bash. I was actually looking at Ruby potentially being easier to work with, I have a little experience with that and it looks like its just a couple of lines of Ruby. The only reason I was doing it in bash is this is one step out of a dozen or so, and the other steps are just bash commands. I started writing a shell script that was just the bash commands I needed to run, then I realized I forgot this step, and went back and tried to work it in with sed, which seemed like the most sensible tool to use at the time.

post hole digger fucked around with this message at 06:40 on Nov 2, 2018

Methanar
Sep 26, 2013

by the sex ghost
The => is a bit weird but 's/ => /:/g' probably gets you to real json and then its easy to delete keys named package.

If you want, you can heredoc ruby code into the interpreter to keep everything in one big shell script.

post hole digger
Mar 21, 2011

Since the file I have to work with is not quite standard JSON and contains a few oddities (commented out blocks, => symbols, variables defined at the top of the file), I didn't want to spend too much more time trying to get jq to play nice with it, and I've gone the hacky ruby route. Here is what I ended up with if anyone cares. After I added some parenthesis around the regex, it works for my needs.

code:

  pkg = "winston"

  re = /(\{\n\s\spackage\s\=\>\s\'#{pkg}\'\,(.|\n)+?\}\,)/m

  config_txt = File.read("test.txt")

  replace = config_txt.gsub(re, "")

  File.open("test.txt", "w") {|file| file.puts replace}

Thanks for your help folks.

post hole digger fucked around with this message at 19:34 on Nov 2, 2018

SurgicalOntologist
Jun 17, 2004

So, today's the day Dropbox stops working for me. What are people switching to? Need something easy to use headless.

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

SurgicalOntologist posted:

So, today's the day Dropbox stops working for me. What are people switching to? Need something easy to use headless.
SpiderOak, probably?

other people
Jun 27, 2004
Associate Christ
Since crashplan died I have been using Jottacloud. It is cheap as chips and works with rclone. It seems good so far. I hope it doesn't disappear...

Horse Clocks
Dec 14, 2004


SurgicalOntologist posted:

So, today's the day Dropbox stops working for me. What are people switching to? Need something easy to use headless.

I’ve been using resilio sync for the last year or so with no issues.

It’s not a hosted solution, but with at least one other PC on at any point in time, it replicates across my systems well.

It also gets bonus points because it does it over LAN when it can, and can punch through NAT when it can’t.

gourdcaptain
Nov 16, 2012

I've been using SyncThing (with my home system that's almost always on as the main sync point) combined with a free Google Drive for a few files I want on my phone immediately accessible but not synced physically.

apropos man
Sep 5, 2016

You get a hundred and forty one thousand years and you're out in eight!
Syncthing on my home server which is running CentOS - almost always on.

Syncthing on a Linode VPS that costs me about £10/month and I use for other poo poo - almost always on.

Syncthing on various Windows and Linux boxes that get turned on and off. The two nodes that are almost always on ensure that the sync is permanently running.

As an emergency fallback, the home server does a nightly cronjob to ``rsync --delete`` my Syncthing folder at 2am in the morning. If I stupidly delete something something goes wrong I can retrieve a file that existed at 2am.

This is for everyday work documents and random poo poo that I throw around. Anything worth keeping that I Syncthing during the day gets moved somewhere more permanent when I get home.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Trying to install Ubuntu server on an existing rig with a zpool is sure frustrating. curtin is spotting the ZFS disks and is trying to call zpool despite the ZFS not being part of the distro out of the box, therefore failing. I mean, the gently caress why even?

Powered Descent
Jul 13, 2008

We haven't had that spirit here since 1969.

apropos man posted:

As an emergency fallback, the home server does a nightly cronjob to ``rsync --delete`` my Syncthing folder at 2am in the morning. If I stupidly delete something something goes wrong I can retrieve a file that existed at 2am.

I have a very similar setup, but since the backup location (a remote VPS) has stupid amounts of space available compared to what I'm backing up, I just have a cron job to do this every night:

code:
#!/bin/bash

# Rotate backups in a very simple brute-force way.

rm -rf /home/secondfoundation/4dayold
mv /home/secondfoundation/3dayold /home/secondfoundation/4dayold
mv /home/secondfoundation/2dayold /home/secondfoundation/3dayold
mv /home/secondfoundation/1dayold /home/secondfoundation/2dayold
cp -r /home/secondfoundation/backups /home/secondfoundation/1dayold
Simple but effective, and once or twice I've been able to recover a file that got borked a couple of days ago but I just discovered now.

I'm sure there's a more elegant way to do this, with zfs snapshots or something, but hey, this took me about thirty seconds to code up.

apropos man
Sep 5, 2016

You get a hundred and forty one thousand years and you're out in eight!

Powered Descent posted:

I have a very similar setup, but since the backup location (a remote VPS) has stupid amounts of space available compared to what I'm backing up, I just have a cron job to do this every night:

code:
#!/bin/bash

# Rotate backups in a very simple brute-force way.

rm -rf /home/secondfoundation/4dayold
mv /home/secondfoundation/3dayold /home/secondfoundation/4dayold
mv /home/secondfoundation/2dayold /home/secondfoundation/3dayold
mv /home/secondfoundation/1dayold /home/secondfoundation/2dayold
cp -r /home/secondfoundation/backups /home/secondfoundation/1dayold
Simple but effective, and once or twice I've been able to recover a file that got borked a couple of days ago but I just discovered now.

I'm sure there's a more elegant way to do this, with zfs snapshots or something, but hey, this took me about thirty seconds to code up.

Hmm. Yeah, I could add that quite easily.
Let's say my Syncthing directory is at /home/foo/sync and my nightly fallback directory is at /home/foo/accident

Currently it would be, an rsync like this:

rsync -a --delete /home/foo/sync/ /home/foo/accident/

All I would need to do is generate a random directory every night, perhaps using uuidgen:

I just knocked this up:

code:
#!/bin/bash
NEWDIR=`uuidgen`
mkdir ~/accident/$NEWDIR
rsync -a ~/sync/ ~/accident/$NEWDIR/
find ~/accident -mindepth 1 -maxdepth 1 -mtime 3 -exec rm -rf {} \;
The '-mtime 3' argument here would keep 4 days worth of directories, so you could adjust mtime to however many days you want.
You can easily list the randomly named directories by the night they were created by using 'ls -ltr' and find which day you thought you borked a file.

I forget why -mtime actually finds files a day greater than the number that you give it, but there's a reason for it if you feel like Googling it.

EDIT: Ooops! I was tired last night and missed out a plus sign. That mtime argument should be '-mtime +3', not '-mtime 3'. DOH!!

apropos man fucked around with this message at 07:50 on Nov 12, 2018

Sheep
Jul 24, 2003

Combat Pretzel posted:

Trying to install Ubuntu server on an existing rig with a zpool is sure frustrating. curtin is spotting the ZFS disks and is trying to call zpool despite the ZFS not being part of the distro out of the box, therefore failing. I mean, the gently caress why even?

In my admittedly limited experience, trying to install Ubuntu on anything except clean disks is a disaster. I crashed the 16 installer I don't know how many different ways just trying to preserve an existing LVM setup on one machine, and I had to manually edit some files in the 18.04 installer so it wouldn't crash repeatedly too.

Sheep fucked around with this message at 01:19 on Nov 12, 2018

Hekk
Oct 12, 2012

'smeper fi

I have a new XPS 13 with 4k screen running Fedora 29 with KDE. I love the laptop to death but I have to force a higher DPI to make things readable on the laptop screen since it's only 13 inches. However, I also bought a 32 inch monitor and a fancy Dell dock so I can look at the bigger screen when I am working from home. The scaling makes everything look blurry when the laptop is docked. I am wondering if there is a way to enable scaling when the display is output via the laptop screen BUT disable scaling when the display is over the 4k monitor? So far, all I've been able to do is adjust the DPI manually (which requires me to log out and back in again to take effect).

Horse Clocks
Dec 14, 2004


Which version of which desktop environment, backed by which display protocol?

If it’s anything X, no.

I think I heard about Gnome under wayland getting support for mixed dpi displays, but I don’t have any first hand experience with it.

No idea about KDE, but if wayland supports mixed dpi it should get support... eventually.

I just set my internal display to 1080p when external displays are plugged in. Usually the WM will revert it back to 4K when you unplug them.

Hekk
Oct 12, 2012

'smeper fi

Horse Clocks posted:

Which version of which desktop environment, backed by which display protocol?

If it’s anything X, no.

I think I heard about Gnome under wayland getting support for mixed dpi displays, but I don’t have any first hand experience with it.

No idea about KDE, but if wayland supports mixed dpi it should get support... eventually.

I just set my internal display to 1080p when external displays are plugged in. Usually the WM will revert it back to 4K when you unplug them.

Not sure what additional info you are looking for. Here is a screenshot showing my system details.

apropos man
Sep 5, 2016

You get a hundred and forty one thousand years and you're out in eight!
Is that conky?

That takes me back. Back to around the days of Ubuntu Gutsy Gibbon. I might actually give it a whirl.

Hekk
Oct 12, 2012

'smeper fi

apropos man posted:

Is that conky?

That takes me back. Back to around the days of Ubuntu Gutsy Gibbon. I might actually give it a whirl.

I had Conky setup with Gnome but it's a pain in the rear end to get it moved wherever I want it. This is a KDE Plasma Widget called Simple Monitor.

apropos man
Sep 5, 2016

You get a hundred and forty one thousand years and you're out in eight!
Cool!!

Volguus
Mar 3, 2009
if you're using KDE, it's a crime to not use the "Picture of the day" wallpaper.

apropos man
Sep 5, 2016

You get a hundred and forty one thousand years and you're out in eight!
I tried "Picture of the day", and it's good but I can see it clashing with Simple Monitor.

I was using the old Manjaro desktop wallpaper because I quite liked the retro colours but the stock Fedora one looks good with Simple Monitor.

Why it took me so long to get rid of the ugly Home and Wastebin directories from my desktop, I'll never know!

Hekk
Oct 12, 2012

'smeper fi

I have been using Variety to change the wallpaper periodically.

tjones
May 13, 2005

Nostalgia4Ass posted:

I have a new XPS 13 with 4k screen running Fedora 29 with KDE. I love the laptop to death but I have to force a higher DPI to make things readable on the laptop screen since it's only 13 inches. However, I also bought a 32 inch monitor and a fancy Dell dock so I can look at the bigger screen when I am working from home. The scaling makes everything look blurry when the laptop is docked. I am wondering if there is a way to enable scaling when the display is output via the laptop screen BUT disable scaling when the display is over the 4k monitor? So far, all I've been able to do is adjust the DPI manually (which requires me to log out and back in again to take effect).

Horse Clocks posted:

Which version of which desktop environment, backed by which display protocol?

If it’s anything X, no.

I think I heard about Gnome under wayland getting support for mixed dpi displays, but I don’t have any first hand experience with it.

No idea about KDE, but if wayland supports mixed dpi it should get support... eventually.

I just set my internal display to 1080p when external displays are plugged in. Usually the WM will revert it back to 4K when you unplug them.


Could you not use xrandr to scale the lower DPI monitor after setting dpi to the 4k monitor?

Man xrandr and look at --dpi, --mode and --scale. I can't test this so I'm not 100% sure this will work.


Edit: If you are using X. If Wayland, please ignore.

other people
Jun 27, 2004
Associate Christ
RHEL 8 Beta is out:

http://redhat.com/en/blog/powering-its-future-while-preserving-present-introducing-red-hat-enterprise-linux-8-beta


Still uses systemd smdh.

xzzy
Mar 5, 2009

What's the status on DNF? Got symlinks to yum?

edit - scrolled down and actually read, using yum 4. Which is DNF, right? I can't keep this poo poo straight anymore.

Docjowles
Apr 9, 2009


Probably responding to a joke/troll, but what would they reasonably replace systemd with at this point?

In before "sysv init as god intended"

xzzy
Mar 5, 2009

Docjowles posted:

Probably responding to a joke/troll, but what would they reasonably replace systemd with at this point?

docker!

other people
Jun 27, 2004
Associate Christ

xzzy posted:

docker!

supervisord

Salt Fish
Sep 11, 2003

Cybernetic Crumb

"Linux containers, Kubernetes, artificial intelligence, blockchain and too many other technical breakthroughs to list all share a common component - Linux, the same workhorse that has driven mission-critical, production systems for nearly two decades."

Blockchain!!!!

SoftNum
Mar 31, 2011

Salt Fish posted:

"Linux containers, Kubernetes, artificial intelligence, blockchain and too many other technical breakthroughs to list all share a common component - Linux, the same workhorse that has driven mission-critical, production systems for nearly two decades."

Blockchain!!!!

I'm a bit afraid of systemd artificial intelligence. Someone is going to but a kill all humans rule before asimov.d and we'll all die.

Salt Fish
Sep 11, 2003

Cybernetic Crumb
Hating systemd is a meme and nobody who actually knows what they're doing prefers it over init scripts.

G-Prime
Apr 30, 2003

Baby, when it's love,
if it's not rough it isn't fun.

No process reaping functionality.

And it can't make coffee for me.

Powered Descent
Jul 13, 2008

We haven't had that spirit here since 1969.

Docjowles posted:

Probably responding to a joke/troll, but what would they reasonably replace systemd with at this point?

The cloud! :yayclod:

apropos man
Sep 5, 2016

You get a hundred and forty one thousand years and you're out in eight!
How do I get around this error when trying to install an Ubuntu VM on the command line with virt-install:

code:
Starting install...
Retrieving file info...                                                                                                                              |   70 B  00:00:00     
Retrieving file info...                                                                                                                              |   70 B  00:00:00     
ERROR    Couldn't find hvm kernel for Ubuntu tree.
Domain installation does not appear to have been successful.
My host is CentOS 7 and works fine with a variety of CentOS and Fedora Server guests, but Ubuntu always throws up this kernel error. I remember giving up on it months ago but now I really want one Ubuntu headless VM to run UniFi on.

Super-NintendoUser
Jan 16, 2004

COWABUNGERDER COMPADRES
Soiled Meat
Here's a dumb question for the thread. For reasons, I've been using Atom as my text editor (in windows and linux). I have it setup with Git to push my note folder to a gitlab repository, so I have my notes backed up and I can sort of sync them.

I'm having a hard time finding an Atom package that will auto-save periodically and also auto-git add/commit/push on edit. I know there's probably an easier way to do this, but I'm trying to get this to work. I did find this:
https://atom.io/packages/sync-on-save
which says it does what I want, but I don't know how to setup the git hook that it wants.

Chilled Milk
Jun 22, 2003

No one here is alone,
satellites in every home
Trying out Ubuntu 18.10. Is it normal for many snaps from the store to just.. not work? Either they refuse to install or they install and won’t launch. Seems like the ones I have trouble with were published by “Snapcrafters” and not the developer.

Adbot
ADBOT LOVES YOU

mike12345
Jul 14, 2008

"Whether the Earth was created in 7 days, or 7 actual eras, I'm not sure we'll ever be able to answer that. It's one of the great mysteries."





Snapcrafters? Does that mean I can repackage popular apps with malware, and upload them?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply