Arch Linux and running applications in terminal as root.

Want to run app as root from the terminal? Its a bad idea from a security point of view. You need it for debugging / testing for permission issues? Ok I guess…

Running application from terminal as root will give You errors:

[root@wishmasus andrzejl]# systemsettings
No protocol specified
systemsettings: cannot connect to X server :0

[root@wishmasus andrzejl]#

To fix this add these 2 lines (modified properly):

export XAUTHORITY=/home/username/.Xauthority
export $(dbus-launch)

to this file:

/root/.bashrc

Close the terminal, re-open it, use su to gain root’s privilages and try running application again.

IF You don’t want to add this line:

export $(dbus-launch)

You can skip it but then some of the apps will spit out errors:

[root@wishmasus andrzejl]# systemsettings
QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
systemsettings(6839): KUniqueApplication: Cannot find the D-Bus session server: “Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.”

systemsettings(6838): KUniqueApplication: Pipe closed unexpectedly.

[root@wishmasus andrzejl]#

and You will need to start them with dbus-launch prefix like this:

dbus-launch systemsettings

Cheers.

Andrzej

Thank You very very much Sarah from Vodafone Ireland Customer Care helpline.

I had a dilemma today…

I am planning a “little” trip soonish and by little I mean 4 hours drive one way. It will be boring and tedious and on top of that the driver decided to not to take their own car so there is total smoking / vaping ban… Lovely… I thought – IF I am going to survive this – I need Internet on my phone… So I went to the Vodafone Ireland website to check their offers. 2 things I could do:

– spend €15 and buy 1GB internet bundle or
– opt into the FREEINT

What is the FREEINT? At the moment every time I top up with €20+ voucher I will receive 30 days of free Vodafone to Vodafone calls and text messages and 20+ Cherry Points. Good enough. FREEINT will however add 250MB of Internet data allowance to them.

Both options are great! The only problem is… I have ~€19 of credit on my phone. I don’t want to spend 3/4 of it buying a 1GB of the Internet add-on which I won’t use anyway, neither do I want to opt into FREEINT because I will need to top up my phone with €20 voucher 2 weeks ahead of time if I want to get the internet add-on… I am short on cash… It’s a week when ESB bill and rent came together… I bet You know the pain.

So… I thought MAYBE I will give Vodafone Customer Care a call. Maybe they have cheaper add-ons like a 100MB for a fiver or something like that. After going thorough the automated menu I finally had an option to speak to customer service representative. “Vodafone Customer care Sarah speaking. How can I help You?“. Polite Young woman (after confirming my identity with several security questions) patiently listened to my story. She told me about the 1GB for €15 add-on and about the FREEINT options that I had. Unfortunately there were no other (cheaper) internet bundles that the Vodafone was providing at the moment. “I am screwed.” I thought. But then Sarah said something that made my day. “I will opt You into the FREEINT, then I will top up Your account with €20 to activate it and then I will take the €20 out from Your account. I will do that as an exception…” WOW! I was floored… I could not believe it… Thank You very very much Sarah. You are a good person and a lifesaver… This means that I get the 250MB internet allowance for free and I don’t have to purchase the 1GB internet add-on or top up with €20…

I am very pleased. Thank You again Sarah from Vodafone Ireland Customer Care.

Cheers.

Andrzej

Edit 01: The Dublin trip may not be such a PITA after all… Unexpected change of driver may change many aspects of the trip. Positive vibes… at last.

My changes in the Tempera theme.

I am loving this theme but there were few changes I had to make… (with most of them I received help from Olgierd – thanks Olo!).

Added these:

#bg_image {
max-width: 100%;
height: auto;
}

.entry-content blockquote {margin-bottom: 1em;}

code, pre { background: #333; color: #18ef18 !important; }

.widget-container {
padding:2px;
margin: 2px 0 5px 0;
}

.widget-container ul li {
display:block;
float:none;
margin-bottom:2px;
}

to the Custom CSS section in the Miscellaneous settings of the Tempera:

Tempera_Settings_Miscelaneus_Custom_CSS.png

And then I had to comment few things out in the style.css file body.

/* */ out the:

white-space: nowrap;

in the:

.entry-content code {
border: 1px solid transparent;
border-bottom:3px solid transparent;
clear: both;
display: block;
float: none;
margin: 0 auto;
overflow: auto;
padding: 10px !important;
text-indent: 0;
white-space: nowrap;
}

/* */ out the

height:100%

in the:

#header-container {
display:block;
float:none;
position:absolute;
top:0px;
width:100%;
height:100%;
}

And here is my theme options export file.

Last step was to replace the files Etsy.png and Technocrati.png in the /var/www/html/wordpresswp-content/themes/tempera/images/socials/ folder with the custom SMF Forum and Piwigo icons that I have created in Inkscape.

Custom_Icons.png

Tadaaaa… All done ;).

Cheers.

Andrzej

Kdiff3… I am loving this tool… Tempera’s theme upgrade – almost a headache… Almost…

I have noticed that there is an upgrade of the Tempera theme that I am using (and enjoying very much). I did the upgrade just to realize that it overwrote my style.css file changes (I did it improperly – I should have added it in custom css file – this way it would not be overwritten – so I don’t blame them). I have a backup! HELL YEAH! But… the style.css file is 2000+ lines long – I don’t remember which lines were added / removed / modified by myself and which were not… How would I compare them? I tried diff command line tool few times. Its… not for me – not for such big task. I remembered reading about kde tool that will do the same thing… Lo and behold… Kdiff3. FANTASTIC tool. Simple. Clear. Very user friendly. Very ejeet-proof. Very very easy to read. PERFECT. Thanks to this tool I had all the changes highlighted and fixing my theme was a breeze instead of a headache. Recommending kdiff3 to anyone. Its utterly freakin brilliant.

"So You say You want to compare 2 files? Point me to them!"

Comparing_2_Files_With_kdiff3_001.png

"You don't have to search for the differences... I will clearly mark them on the scroll bar for You..."

Comparing_2_Files_With_kdiff3_002.png

"And I will add those green and blue rectangles and other visual hints so You don't get confused!"

Comparing_2_Files_With_kdiff3_003.png

Cheers.

Andrzej

Embedding, resizing and centering YouTube videos in WordPress posts.

I got very much annoyed by the fact that when I was adding YouTube video links the player size was just bloody huge… I tried finding the solution for it and at first it seemed like I have 2 choices… WordPress shortcodes or some 3rd party plug-in recommended by few users. I don’t want to add a 3rd party plug-in so I got left with shortcodes… and they simply suck… Example? You can find this on their examples site:

[youtube=https://www.youtube.com/watch?v=JaNH56Vpg-A&w=320]

[youtube=https://www.youtube.com/watch?v=JaNH56Vpg-A&w=320]

and as You can see it does nothing of what its promising. It behaves like a politician after the won elections. It just sits there and does absolutely nothing…

It almost seemed like I am out of the options… and then I have found this… I tried it using the same video as above…

[embed width=320]https://www.youtube.com/watch?v=JaNH56Vpg-A[/embed]

https://www.youtube.com/watch?v=JaNH56Vpg-A

[embed height=320]https://www.youtube.com/watch?v=JaNH56Vpg-A[/embed]

https://www.youtube.com/watch?v=JaNH56Vpg-A

Results are promising…

It’s embedded and resized. Now… Let’s try centering… Wrapping the whole thing in:

<p style="text-align: center;">TheWholeThing</p>

<p style="text-align: center;">[embed width=480]https://www.youtube.com/watch?v=JaNH56Vpg-A[/embed]</p>

https://www.youtube.com/watch?v=JaNH56Vpg-A

So… Centering works…

Now lets try starting it at 20 seconds… adding:

&#t=00m20s

<p style="text-align: center;">[embed width=640]https://www.youtube.com/watch?v=JaNH56Vpg-A&#t=00m20s[/embed]</p>

https://www.youtube.com/watch?v=JaNH56Vpg-A&#t=00m20s

That works too…

So… Embedding? &#x2713 Resizing? &#x2713 Centering? &#x2713 Starting at a certain time? &#x2713

All good.

Cheers.

Andrzej

Sometimes… On a very rare occasions I think that we might have made a mistake…

Sometimes… On a very rare occasions I think that we might have made a mistake when we have decided not to have children.

Hearing the neighbors kids playing in the garden next door is a very painful and very quick remedy for this situation…

It sounds roughly something like this:

Thank you neighbor’s kids for reassuring us in the moments of doubt…

And now if You don’t mind…

Shut_Your_Pie_Holes_And_Get_Of_My_Lawn.jpg

Cheers.

Andrzej

Ok… SO…. How much electricity / money devours my computer?

Hi folks…

I was looking for an answer to this question for a while now and thanks to some websites and thanks to my colleagues on the #pclinuxos-pl channel I finally figured it out. It’s not difficult.

When You are paying for the electricity You are paying for the amount of kilowatt hours (also called “units”) that You have used in the billing period. This is all great BUT how do I know how many of those kilowatt hours is my machine using?

This is not very difficult to calculate (approximately).

First we have to know how much electric power does Your machine needs. Sometimes You know exactly (or You can read on the label on the back of Your computer) that Your machine has X Watts adapter. This is what You need. I was not so lucky with my laptop. Label on the adapter states:

Output: 16V, 4.5A

I had to calculate the power (watts) myself. To do so I had to use this formula:

P(t) = V(t) * I(t)

where:

– P(t) is the instantaneous power, measured in watts.

– V(t) is the potential difference (or voltage drop) across the component, measured in volts.

– I(t) is the electric current, measured in amperes.

Ok so the output values of 16 volts and 4.5 amperes multiplied by each other will give me the power (watts) of my laptop’s ac/dc adapter:

P = 16V * 4.5A = 72W

My laptop’s power pack uses 72 watts. This is a very simplified / approximate value. Why? Because it’s a maximum power that the power pack can provide when laptop is using 100% of it. This means screen is on and on full brightness, WiFi, Bluetooth and all other devices are on…

What can I do with those watts then? I can convert to kilowatts. How? Divide it by 1000. This means that You take the power of the device in watts and You divide it by 1000:

72W / 1000 = 0.072kW

Now… Knowing the amount power in kilowatts and multiplying it by the amount of hours You will get the result in kilowatt hours. Let’s say that my laptop runs 24/7. All the time. 365 days per year… Ok… First I am gonna find out how many kilowatt hours it uses in one day. To do that I am gonna multiply the amount of kilowatts and the number of hours.

0.072kW * 24 = 1.728kWh

So my laptop is using 1.728 kilowatt hours during a one day. My bills are sent to me approximately every 60 days. This means that if I multiply the daily usage times 60 I will get the rough estimate of how many kilowatt hours this machine will eat in one billing period.

1.728kWh * 60 = 103.68kWh

So my machine will consume roughly 103.68kWh in 60 days right? Right. Now if I will multiply that with the current price of the kWh unit I will know approximately how much money will I have to pay for the electricity devoured by this little devil.

103.68kWh * €0.15 = €15.55

This means that if this machine was running full speed, with fully bright screen, with WiFi, Bluetooth etc. enabled, 24/7 then it would cost me approximately €16 / 2 months to power it up. This is a very pessimistic estimate. If You use power saving features of the laptop ie. if You disable screen when it’s not used, if You are scaling CPU frequency down and if You disable devices like WiFi or Bluetooth when they are not needed – You can bring that estimate down to 1/3 or even less.

You can use info from this post to calculate the price of electricity used by any other electric device over any chosen period of time. It will work provided that the device is not faulty and that it does not leaks power.

Cheers.

Andrzej

My 16 gigs Corsair Flash Voyager GT has died…

Hi folks.

My 16 gigs Corsair Flash Voyager GT has died… No biggie. I am not writing this to complain or cry out. It’s gonna be a happy ending story.

Sometime ago my other 16 gigs pendrive died on me too. It was long time after its warranty has expired. It was old. I had a spare one. No biggie. Why am I even mentioning it then? I am mentioning it simply because I want to mention the behavioral pattern. So the story is… It started few weeks before thumbdrive died completely. I had a video from a friends wedding copied onto the pendrive. I was watching it. All of the sudden SMPlayer closed – no errors – clean exit. I thought “What the hell…” and tried to play the video again. Well… No video to be played. And then I have noticed something far worse then missing video… “Holly crap where’s my pendrive…”. Yes. The dongle was not recognized by the system. I unplugged it and plugged it back in and everything worked fine again. I thought it was a USB port that was to blame. Maybe a software glitch. I remember thinking that maybe a motherboard of that lappy is going bad… Few days later I was watching some other video from this pendrive on another machine. Smplayer died again twice within 10 minutes… “Uhuh… that is not the usb / mobo problem…” I thought and I have copied all the data from the memory stick to he HDD on my main machine. I sensed the reaper coming after my old friend. After a while system was “loosing” the drive way to often – it became unreliable. I tried many things to recover it – nothing worked.

Last night I was watching a Ted.com talk from the Voyager and the SMPlayer closed. It closed again 20 minutes later… I know what’s going on and just finished copying data from the flash drive. I hear that Corsair has a great confidence in their products and they give long term warranty… 5 years or sometimes even lifetime… This pendrive is with me shorter then that… I went to the manufacturers site and reported a dying pendrive. I was told to send the Voyager to the Netherlands to be replaced. BUT… but… but… what about all my pr0n documents… I don’t want some curious dude at Corsair to be able to recover all my notes and photos and so on… How would I overwrite the drive with some useless random data that would make it harder or almost impossible to recover?

After a while of searching I have combined few commands for my convnience. Here they are:

Run these commands:

su

Now give it root’s password

Then run:

fdisk -l

That’s fdisk space dash lower case L.

This command will list all the hard drives available in Your system. Example:

[root@icsserver andrzejl]# fdisk -l

Disk /dev/sda: 40.0 GB, 40007761920 bytes
240 heads, 63 sectors/track, 5168 cylinders, total 78140160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xef08263a

Device Boot Start End Blocks Id System
/dev/sda1 * 63 73392479 36696208+ 83 Linux
/dev/sda2 73392480 78140159 2373840 5 Extended
/dev/sda5 73392543 75479039 1043248+ 82 Linux swap / Solaris
/dev/sda6 75479103 78140159 1330528+ 83 Linux
[root@icsserver andrzejl]#

This machine for example has only one HDD /dev/sda and it’s 40 gigs.

Now once You have found the correct drive run this:

dd if=/dev/urandom of=/dev/sdx & pid=$!

Remember to replace x with a correct drive letter… DO NOT MAKE A MISTAKE. DD does not ask. DD writes. If You make a mistake of writing random strings to a wrong drive You are the only one to blame…

In my case it’s /dev/sde drive that I want to “randomize” ;).

[root@wishmacer andrzejl]# dd if=/dev/urandom of=/dev/sde & pid=$!
[1] 20951
[root@wishmacer andrzejl]#

It gives me a process id and then runs in a background. You can then check the progress by issuing command:

kill -USR1 $pid

The result will look somewhat like this:

[root@wishmacer andrzejl]# kill -USR1 $pid
[root@wishmacer andrzejl]# 10171578+0 records in
10171577+0 records out
5207847424 bytes (5.2 GB) copied, 2710.78 s, 1.9 MB/s
[root@wishmacer andrzejl]#

It spits out a pretty useful info.

Sometimes it may not give You a prompt. It will look like it froze. Don’t worry. Punch enter. Prompt is back ;).

It will take a longer while but once it’s done You will see something like this:

[root@wishmacer andrzejl]# dd: writing to `/dev/sde‘: No space left on device
31719425+0 records in
31719424+0 records out
16240345088 bytes (16 GB) copied, 8522.4 s, 1.9 MB/s

This means that the process has finished. This should be sufficient – data on Your HDD has been overwritten with “random” gibberish. IF You are paranoid and You want to make the recovery process even more difficult – run the dd command few times. You don’t have to format the disk or anything. Just re-run the command in the terminal. 5 – 10 times should do it.

Cheers.

Andrzej

How to find all the empty folders inside a current folder using terminal? How to filter the output of the command to only show folders that name DOES NOT match a certain pattern?

Hi.

How to find all the empty folders inside a current folder using terminal? How to filter the output of the command to only show folders that name DOES NOT match a certain pattern?

It’s simple:

find . -depth -type d -empty | grep -i -v -e "pattern"

You can filter out more then one pattern:

find . -depth -type d -empty | grep -i -v -e "pattern1" -e "pattern2" -e "pattern3" -e "pattern4"

This command will find all the empty folders in the current (.) folder and will grep (ignoring the UPPER or lower case) for names that DO NOT match the pattern word and will display only those names.

Cheers.

Andrzej

Boy do I love sshfs… Mounting ssh / sftp share as a local drives.

Hi folks.

I have decided to re-post this because after 2 or 3 years of using this setup I am still loving it… and after few tiny modifications (mostly text formatting) here it is.

I have a machine that runs ssh server. That’s nothing new. Neither is it worth mentioning under normal circumstances… Recently I have purchased a 2 TB Western Digital MyBook USB 3.0 hard drive and I was going to use it to backup all my data. Why not make it a network shared drive I thought. It will make my life much easier if I could access the data from all my machines? Not a bad idea… I know… but I am not going to setup samba or nfs. I don’t want to make it a “network” drive. I want to have it mounted as a local drive on every machine that I use without a big fuss… How do I go about it?

I assume that You have drive attached to the ssh server running machine and that it’s mounted and that You have read and write permissions granted to Your user. I am using static IPs in my network – this is making things much easier for me as well.

In my case the drive is mounted on the server (IP 192.168.0.1 and port 20202) as /media/1862_GB_X-Ternal/ and my user andrzejl is the only user that is allowed to write to and read from it.

Now it’s time to prep the client machine. It’s really simple…

I want to have my drive mounted on my ssh client machines in /media/1862_GB_X-Ternal/ folder but I want to mount it as user (andrzejl) – not as root.

First I had to open terminal and gain root’s privileges by issuing:

su

and giving a root’s password.

Next I had to create my mount point:

mkdir -p /media/1862_GB_X-Ternal/

and make andrzejl owner of it:

chown -Rf andrzejl:andrzejl /media/1862_GB_X-Ternal/

Now that I had the folder ready I needed a package that would allow me to work with sshfs / sftp file system so in the same terminal I ran:

pacman -S sshfs

After the package was downloaded and installed I could close this terminal window and open another one. I needed to drop the root’s privileges as I want to do the rest of this as a user.

The syntax of the command looks like this:

sshfs -p sshSERVERport loginTOtheSSHserver@IPorHOSTNAMEofTHEsshServer:/where/is/the/drive/mounted/on/the/server/ /where/to/mount/on/local/machine/

Now… if I will start filling the data in this command I get this:

sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/

After running this command and typing in the password (if You got the syntax right) You should find all Your data on Your ssh client machine mounted in /media/1862_GB_X-Ternal/ ready to be read and modified by Your user.

Now…

IF You want the data to be auto-mounted at startup without typing in the password follow this post. Passwordless SSH authentication. Using authentication keys

You also need to create a mountsshfsshare.sh script in your ~/.kde4/Autostart folder and make it executable.

Here is how I do it under KDE4.

Open terminal. Type in:

touch ~/.kde4/Autostart/mountsshfsshare.sh

chmod +x ~/.kde4/Autostart/mountsshfsshare.sh

echo "sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/" > ~/.kde4/Autostart/mountsshfsshare.sh

Don’t forget to modify the sshfs line to suite Your needs.

Just to check run this:

cat ~/.kde4/Autostart/mountsshfsshare.sh

It should spit out:

sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/

or whatever command You use to mount the sshfs share. Now You can reboot the ssh client machine for testing purposes. If You did everything properly – You will have a mounted drive waiting for You next time You boot up Your machine.

Edit 01: Sometimes .sh script will not work. Try creating .desktop file then instead.

Remove the .sh file first.

rm -f ~/.kde4/Autostart/mountsshfsshare.sh

Now create the .desktop file.

touch ~/.kde4/Autostart/mountsshfsshare.desktop

Now edit the file using Your favorite editor. I will use mcedit here. Paste this into it:

[Desktop Entry]
Comment[en_US]=Mount SSHFS automagically.
Comment=Mount SSHFS automagically.
Encoding=UTF-8
Exec=sshfs -p 20202 andrzejl@192.168.0.1:/media/1862_GB_X-Ternal/ /media/1862_GB_X-Ternal/ &
GenericName[en_US]=
GenericName=
Icon=xterm-terminal
MimeType=
Name[en_US]=sshfs_mount
Name=sshfs_mount
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

Do not forget to change the sshfs line. Now save the file and reboot for testing.

Edit 02: I like this setup very much for a good few reasons. Here are just a few:

a) hard drive is being shared over the network but it feels and acts like a local drive
b) it’s not accessible by the windows machines without specific setup
c) it’s easy to setup permissions to the drive so only one user or group can have full access to the drive. You can have some folks to see the drive as read only while You keep the privileges to write to it.
d) like everything that runs via ssh the traffic between you and the hdd is encrypted

Cheers.

Andrzej