Yet another month passed by, and many interesting events took place during this period. Here are a few of the highlights of the previous month.
World of FOSS:
While working with Firebug's Console or Firefox's Web Console, you have to constantly keep switching focus from the web page to the respective command line and back, using the mouse. This gets very repetitive and tiring, real fast. If you are like me, then you have probably figured that (thankfully) there are keyboard shortcuts to focus the command lines of the respective consoles.
In case you didn't know the shortcut keys, here they are:
Ctrl + Shift + L
Ctrl + Shift + K
Note: In the present stable version of Firefox (Firefox 27), the above key combination toggles the Firefox Web Console. In future versions of Firefox — probably starting from Firefox 30 — the behaviour will change to: always focus the command line (similar to the current behaviour of Firebug). Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=612253
Now that we are able to focus the command lines of the respective consoles, another problem arises.
Unfortunately, neither Firebug nor Firefox, seem to provide a shortcut to do so. At least I couldn't find a way to do so. So, I decided to use xdotool for the task.
On its website, xdotool is described as:
This tool lets you simulate keyboard input and mouse activity, move and resize windows, etc.
I used its ability to simulate mouse activity to achieve my goal. Basically, make it perform a pseudo mouse click on the web page, so that the focus is returned to the web page.
Here's a script that achieves this:
#!/usr/bin/env bash # Bring focus back to the web page # from Firebug Console's or Firefox # Web Console's command line sleep 1 # Move cursor to the specified position xdotool mousemove 475 395 # Perform a left mouse click on the above position xdotool click 1
In the following line:
xdotool mousemove 475 395
the values specify the x and y coordinates on your screen, where you wish to move your mouse pointer.
You can use:
$ xdotool getmouselocation
to get the values specific to your screen. Just make sure to move the mouse pointer to the desired location (for instance, the centre of the screen), before running this command.
Here's a sample output for your reference:
$ xdotool getmouselocation findclient: 6291502 x:475 y:395 screen:0 window:6291502
Finally, put the script contents in a file, and bind it to a key combination using your Desktop Environment, Window Manager or similar.
Now, when the respective command line is focused, and you press the key combination assigned to the above script, the focus will be returned to the web page. So, using this script and the built-in shortcuts for the command lines, you can easily toggle between the web page and the command lines.
Well, it's been a while since I posted the first Tips and Tricks article. Most of the following stuff was gathering dust (of the digital kind) ;-), waiting to be formalized into a post. So, I finally took pity of it and came up with this post.
To reap (can't kill a zombie) a stubborn zombie process, you can do either of the following:
To prevent files from being overwritten by any redirection operator such as
<>, put either of the following in your ~/.bashrc:
set -o noclobber -- or -- set -C
This can help you from accidentally overwriting files. If you decide that you do want to go ahead with the operation, you can use the
>| operator instead.
If you are often scratching your head wondering what a particular error code means, you should give errno a try. It is a part of moreutils. errno lets you look up what a particular error code means, by either specifying the name or the code of the error.
$ errno 13 -- or -- $ errno EACCES
EACCES 13 Permission denied
You can list all available error codes using:
$ errno -l
Note: That's a lowercase L.
You can even search for errors containing a given word (or words) using:
$ errno -s "search string"
Feel good stuff:
So, while I had dropped the idea of posting Interesting Links for some reasons, heavy reader demand (read: 1 reader :P) forced me to be back with this post type. From now on, I'll try to post these monthly or bi-monthly, depending upon feasibility.
Also, a very happy new year!
So here's my first post for 2014.
Linux / FOSS:
A little while ago, I had to set up a backup script using cron. dcron is my favourite cron implementation.
I have been using dcron since a few years, and it has served me well. But this time, my requirement was a bit complicated.
What I wanted to do was: Run the backup script every two days.
Now, this may sound simple to achieve using any cron implementation. Fair enough, it can be done by specifying something like the following in a crontab:
0 8 */2 * * script.sh
The above syntax will execute the given script at 8 AM, every 2 days.
Well, the catch is that this method has a huge limitation — which is — that it requires the computer to be running at the time specified, or the job will be missed.
I need to run the script on my personal computer, which isn't powered on all the time. So, this syntax was ruled out.
So, my exact requirement was to run the script, after an interval of two days, but at any time of the day (since the computer isn't guaranteed to be running at a given time of the day).
I was not sure if dcron could handle such a task. Thankfully, scouring the Man page for dcron's crontab, I found the
FREQ directive, which could get the job done.
I have been having internet speed problems lately (as always :P), which kept me from updating my Arch Linux system. Today I decided to go ahead and update the system anyway, only to find that the download speeds were excruciatingly slow. As always, whenever I need to update my system with a bad internet connection, I fall back to aria2.
Somehow, I was getting decent speeds with concurrent outbound connections, so I decided to use multiple mirrors to download the packages. aria2 supports downloading a file from multiple sources (and protocols!) at the same time.
So, I decided to generate three download lists using three of my favourite mirrors. I first did:
# pacman -Su --print > mirror1.list
And, after editing pacman's mirror file:
/etc/pacman.d/mirrorlist, I generated mirror2.list and mirror3.list in the same fashion.
Now came the real problem. When using an input file with aria2 (as I was about to), aria2 expects all the sources for a file to be specified on the same line and separated using a <Tab> character.
So, I had three input files containing urls, and they needed to be merged linewise in the above mentioned fashion.