« first day (2115 days earlier)      last day (2855 days later) » 

8:01 AM
yeah, probably that's the easiest solution. There should also be some form of logging utils
 
:D
 
@Serg And how do I calculate how old a timestamp is in seconds?
 
I didn't know Paper Mario could be this fun
 
Who edited my post ?
I was working on it
 
not me
 
8:06 AM
oh, terdon
 
im playing paper mario
 
it's ok, i'll just add stuff
 
@Serg Looks good.
@Serg Ah, sorry, I just fixed the backticks, they were breaking your formatting.
 
^itchy fingers
 
@terdon cool, thanks ^_^ I added a bit more stuff to the answer. Didn't even notice that those backticks were breaking the answer
 
8:13 AM
@Serg xargs is POSIX, not GNU, you don't need the disclaimer.
 
oh, ok . . .will fix that in a jiffy
So ... today i learned how to use my power bank thingy . . . which i bought for my trip in China . . . and left it home, because i didn't know how to use it then. . .
And they didn't have instructions
So I couldn't RTFM
 
rare occasion where RTFM is not applicable
 
yeah, it's hard to RTFM without TFM . . . although I should have googled . . . I also should have guessed that the powerbank doesn't have any initial charge
 
for many things I find I cannot make sense of TFM when I attempt to R it. Maybe it's a certain specialness of me
 
depends on the language TFM is written in. If it's too technical , then yeah, it won't make sense. Also lack of examples . . . .I hate man pages without examples
 
8:26 AM
I really need examples
and diagrams
and to try it out for myself... I understand & learn by doing
 
yeah . . . same here
 
and for most people I think the same is true. but the writers of TFMs seem rarely to be aware of this
 
They're aware. Some just don't like doing documentation. Writing print_usage() function in my scripts is a bother , because i know what the script does. I just know that other users will need it
2:32 AM . . .
 
Good morning
 
Good evening here . . . . or rather night
 
8:33 AM
hmm 11:30 here .. and I just woke up
 
@Serg aaah true. Personally I love to Explain Things :)
 
@Serg Can you please look over my little script here, it seems not to work: gist.github.com/ByteCommander/5ecf6a989e25159eb1283988e3d2b5d5
It refoxes firestart when the power button is pressed once, but does not detect double presses to shut down the machine.
(advice by anybody else who knows Bash is also appreciated of course)
 
omg so much time
 
I found the problem, but don't understand why:
When I manually sudo touch /tmp/powerbtn-touched and run the script immediately afterwards, it wants to reboot.
But the script does not correctly touch that file itself to update the timestamps.
Why???
 
@ByteCommander is the temp file created before script starts running ?
 
8:48 AM
No.
It may be created, but not necessarily.
Therefore I added the -e check.
The problem seems to be the touch command that does not modify the timestamp propoerly.
for whatever reason.
 
@ByteCommander what exactly you're trying to do and is that from a question ?
 
user image
2
 
@Serg It is for a question, but not directly asked that way. I want to use the power button to run a custom script when pressed once (and do not shut down) and to shut down the normal way when it is pressed twice within 5 seconds.
It works if I do not check the timestamp and touch the file but echo the current time into the file and check its content.
Why the heck is simple touch broken that way?
 
touch works for me if manually done
 
manually it works for me too, but not in the script!
@Serg I updated the Gist, this time it works.
 
8:59 AM
damn it restarted my firefox .. BRB
 
that's what it is supposed to do...
But although it now prints "rebooting" when running manually twice within 5s, it does not reboot although I uncommented that line.
 
it does update the time for me ..even using your script
 
@ByteCommander so i played around with the old version. Aside from doing "if [ -e "$mytempfile" ]" I didn't change anything else (except commenting out killing firefox). File gets touched ok within 5 seconds
 
I mean , if I wait more than 5 seconds , it shows me else part, if less than 5 seconds - it's if part
 
9:05 AM
But why...
 
@ByteCommander does it work if you add -m optin to touch ?
touch -m "$mytempfile"
 
Yup, seems like the -m fixes it.
But why does touch behave differently in a script than manually?
 
No idea. There's no subshell, so we can't blame that
3
Q: terminal command | grep IP

user565934ifconfig -a | grep 10.16 inet 10.16.x.xx netmask 0xffffff00 broadcast 10.16.x.xxx inet 10.16.x.xx netmask 0xffffff80 broadcast 10.16.x.xxx I have replaced the numbers with x My aim is to remove everything apart from the inet IP's. so it just shows as: 10.16.x.xx 10.16.x.xx Is thi...

^ This guy apparently uses Mac OS X
question is relevant to ubuntu though
 
@Serg why in the world did you vote to close this?
 
@terdon Kali
 
9:16 AM
guess not anymore
 
@Serg Oh, good grief, I didn't even notice that. Makes no difference whatsoever though, so I just removed mention of Kali.
 
Sure , that works.
 
@terdon do we keep this one as well with tags and comments removed ? askubuntu.com/q/797452/295286
Mec OS Z
How the heck it just became 3:21 AM ????
 
@Serg That one's trickier. The output format of ifconfig is different on the mac (matched what I get on my Arch, apparently, which is why I didn't even realize they were using a mac). That made the first version of my solution break on Ubuntu.
Yeah, OK, I migrated that one away.
 
9:23 AM
[ SmokeDetector ] Manually reported answer: How to write comment in .vimrc file? by user568221 on askubuntu.com
 
Need to ask someone if Macs have ip command
 
Good grief!
My script restarts Firefox, but as ROOT! O.O
 
baaaad idea
 
kittens died because of that
 
I guess a few kittens just died...
 
9:25 AM
@edwinksl @ByteCommander are you two related ?
 
lmao
 
great minds think of kittens
 
So... how can a command running as root restart a user's firefox process as this user?
 
em . . . su ?
 
9:27 AM
Does su require target user password if running as root?
 
@ByteCommander No, but why su? Use sudo -u $user command
 
Yeah.
And how do I find out which users' Firefox I just murdered?
Or I just hard-code the user...
well, no. Once I typed it, it sounds like a bad idea.
But it would be easy as killall also has an -u option.
 
@ByteCommander
$ pgrep -u 1000 firefox
12284
Then use kill $PID
or just pkill
 
Or killall -u 1000 firefox.
 
or that
 
9:30 AM
Btw, how do I kill softly?
 
With a soft pillow ?
 
I thought SIGTERM would be soft, but it crashes Firefox.
 
yeah, that's what it does. Soft kills are handled by X server
you need wmctrl for soft kills
like if you kill gnome-terminal it won't ask for confirmtion, but if you use wmctrl it will
because signals for that come from X server
and wmctrl does exactly that
it doesn't send sigterm
 
@ByteCommander try SIGQUIT or SIGINT
 
doesn't work either @terdon I have played with that many times
 
9:33 AM
SIGQUIT also brings up the restore last session dialogue.
 
What @Serg sais ^
 
Reading wmctrl source code was quite beneficial , by the way
 
And how do I find out the Firefox window?
 
@Serg How does it softkill then?
 
wmctrl -c Firefox works. Thanks!
 
9:37 AM
$(wmctrl -l | grep 'Mozilla Firefox' | tail -1 | awk '{ print $1 }')
@ByteCommander your command is not reliable
 
So I will first try to soft-kill Firefox, wait 5 seconds and then hard-kill it.
 
$(wmctrl -l | awk '/Mozilla Firefox/{k=$1}END{print k}')
 
...it closes the first found window with Firefox in it
 
right...
 
@terdon not the best
 
9:38 AM
But yours closes the first window with "Mozilla Firefox" in it.
 
better by window id
 
@JacobVlijm Why? It's just the same as yours, only more efficient.
 
@terdon source code has this function : static int close_window (Display *disp, Window win); That function ( in main.c )
That function is basically this
 
ooops, copied the wrong one...
 
static int close_window (Display *disp, Window win) {/*{{{*/
    return client_msg(disp, win, "_NET_CLOSE_WINDOW",
            0, 0, 0, 0, 0);
}/*}}}*/
it sends _NET_CLOSE_WINDOW to X server
 
9:39 AM
$(wmctrl -lp | grep "$(pgrep firefox)" | tail -1 | awk '{ print $1 }')
wmctrl -ic "$(wmctrl -lp | grep "$(pgrep firefox)" | tail -1 | awk '{ print $1 }')"
 
@Serg And what does that do, I wonder?
 
....to be complete @terdon, @ByteCommander
@terdon it closes the window gracefully
really gracefully
6
A: How do I close a new Firefox window from the Terminal?

Jacob VlijmTo make a command that finds the id of the last window, created by Firefox (and to close it), you will need wmctrl to be installed: sudo apt-get install wmctrl The command Then use the command: wmctrl -ic "$(wmctrl -l | grep 'Mozilla Firefox' | tail -1 | awk '{ print $1 }')" Explanation:...

 
I guess, I'm just wondering how. SIGHUP is the soft kill, but firefox must not be dealing with it correctly.
 
The last version closes by pid ^
 
@terdon gui apps respond to X server messages and trap those . Unless it's hard coded, they don't trap SIGHUP or SIGKILL
By the way, the post Jacob has linked was the one which prompted me to read source code of wmctrl and what it does
Actually , no
not that one
 
9:44 AM
SIGKILL can not be caught.
 
Awww, but i wanted to downvote that post !
deleted too soon
 
@JacobVlijm How does this behave when running as root?
Will it kill all users' Firefoxes?
How can I limit that to one single user?
The simplest thing would be sudo -u <UID> wmctrl...
right?
 
@NathanOsman docker is like a cardboard cutout of virtualisation
(:
 
@ByteCommander the first thought that comes into mind is that sudo wmctrl -lp only lists windows of the current user's x-session
 
But if the script runs as true root and not with sudo?
 
9:54 AM
do you ever run firefox as root btw?
 
@ByteCommander Why would there be a difference? All that changes are a couple of environmental variables.
 
That's the point.
Does wmctrl always only operate on the current active user?
I'll just sudo -u into the target user, that should be safe.
 
@NathanOsman @serg yup!
 
@JacobVlijm Btw, wmctrl does not block if the window does not react and stays open, right? The script will continue immediately without waiting?
 
Start with that. HTML version is free.
 
9:58 AM
@James Nathan was referring Androind guy to you , i think , but I am still glad to see you :) Also I know of that book , actually wanted to buy it
 
@ByteCommander subprocess.call() waits for it to finish
 
@ByteCommander i'm gonna ponder this thingy of yours. Interesting idea . . . might even write something that doesn't require root
 
Subprocess.Popen() does not...
 
I'm in a Bash script, not Python.
 
time to port bash script to python maybe ?
 
10:00 AM
I want to send the soft quit signal to all windows, wait 5 seconds and then hard-kill the remaining ones.
 
In python, a piece of cake
...using thread
 
But I'm in Bash.... :P
 
Poor guy :)
 
Do I have to send it to background then?
 
FINALLY justice :)
 
10:01 AM
sudo -u USER wmctrl ... &
 
I don't know the most efficient way in bash...
 
@James and speaking of PHP . . . is it worth learning it nowadays ?
 
Oh yes ^
 
just has to work... efficiency is not important here
 
The thing is that you need to time the 5 seconds while the closing is being tried, you need something like a second thread as far as I can see
 
10:04 AM
wmctrl returns immediately. Just tested.
So I simply do wmctrl, sleep 5, killall.
 
...not of you get the dialogue
 
Yes it does.
Tried with a gedit window.
 
@ByteCommander what should your action be for double press ? shutdown ?
 
it asked me whether I want to save and stayed open, but wmctrl returned anyway.
@Serg yes.
 
@ByteCommander well use dbus . . . that doesn't need root, and you can run your whole scripto as regular user
 
10:06 AM
@ByteCommander you are right, just tried!
 
hold on
 
@Serg yes! PHP is finally fixing many of the issues that got it a bad name.
The world needs more good PHP devs.
 
@Serg No I can't - it will get called by the acpi daemon which runs as root.
 
@ByteCommander then the script runs on, in python as well.
 
@ByteCommander use qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.Shutdown
To shutdown
And use this :
netcat -U /var/run/acpid.socket
For reading power button press
 
10:08 AM
@Serg what's the benefit over shutdown now?
 
benefit is that you don't need root
And since it's a Unity dbus call, it should work better I think ?
 
But then I have to manually poll this socket instead of waiting to get called...
 
Yes . . . what's wrong with polling ?
 
How would I do that?
 
netcat -U /var/run/acpid.socket | while read LINE ; do . . . done
Then you can use grep for "LNXPWRBN"
 
10:11 AM
Sounds reasonable.
Then I also would not have to mess around with the acpi scripts.
Thanks! :)
 
And you can save time stamp ( date +%s ) to a variable. If old time stamp is less than new timestamp , then do A. Else , do B and save old timestamp
You're very very welcome ^_^
 
I guess I'll start a proper github repo for this now.
2
A gist seems not enough.
Really? Why is that star-worthy... >.<
 
@ByteCommander you should have started the repo long time ago :p This script still can be as a gist, unless you plan to have multiple scriptos interacting
Also, not my star . . .but have another one
 
@ByteCommander do you want me to provide you an example of polling ( for inspiration ) ?
 
10:16 AM
Any cool name proposals for the repo?
 
SergIsAwesome
How's that ?
 
No thanks, I think the netcat | while read thing above is enough.
Nope.
UniversalPowerButton maybe?
But that's a bit long...
 
neopb
neo-power-button
 
hmm... :/
 
@ByteCommander just make a general repo for all AskUbuntu scripts
that's what i do
i post most serious scripts to sergrep repo
 
10:21 AM
I made an org for Ask Ubuntu answer scripts once...
But it still only contains 2 repos...
 
so add another one. AskUbuntuGeneralScripts
and since i mentioned sergrep , here it is github.com/SergKolo/sergrep
awful name, but at least people know it's mine
 
Why should I add a general repo?
 
well, why add a repo for just one script ?
 
Why not?
 
sure, can be done. repos typically are for multiple files though
 
10:35 AM
I have at least a readme and a license file.
But this one will contain more files anyway.
 
@ByteCommander so what do yoi wanna do with this script ? do you wanna add action for more keypresses ?
 
Maybe. I especially think of custom actions scripts
 
nice, nice !
I would love to contribute to this project at some point
@ParanoidPanda Wagakki have new music video out :D youtu.be/UyuzfQkUlyY
 
wow, the Axon 7 is only $400
 
@Zacharee1 how are you up this early ?
 
10:48 AM
dunno
why are you?
 
because i am a night owl who cant control my sleep even if i tried
and i tried many times
ok, im out. 88
 
@Serg FSCK you, GEMA. :-/
not in the mood for youtube over tor browser at the moment...
Uh... I think I have to use Python anyway...
 
yay for censorship . . . .@ByteCommander use tiger proxy maybe ? i use that site sometimes
@ByteCommander why have you decided to switch ?
 
Or does anyone know how I could listen for output lines of a command in Bash and execute a command once the last event was 2 seconds ago?
Because as it currently is, I only support single and double tap.
 
11:03 AM
@ByteCommander You can probably do it with expect but that's so complicated...
 
Personally I'd use timestamp difference
 
And more important, the single tap command will also be executed if I tap again right after it.
 
@Serg Weren't you going to bed? Do I need to kick you?
 
When editing files with Git I sometimes forget it's okay to commit changes that are less than 6 characters xD
 
@Serg does not prevent execution of single-tap command always before the double tap one.
 
11:04 AM
Maybe a mod message: "This user is currently suspended to get some sleep. The suspension ends in 8 hours"
5
 
It's cool, it's cool. I'm going :D
 
I would actually need some kind of multithreading in Bash here...
 
@ByteCommander keep me posted, I'm interested in this script
 
okay, will do :)
 
If @ByteCommander changes it into a repo, you could star and watch it
 
11:07 AM
it is a repo already.
It's just still empty.
Need to push first.
 
Woot
It seems like a cool idea
I could launch atom, chromium-browser and filezilla in one tap
 
@ByteCommander the au-answers org on github looks kind of official
I'm no expert, but maybe review the trademark guidelines
 
A lot of @JacobVlijm's scripts would fit in there
 
I remember we had to make some changes to the google+ group because of this
 
11:10 AM
I shall now go to eat lunch
 
@grooveplex thanks! In practice, AU is my script- database. Launchpad for the more advanced stuff.. In the beginning, I kept them locally, but my book-keeping is worse than AU :)
 
@StefanoPalazzo Thanks for the hint, I'll read your link...
@StefanoPalazzo I added "Please note this is NO OFFICIAL repository of Ask Ubuntu or Stack Exchange!" to the org's description. That should be enough, I think?
The logo is made by myself and Ask Ubuntu is spelled correctly. I see no issues here.
 
good morning
 
11:30 AM
@ByteCommander aks ubnutu
@IanC o/
:p
 
what you guys up to?
 
@IanC I'm going to review some first posts by new users
 
Serg is still here - or again...
 
guess I don't have rep to review anything yet
 
0
Q: How to count read lines and run command two seconds after last input in Bash?

Byte CommanderI want to monitor the output of a command which keeps running infinitely and prints a line every now and then. It displays events of a hardware button and each line indicates a push. My script is supposed to run other commands when it receives lines, but the problem is that not the content of th...

 
11:36 AM
@IanC Just keep going, suggest good edits to posts, post awesome answers :)
 
everytime I see a question that I've the knowledge to answer, it's already answered haha
most are out of my skill set :/
 
@IanC You'll learn
You might want to fix this one up, fix the grammar, make it readable, while preserving the question askubuntu.com/questions/798358/…
If you do your best, you'll get +2 rep.
 
I'll suggest an edit :)
 
That's what got me started and now I'm hooked.
 
man, I have a blockage to write I with lowcase
 
11:44 AM
This one needs some love too (and isn't as bad) askubuntu.com/posts/798521/edit @IanC
 
the idea is just to correct the grammar stuff or take stuff that is out of context too?
 
Just remove anything irrelevant
That's what I do
 
like 'this is a good netbook'?
lol
 
delete it
 
@ByteCommander I can't say yes or no of course. I would be surprised if there are still any issues now.
thumbsup
 
11:49 AM
:)
 
good morning
 
good morning @ThomasW.
@grooveplex, I edited the first one, what do you think?
 
Now it's placed in a queue and users with enough reputation will approve it
This takes time
But I see the edit button is greyed out for me, so another edit (yours) is pending approval. In the mean time, you can fix askubuntu.com/posts/798521/edit and askubuntu.com/posts/798491/edit
@IanC
 
coughs
i don't think it's 'pending' no more
 
@ThomasW., we were talking about internet security yesterday. Man, I got scared how unsafe some website authentications are
 
11:53 AM
that said, that one could be better written, IMO. Just not awake enough to edit it :P
@IanC welcome to the world of poor web applications
sites I don't trust I never give them a good password
randomgenerated all the way :P
 
They didn't even encrypt authentication on the user side!!!
 
yep, as I said, welcome to poor web apps and deployments
 
like, not even a xor hahaha
 
wouldn't help
HTTPS for the data traversal between endpoint client and server <-- this helps
encryption on the web app side is also something, but not implemented everywhere
 
I know, but it would be less ugly than throwing the password in text mode :/
 
11:55 AM
the huge host of issues on the web applications front is a headache, and it's why GOOD site admins make everything work :P
 
btw, do you think websites like net-force are good learning places?
I was doing some jscript challenges, just shows how client-side authentication is a sin
and how Micro$oft screws up from time to time (I mean, what the hell is that JScript.Encode?? lol)
 
5 days
 

« first day (2115 days earlier)      last day (2855 days later) »