UNIX Diary - Psychology, Philosophy, and Licenses

Users browsing this thread: 29 Guest(s)
xero
Long time nixers
dear unix diary,
today i learned about pandoc, a tool that's used to convert between markup formats. armed with this new tool i made a simple shell command that converts markdown files to man page format then pipe them into a pager. so essentially this mdcat command makes markdown files act like man pages :D

Code:
# read markdown files like manpages
mdcat() {
    grep -v "\-\-\-\-\-" "$*" | pandoc -s -f markdown -t man | groff -T utf8 -man | less
}
greduan
Long time nixers
Dear UNIX diary,

Sunny with a chance of meatballs.

OpenBSD-san is awesome. CRUX-san is awesome. I don't like systemd-san, though I'm not sure why.

OpenBSD-san is mean to me and won't turn on the screen after a suspend/resume, and I am sad that my uptime is always low because of that.

Ethernet cable-kun is strange. He needs to be in a comfortable position at an angle or otherwise he doesn't want to work.
Eduan / greduan
https://greduan.com
me@greduan.com
cjm
Long time nixers
@xero Awesome idea, very unixy. You inspired me to go looking for a markdown man page viewer and I found this:

* https://github.com/tj/mad

* PS: A big problem with pandoc for me is that its a bit of dependency hell if your not into haskell. I found [mkd2pdf](https://aur.archlinux.org/packages/mkd2pdf/) its not bad as a simpler program.

* Have a good one :)
----
blog: c-jm.github.io
twitter: https://www.twitter.com/_c_jm
My ambition in life is to be a graybeard by the time I am 65.
----
z3bra
Grey Hair Nixers
There is also ronn which can create manpages directly from markdown. Never tried it though
neeasade
Grey Hair Nixers
Dear unix diary,

Today I wrote a simple neat script. I really like discovering music on youtube by the 'up next' autoplaylist thing that youtube has going on - if I find a song I like that I am not familiar with, it is nice to get others like it! So, to feed my data hoarding, I wrote a script that takes in a youtube url, then grabs the 'up next' suggestion. And then the next one. and the next one after that. You get the idea - anyways, after all the urls are accounted for by a loop, I have youtube-dl download the audio to my music folder. I threw it into a gist as well: https://gist.github.com/neeasade/24822fe4ac96edb39187
z3bra
Grey Hair Nixers
Pretty cool! It could be nice to use it as a "background music playlist" when you get people at home.
Houseoftea
Long time nixers
Dear UNIX diary,

I wish the writers of *nix documentation had cracked open the elements of style.

What should have been a painless install of gentoo turned sour when my exotic wireless card and the messy sporadic notes that are the gentoo wiki ganged up on me.

I tried to flee back to the safety of debian to nurse my wounds only to find that I had accidentally deleted the partition. My afternoon turned into an epic hunt for my CD case. Which my brother had hidden after I continued leaving Linux live CDs in his computer to try and woo him to the freedom: he was not amused.

I found it behind a pile of clothes on the washer and popped the CD back in.
It is with a heavy heart that I type this out. For I must remake my entire setup, again.

While I was setting up my window manager I spotted a few dinosaurs in the repositories. Only in debian.
movq
Long time nixers
(Houseoftea, you have my sympathies.)


Dear UNIX diary,

I recently added "\a" to my $PS1. This way, I automatically get notified when a long running task has finished. I wonder if this is going to helpful or annoying.
z3bra
Grey Hair Nixers
Dear Unix diary,

Today I discovered a neat trick involving /proc
Some user complained AGAIN that their development server was full. Indeed, they have a component whose logs are set in "DEBUG" mode, which makes it fill the available space rather quickly (and they don't want to do anything about it, because they're lazy asses!).
So as usual, I log onto the machine, perform the traditionnal "df -h" semi-automatically, and then navigate to the log directory that I know is guilty. But this time, I was surprised:

Code:
# cd /opt/app-data/guilty/var/log
# du -sh *opt/app-data/guilty/var/log
5.1M    APP_20150720.log
72K     APP_20150721.log
72K     APP_20150722.log
72K     APP_20150723.log
237M    APP_20150724.log
0       APP_20150725.log
0       APP_20150726.log
17K     APP_20150727.log

Ah, so there might be another guilty app! which one is it?

Code:
# du -sh /opt/app-data/*
500M    app01
123M    app02
17M     app03
400M    guilty

# du -sh /
7.6G    /

WTF? Then I got enlightenned... Someone deleted a huge ass file, while it was still openned!
Dammit, I already told them not to play heroes on the box, and call me instead...
After some research and the help of our good IRC members (props to SOMEONE[1] for finding the link).

This stackoverflow post advise to use "lsof" to find the openned. I already though about it, but lsof was not installed on the box, and the disk being full didn't allow me to install it. So I had to go with another option.
Hopefully, another answer on the page suggested an alternative, which I tried immediately:

Code:
# find /proc/*/fd -ls | grep  '(deleted)'
35225653    0 lrwx------   1 appuser users          64 Jul 27 18:56 /proc/3568/fd/1 -> /dev/pts/0\ (deleted)
35225657    0 lrwx------   1 appuser users          64 Jul 27 18:56 /proc/3632/fd/2 -> /dev/pts/0\ (deleted)

I found them! I told them that restarting their component would free the space, but being too busy "coding", they couldn't afford a reboot. So I just temporarily emptied the file descriptors by hand ("> /proc/3568/fd/1" , and let them go with it.
/proc/3568/fd/1
Code:
# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       73G   6.7G 66.3G 9%  /

Hooray! Unix will always impress me!

[1] ymbx doesn't deserves the honor of being cited. Die alone man.
z3bra
Grey Hair Nixers
Dear Unix diary,

Today I scratched an itch I had for a long time, using chmod.

I've always been irritated by the fact I had to change file/directories ownership of my web root everytime I wanted to share a file, or publish a git repository. I had to let my current user own the said directories, create the files, then "chgrp -R http ." so the HTTP daemon could read it. Easy to automate, but really hackish.

This time is over.

I just discovered the 's' flag for directories. If you run

Code:
mkdir /var/www
chgrp http /var/www
chmod g+s /var/www

Then every file or directory created under /var/www will inherit it's parent group, meaning every file will be readable by group "http" if you have your umask set accordingly. It's time for a new era!

PS: sadly, I couldn't find a way to assign a umask to a group. It does not seem to be possible.
xero
Long time nixers
(24-08-2015, 07:07 PM)z3bra Wrote: chmod g+s

after we chatted on irc about this, i went home and set this up on my htpc/nas. worked like a charm. thanx again!
rocx
Members
Dear UNIX Diary,

Today I discovered the true power of a xargs. Maybe not "the true power" per se, but the first time I'd find a use for it. Close enough. hsetroot can change the wallpaper for me and meh can output the viewed file's name to standard output. You catch where I'm going with this?

Just a simple hackjob in my ~/.mkshrc...

Code:
export WALLPATH=$HOME/img/wall
...
setwall()    {
    meh $WALLPATH/* 2>/dev/null |xargs -I% hsetroot -center %
}

Boom. Interactive wallpaper changer with preview. I'll be expecting to use xargs more somewhere.
z3bra
Grey Hair Nixers
meh rocks for this! It's also pretty usefull to sort out pictures (eg removing, or flipping them)
venam
Administrators
Dear Unix Diary,
I've transitioned my irc bouncer from one server to another and changed the running port. I'm now able to connect to it from work.

These days I've been playing a lot of wargames and programming challenges on WeChall. I'm learning a lot on security of Unix servers and programs.
pranomostro
Long time nixers
Dear Unix Diary,
today I discovered profiling is pretty useful. I am currently writing uu (unsorted uniq), using a dynamically resizing array to store hash sums for the lines. Previously, I was just appending the sums to the list and searching them linearly, now I have profiled it and it is obvious that the searching is way too slow, so I decided to insert the hashsums and use binary search.
kirby
Long time nixers
Dear Unix Diary,

Today I had an actually enjoyable day at work, I found some box used to flash firmware on to SSDs, and got to mess around with it for a while. Ended up writing some C to communicate with it over serial, great stuff. Then once I understood how it worked, I had to install CentOS 6.5 on it and get some Python working on it. I have no idea how Python libraries work, but apparently the answer is 'not well' because installing wxPython was a nightmare. I'm not even sure how to start the program, there's just a 'scripts' directory with a load of random Python. Gah.
xero
Long time nixers
dear unix diary,
i've been doing more devops/sysadmin stuff at work recently. i've been tasked with creating automation scripts, and i recently learned about expect

Quote:Expect is a program that "talks" to other interactive programs according to a script. Following the script, Expect knows what can be expected from a program and what the correct response should be. An interpreted language provides branching and high-level control structures to direct the dialogue. In addition, the user can take control and interact directly when desired, afterward returning control to the script.

so it's an evaluation engine that you can "pre-script" interactions with other software (mainly those which prompt for user input). it's a similar concept to the yes utility, but is far more flexible.

here's an example. say you connect to an open vpn server that interactively prompts you for your username/password after the initial handshake:

Code:
#!/usr/bin/expect -f

spawn sudo openconnect --juniper vpn.whatever.com
expect "username:"
send "xero\r"
expect "password:"
send "xxxxxxxxxxxxxx\r"
expect "ESP session established with server"
interact

first: set the correct shebang for expect scripts. the spawn directive allows you to run a command. expect looks for a string (regex) returned from the previous command(s). when an expect is matched the next line will execute. in this case it's the send command, which mimics users input. here we're entering our username then pressing return (\r). there's another set of expects on the password, as well as the final expect for a successful login. the final line is the interact directive, which simple holds the program open waiting for manual user interaction. but in this case it simply keeps the vpn connection open. without this final command the script would have terminated and closed any programs it's run with the spawn method.

this is very cool, but it's a simple / dumb example. here i have my username and password hard coded into the script. this can be very dangerous / insecure, but i thought a simple script to explain the concept would work out better.
venam
Administrators
Dear Unix diary,
I've fixed my urxvt perl plugins. For some reasons the selection in url-select didn't copy to the clipboard when yanking.

Knowing perl helps a lot in those cases. If I ever get an idea for a plugin it'll be easy to implement.
darthlukan
Members
Dear UNIX diary,

I learn a new thing every day. Today I learned of the awesome-ness known as wmutils. It's changed my life and I can already feel the productivity gains. I do see that there are a lot of scripts to be written in order to make this work perfectly for me, but that's what I want, so it's okay.

(Thanks for writing wmutils z3bra and dcat!)
Github: https://github.com/darthlukan
CRUX Ports: http://ports.brianctomlinson.com
GPG: 3694569D
"We're all human, act accordingly." -- Me
dkeg
Members
Dear Unix diary,

Its complete. Consistent theming across GTK and CLI from xcolors. Its a bit ironic. You spend so much time to make ricing easier and more automated. Now that I have put in the final puzzle piece, I realized oddly enough it's the process of making the consistency happen that was also fun. Now that its automatic, its kind of anticlimatic. Weird how that works. Next up, wrap functionality and logic around some of my disparate scripts to create something new. Anyway, thank you awk,sed,cut. And thank you xrdb.
work hard, complain less
darthlukan
Members
Dear UNIX diary,

Today I learned enough sed and awk to be slightly more than just dangerous. I know that this feeling of unstoppable-ness is premature since I will most-likely cause more harm than good, but holy shit why didn't I bother to use these tools sooner? Just the little I know now would have helped out so much over the last two decades. Oh well, better late than never.
Github: https://github.com/darthlukan
CRUX Ports: http://ports.brianctomlinson.com
GPG: 3694569D
"We're all human, act accordingly." -- Me
pranomostro
Long time nixers
@darthlukan:
Interesting: Today I was writing two small programs, omit and take, to deal with columnized input.
Both are written in awk and not yet finished, but I feel like they will be a great deal when dealing with things
like ps or git blame, because too many columns are not always fun.

Dear Unix diary,
today I discovered something nice about git branch: you can use git branch in you .config directory to switch configurations
very easily. This way, I manage my upcoming wmutils configuration and keep it nicely separated from my current, finished
awesome setup.
apk
Long time nixers
Dear Unix diary,
i fucking mkfs.vfat'd my root partition, mistaking it for my EFI System Partition.







For the 5th time.
Mafia
Long time nixers
(06-10-2015, 02:41 PM)dsplayer14 Wrote: Dear Unix diary,
i fucking mkfs.vfat'd my root partition, mistaking it for my EFI System Partition.







For the 5th time.
L...f*ck*ng O.....L
kirby
Long time nixers
Dear Unix Diary,

Today I started learning Haskell at Uni. Looks like a really cool language, but the lecturer is a tad...eccentric and he's making us use hugs, which hasn't been updated since 2006.
pranomostro
Long time nixers
Dear Unix Diary,

Yesterday I began working on the Potion programming language (a former project by _why, www.github.com/scharlatan/potion/).
I deleted more than 6000 lines (while adding only 61 lines).
Seems to start fine.
venam
Administrators
(13-10-2015, 08:37 AM)pranomostro Wrote: Dear Unix Diary,

Yesterday I began working on the Potion programming language (a former project by _why, http://www.github.com/scharlatan/potion/).
I deleted more than 6000 lines (while adding only 61 lines).
Seems to start fine.

Deleting lines is always good. I'm currently doing the same with a very old project of mine.
Good job!
xero
Long time nixers
(13-10-2015, 08:37 AM)pranomostro Wrote: Yesterday I began working on the Potion programming language (a former project by _why, http://www.github.com/scharlatan/potion/).

Code:
~
           .ooo
            'OOOo
        ~ p ooOOOo tion ~
            .OOO
             oO      %% a little
               Oo    fast language.
              'O
               `
              (o)
          ___/ /          
         /`    \
        /v^  `  ,
       (...v/v^/
        \../::/
         \/::/

nice readme ascii!
pranomostro
Long time nixers
@venam:
»My most productive day was when I deleted 1000 lines of code«
-- Ken Thompson --
@xero:
I know.
Not by me, unfortunately! _why was seriously great.
And since perl11.org stopped working on it, I decided I could give it a try.
venam
Administrators
Dear Unix diary,
I wished I had new ideas for Unix related projects but I'm not getting a lot these days.
No problem, ideas can't be forced out of a brain.

I tried out the autotheme script that neeasade arranged together by grouping programs that automatically set a specific part of a desktop environment. It's nifty, I love it.
It has URNN which is an AI we wrote to smartly create a terminal colorscheme based on the wallpaper image, then based on those colors another program called oomox will generate a gtk theme that will perfectly fit, and finally ACYL (AnyColorYouLike) icon theme, which I was already using, is automatically customized with a color that will fit.

Plus, I use the 2bwmColor that will also, yet again, make my wm borders fit with the theme.

Everything fits, all is in order!

This conclude the talk we had on Telegram about the "automatic artificial intelligence ricer". It's a dream come true!

However, the base of all the cycle is URNN and the neural network needs more training to be better. Neeasade recently contributed to the repo by writing a wrapper that'll help the contributors.

Kudos bro!

Apart from that I've been doing the usual things, resuscitating old projects and playing hacking challenges.
The project I'm working on will have a refactor of the Unix-python-cli-template.
The challenges are sometimes easier because of my Unix knowledge. It's impressive how much you learn about the underlying technology when you enter the Unix world.

Have a sweet and wonderful day!