Download a list of files using a shell (bash) script.

Download a list of files using a shell (bash) script.


Today I'm going to share something interesting which will help you to download a large number of files at once. For one of my projects, I had to find images from Google, and upload them one by one to a particular website and create posts. At first, this was not much difficult as the number of images I needed was very little. But it kept growing and growing and I had to manually do the same thing repeatedly. Since I'm a lazy person by nature, I wanted to automate the process and here is a part of it, which I did to download the images quickly.

Unfortunately I couldn't automate the Googling part because it needed some human eyes to find quality images (I didn't want to go to the level of automation using computer vision ;) ). So however I searched for images, then whenever I found an interesting image, I right clicked on it and opened the image in a new tab (using ctrl + click). I kept doing this until I had enough images.

Here's the interesting part:

I installed this awesome Firefox extension in my browser, which allowed me to copy all of the URLS which were currently open in my brower. That was very convenient given that I had to copy each URL one by one when I began this task.

So now I have a list of URLS of the images I wanted to download. Now what? I pasted the copied list to a text document and opened another text document to write my shell (bash) script. So here it is.

#!/bin/bash

file="urls.txt"

while IFS= read line
do
    echo "$line"
    wget "$line"   
done <"$file"

Explanation: First I assign the name of the file I want to read into the file variable. Then I simply read the file line by line and run a wget command with the url to download the file.

To run this script, all I had to do was fire up a terminal, grant the execute permissions to the file and run it using the following command.

$ ./download.sh

download.sh is the name of your shell script.

That's it folks. I hope this will help someone :) Please leave a comment if you think this helped you or if you think I miss anything.

Solved - How to exit a telnet session?

How to exit a telnet session?
How to exit a telnet session?
It's funny, but I was fumbling with the terminal to exit a telnet session today. I rarely have to use telnet so I'm not much experienced with it. But if someone ever want to exit from a telnet session this is what you have to do.

Basically when you start a telnet session, this is what you would see most of the times:

~$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.


Now what? Pressing Ctrl + c, z, x, d will not do anything. I was too lazy that I didn't pay much attention to what was printed in the console. If I had read that, I would have easily exit the session.

It says:  Escape character is '^]'.

So that's it. You need to press Ctrl + ] keys and it will take you back to the telnet prompt where you can either press Ctrl + D or enter the command "quit" and press enter.

~$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.


One thing to note is that I use Terminator as my terminal emulator and this method doesn't work in it. I Still can't exit from that (: But this definitely works in the gnome terminal.

I hope this will help someone :) Please don't forget to leave a comment if you ever come across this post. Feel free to correct me or add any methods you know other than this.

Fix libQt5Charts.so.5: cannot open shared object file error with Redis Desktop Manager in Ubuntu



A few days ago, I was looking for a Redis client for Ubuntu and found that there is one called Redis Desktop Manager. Although it's free and open source, it only provides builds for Windows. Ubuntu and Mac OS users have to subscribe by making a monthly payment or they can build it by themselves using the source (: So I opted for the second option and built and installed it in my Ubuntu box since it was for a small task.

Then today, when I tried to run the RDM again, I got this error and I was wondering what might have changed in the system. In fact there was nothing changed so I had to dig a little bit more into the error and found why I got this error. So here's how I fixed it.

If you haven't built the Redis Desktop Manager (RDM) by source before, this is how to do it. (It's all well documented)

~$ git clone --recursive https://github.com/uglide/RedisDesktopManager.git -b 0.9 rdm && cd ./rdm

~$ cd src/
~$ ./configure
~$ source /opt/qt59/bin/qt59-env.sh && qmake && make && sudo make install
~$ cd /usr/share/redis-desktop-manager/bin
~$ sudo mv qt.conf qt.backup

Now it's done and you can simply run RDM by entering the command:

~$ cd /usr/share/redis-desktop-manager/bin/
~$ ./rdm

or simply by using:

~$ sh /usr/share/redis-desktop-manager/bin/rdm.sh
I believe that you are reading this blog post means you got either of the following errors when you run the above command:

/usr/share/redis-desktop-manager/bin/rdm.sh: 2: /usr/share/redis-desktop-manager/bin/rdm.sh: source: not found
/usr/share/redis-desktop-manager/bin/rdm: error while loading shared libraries: libQt5Charts.so.5: cannot open shared object file: No such file or directory

or just:

./rdm: error while loading shared libraries: libQt5Charts.so.5: cannot open shared object file: No such file or directory
It says it's unable to load the libQt5Charts.so library. So if you are sure that you have installed (I bet you have) and still get this error, you need to do a few things before running RDM.

First you need to tell it where you have the QT libraries. When you build from the source, the QT libraries are installed at /opt/qt59 directory.

So just enter the command

~$ source /opt/qt59/bin/qt59-env.sh
Now if try to run RDM again, it should work fine :) Since this seems reduntant for us to enter this command everytime we want to run the Redis Desktop Manager, you can edit the rdm.sh file and add the above line on top of it.

Note: If you paid enough attention to the build process, you may have noticed that we ran the above command during building it from the source. That's the reason why it worked a few days ago when I installed it.

So let's update /usr/share/redis-desktop-manager/bin/rdm.sh file.

~$ vim /usr/share/redis-desktop-manager/bin/rdm.sh
#!/bin/bash
source /opt/qt59/bin/qt59-env.sh
DIR=$(dirname "$(readlink -f "$0")")
export LD_LIBRARY_PATH="$DIR/../lib":$LD_LIBRARY_PATH
$DIR/rdm

Notice that we added the line: source /opt/qt59/bin/qt59-env.sh after the shebang. Now save it by pressing ESC then :wq in vim and RDM should load fine :)

I also found that having to enter long paths to run RDM is overkill. So I just added a softlink to my /usr/bin directory using the below command.

ln -s /usr/share/redis-desktop-manager/bin/rdm.sh /usr/bin/redis-desktop
Now I can run Redis Desktop Manager using the redis-desktop command.

That's it folks. I hope this will be helpful to someone. Please don't forget to let me know if I have missed anything, and leave a comment if you know a better way to do this.

Fix - PyCharm pydev debugger not working.

Fix - PyCharm pydev debugger not working.

I was using PyCharm today and I suddenly got this weird error when I started the debugger. The debugger was working fine earlier so I was a bit clueluess as to why it happened. The error I recieved was something similar to what I have shown below.

Connected to pydev debugger (build ....)
Could not connect to 127.0.0.1: 60695
Traceback (most recent call last):
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydevd.py", line 1572, in <module>
debugger.connect(host, port)
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydevd.py", line 319, in connect
self.initialize_network(s)
File "/Applications/PyCharm 2.app/Contents/helpers/pydev/pydevd.py", line 311, in initialize_network
time.sleep(0.1) # give threads time to start
KeyboardInterrupt

This is not the exact error, but it was something similar. Anyway, if you get this error and you aren't able to debug your lovely app, here is a simple fix for that.

Just remove all your hit points in the debugger and restart the debug process. It will work fine :)

That's it!! I hope this will help someone. If it helped you, don't forget to leave a comment. If you also know any other fix, let everyone know that too by leaving a comment.

Fix: /usr/bin/env: node: No such file or directory


Fix: /usr/bin/env: node: No such file or directory

When I was trying to install a module using npm today, it returned an error stating that my nodejs version is old and it needs to be updated. Then I checked the node version and it was really old, and noticed I installed it using the Ubuntu repos (which doesn't get latest updates.)

So I installed the latest LTS version of node using the Node Version Manager (NVM) and noticed that I had two versions of node running after this upgrade. ie:

$ node -v
v8.9.3

$ nodejs -v
v4.2

This caused problems when using the NPM because it was referring to old nodejs version. So I removed it with the command

sudo apt-get remove nodejs
Now whenever I ran the npm install command, it failed stating:

/usr/bin/env: node: No such file or directory
So to confirm if I'm using the right node binary, I ran the command which node and it showed the right node binary path inside the nvm directory inside my home directory.

/home/nimeshka/.nvm/versions/node/v8.9.3/bin/node
Although it showed the correct path for node, npm failed because its referring to node inside my /usr/bin path.

Then I ran the following command to see what I have in my /usr/bin/ directory for node and found that it was linked to /usr/bin/nodejs (which I uninstalled earlier).

So to fix the issue, I removed the /usr/bin/node symlink and added a new symlink to point to the right node binary path.

sudo rm /usr/bin/node
sudo ln -s /home/nimeshka/.nvm/versions/node/v8.9.3/bin/node /usr/bin/node

Instead of creating the symlink with this full path, you can enter

sudo ln -s "$(which node)" /usr/bin/node
$(which node) will be excecuted when you run the command and will be replaced with your path to node :)

I hope this post will help someone to fix this error. Please don't forget to leave a comment if this helped you, or if I have missed anything.

Fix - No Bootable Device Error in Acer laptop



Hello folks. I'm going to write about a strange and a scary problem I faced yesterday with my new laptop (hope this will help someone).

I recently got an Acer Aspire E 15 laptop and I have been enjoying working on it until last night (I still do). It's one of those laptops which you can buy for a reasonable price with some good performance. However, last night, my laptop suddenly turned off while I was working. I thought it was because my battery was empty. I switched it on again, and saw this scary message saying "No Bootable Device" with an icon of a magnifying glass. (need not to say, I was doing some important work and I had not commit my work. I thought my hard disk was gone.)

Luckily, I found some easy solutions to fix it. Here's what you have to do if you get this error.

  1.  Restart your laptop.
  2.  As soon as you see the "acer" logo coming on the screen, press F2 key. 
  3.  It will take you to the bios screen. Now, from the bios settings, change your boot method from UEFI to Legacy. (If you are lucky, you will have this option).
  4.  Press F10 to save and exit bios. Now your laptop will boot normally.

That's it guys. This is the method which worked for me. This might not work for some people because this could happen for any reason, like a hard disk failure. If your had disk is damaged, this method won't obviously fix it :) But you can always try.

I also found that disconnecting and reconnecting the hard disk cable also worked for some people. Please let us know if this helped you. Don't forget to mention any other methods you know in the comments below.

DBeaver 4.0.8 Cannot insert new record in an empty table.

Note: This issue has been fixed in DBeaver 4.1 :)




I've been using DBeaver for a while to work on some Postgres databases (because PgAdmin 4 sucks!) and I found this tool to be really awesome so far. However, as we know, not everything is perfect, and I found a little bug in DBeaver which is, that you cannot add a new record by clicking on the small plus (+) sign on the grid view. This is not working only on new / empty tables. If the table has at least one record, this works.

However, you are not left alone helpless in this case. There's a small workaround to overcome the issue. This is how to insert data into a new empty table without writing a sql query.

All you have to do it press and hold the "Shift" key while cliking on that green plus sign. Then DBeaver will add a new row as usual :) That's simple, isn't it?

I hope this will be useful to someone. Please don't forget to leave a comment if you know any other work around to this :)

Solve Ubuntu Error mounting windows partition status 14: The disk contains an unclean file system

Hello guys, here is another issue I faced today with Ubuntu 16.04. I have a laptop which runs Windows 10 and Ubuntu 16.04 on dual boot. Sometimes I have to switch between the two systems depending on the project I work. So it's very usual that I switch between them a few times in some days.

If you do the same, you may have already got this error, or at some point you will get this error when you try to mount a partition that you use with Windows and Ubuntu both. I'll show you how to fix this easily.

Error Details:

Error mounting /dev/sda2 at /media/nimeshka/6E86FACC86FA93B5: Command-line `mount -t "ntfs" -o "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000" "/dev/sda2" "/media/nimeshka/6E86FACC86FA93B5"' exited with non-zero exit status 14: The disk contains an unclean file system (0, 0).
Metadata kept in Windows cache, refused to mount.
Failed to mount '/dev/sda2': Operation not permitted
The NTFS partition is in an unsafe state. Please resume and shutdown
Windows fully (no hibernation or fast restarting), or mount the volume
read-only with the 'ro' mount option.

You get this error and you are unable to mount the partition. However, Ubuntu lets you mount the partition in a read-only mode which may be enough sometimes, but it's not a real solution to this. Before diving into fixing the problem, let's look closely at the error message once again. If you read it carefully, you will see that Ubuntu reports the error in a clear and a concise way. Towards the end of the error message, you can see it states "Please resume and shutdown Windows fully (no hibernation or fast restarting)". That basically gives you a hint on the solution. It says that Windows has not been fully shutdown, hence Ubuntu is unable to mount it. So the problem is really in Windows, not in Ubuntu.

You may wonder that you didn't hibernate Windows, then how could this happen? Yeah, it happens because with recent versions of Windows, they have introduced some new features to speed up the booting process, known as "Fast Startup" in Windows 10 and "Fast Boot" in Windows 8. It's something very similar to (or almost same as) hibernate option you had with previous Windows versions.

To fix this problem, you need to login back to your Windows OS and shutdown it properly. To do that, please follow these steps.
  1. open a command prompt with administration privileges. (To open command prompt with admin privileges, right click command prompt in the start menu and choose "Run as administrator" option).
  2.  Run the following command:
 shutdown /s 
  1. Now login back to Ubuntu to see that you can mount your drives back :)

That's it guys. I hope this wll help you. Please share this with your friends in G+, Facebook and Twitter if you think this will be helpful to them as well! Also leave a comment to give any feedback.

GIT: Display modified files in the last 'n' commits.



It's a very common thing that a developer usually commits his / her work multiple times in a day. You make changes in your branch, commit them locally, and sometimes at the end of the day, you push them to the remote repository. If you want to see the changes in your last commit, you simply run the command:

git show
But what if you only want to see the names of the files which were changed? Okay, you run the same command with the --name-only parameter. i.e.

git show --name-only
Then what if you want to see all the files which were changed today? If you have made 3 commits today, then you can run the following command to view all the files which got affected across all your commits. To do this, you have to pass the -n parameter with the number of commits you want to view.

git show -n 3 --name-only
Okay, here's another useful tip. What if you want to see the files changed in a particular commit? For that, you only have to pass the commit id.

 git show --name-only 4adf9baa857c885g5a40518ccec68961ae08cc69 And, what if you want to see the files changed in another commit along with these? To do that, again you have to pass the other commit id, as shown below.

git show --name-only 4adf9baa857c885g5a40518ccec68961ae08cc69 7bdf8bac852c865f4a40518cbec689613e07c269

That's it. I hope this will be helpful to someone :) Please don't forget to leave a comment if you know a better way or if this really helped you. You can also share this with your friends in Google+, Facebook and Twitter!

Fix HTTP Error 500 php-cgi.exe - The FastCGI process exited unexpectedly


Today I had to install IIS in my dev laptop to do some bug fixes in an old web application written with PHP 5.5. I enabled the FastCGI module in IIS and loaded the web page in the browser. But it didn't work and it kept giving me this error. It didn't explicitly mention what caused the error. So it was a bit difficult for me to find a solution to this. However finally I found a fix to this and thought I should share it in my blog so it will help someone in the future (of course, only if you had to setup IIS to work with PHP). I used PHP 5.5.3.

This is the error I received:

HTTP Error 500.0 - Internal Server Error

php-cgi.exe - The FastCGI process exited unexpectedly


Detailed Error Information
Module FastCgiModule
Notification ExecuteRequestHandler
Handler PHP
Error Code 0xc0000135 


If you get this error, the first thing you need to check is whether you have the right Visual C++ runtime package installed in your PC. If not, download and install it right away. It will surely fix your issue :)

As a help I will link to the Visual C++ package that helped me (This worked with PHP 5.5.3). If it doesn't help you, I guess you need to find the right version to download. I'll add some more links here so you can find and download it from the Microsoft website.

If you have PHP 5.5.x, Microsoft Visual C++ Redistributable 2012 package is what you need to install. Here is the link to that ->

Here is a list of other Visual C++ packages with download links from Microsoft. Make sure to download the file that suits your system architecture (32 bit / 64 bit). With 5.5, you have to download the x86 version anyway because PHP is running on 32 bit, not 64. :)

Microsoft Visual C++ Redistributable 2015

https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe

https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe

Microsoft Visual C++ Redistributable 2013
http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe

http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe

http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_arm.exe

Microsoft Visual C++ Redistributable 2012
http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU3/vcredist_x86.exe

http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU3/vcredist_x64.exe

http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU3/vcredist_arm.exe


Microsoft Visual C++ Redistributable 2010
http://download.microsoft.com/download/5/B/C/5BC5DBB3-652D-4DCE-B14A-475AB85EEF6E/vcredist_x86.exe

http://download.microsoft.com/download/3/2/2/3224B87F-CFA0-4E70-BDA3-3DE650EFEBA5/vcredist_x64.exe


Microsoft Visual C++ Redistributable 2008
http://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe

http://download.microsoft.com/download/d/2/4/d242c3fb-da5a-4542-ad66-f9661d0a8d19/vcredist_x64.exe


Microsoft Visual C++ Redistributable 2005

http://download.microsoft.com/download/d/3/4/d342efa6-3266-4157-a2ec-5174867be706/vcredist_x86.exe

http://download.microsoft.com/download/9/1/4/914851c6-9141-443b-bdb4-8bad3a57bea9/vcredist_x64.exe

Please do not forget to share this post with your friends in Facebook, Google+ or Twitter if you think this will be helpful to someone :) You can also leave a comment if you have any problems.