I wanted to test the status of my Dropbox client from the terminal. Actually, I wanted to write a script that executes an action when my Dropbox folder is fully synced. So I wanted to test the status if it’s “working” or “synced”.
I found the solution here. It turned out that Dropbox has an official command-line script that can do this and much more. First, get it:
wget -O ~/dropbox.py https://www.dropbox.com/download?dl=packages/dropbox.py chmod u+x ~/dropbox.py ~/dropbox.py status
This is a Python script, written in Python 2, thus I modified the first line to be “
This script can do several things for you:
$ dropbox.py Dropbox command-line interface commands: Note: use dropbox help to view usage for a specific command. status get current status of the dropboxd help provide help puburl get public url of a file in your dropbox stop stop dropboxd running return whether dropbox is running start start dropboxd filestatus get current sync status of one or more files ls list directory contents with current sync status autostart automatically start dropbox at login exclude ignores/excludes a directory from syncing lansync enables or disables LAN sync
Some years ago I wrote a simple script to get the public URL of a file in my Dropbox folder. This script can do that too with the “puburl” command.
There is a command line interface for Reddit called “rtv” (reddit terminal viewer). It’s written in Python, so you can install it with
Here is a short youtube video on how to use it.
$ ping -c 1 www.google.com ping: icmp open socket: Operation not permitted
$ sudo chmod u+s `which ping` $ ping -c 1 www.google.com PING www.google.com (184.108.40.206) 56(84) bytes of data. 64 bytes from ee-in-f104.1e100.net (220.127.116.11): icmp_seq=1 ttl=45 time=38.6 ms --- www.google.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 38.681/38.681/38.681/0.000 ms
In a folder I have lots of files, and the folder also has subdirectories with further files. I want to replace a string in all of them. I want to modify the files in place.
For instance, you want to update a bunch of Python scripts from version 2 to version 3, thus you want to modify the first lines from “
#!/usr/bin/env python2” to “
I found the solution here:
grep -rli 'old-word' * | xargs -i@ sed -i 's/old-word/new-word/g' @
WARNING! Since it modifies the files in place, be very careful! First run just the beginning of the command above:
grep -rli 'old-word' *
Refine it if necessary. If it finds exactly what you need, then proceed.
You buy/get a new HDD and you want to make sure that it has no bad sectors. How to check that?
I found a solution here. In short:
sudo badblocks -wvs /dev/sdx
/dev/sdx is the drive. WARNING! This is a destructive check, i.e. all data on the drive will be lost!
“The -w option tells badblocks to write a known pattern, then read back the data to make sure it matches the pattern. It does this 4 times, using the patterns 0xaa, 0x55, 0xff, and 0x00 (alternating 0’s and 1’s, then all 1’s, then all 0’s). Note that this will overwrite all data on the drive and wipe out all the partitions, as well.” (source)
I wanted to install MongoDB on an old 32-bit laptop of mine. After installing it from the official repository, the mongo shell died with the following error: ” Illegal instruction (core dumped)”.
The problem is that the binary file uses an instruction set that is not supported by my old 32-bit CPU:
$ cat /proc/cpuinfo | grep flags flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx bts est tm2
SSE3 is missing :( What to do? Uninstall the mongodb package and 1) compile it from source, 2) install it and 3) make it start at startup.
(1) Compile the source
I found an excellent blog post about it at http://kdenby.homelinux.com/?p=25 . Here I would sum up the steps.
Download the source from here: https://www.mongodb.org/downloads . It’s about 35 MB. The source uses the SCons build system, so install the “scons” package too. Note that the compilation process took about 6 hours on my old laptop and the work directory where compilation was being done grew to 18 GB! I didn’t have that much free space so I had to move this work directory to an external HDD :) However, when you install the binaries, they will only occupy 90 MB.
So, if you have an old CPU, edit the file
if using_gcc() or using_clang(): myenv.Append( CCFLAGS=['-march=pentium3', '-mtune=generic'] ) #myenv.Append( CCFLAGS=['-march=nocona', '-mtune=generic'] )
The target architecture “nocona” was replaced by “pentium3”. Again, this tip is from Karl.
After this you can start the compilation and wait :)
$ scons --disable-warnings-as-errors --32 all
The blog post at http://kdenby.homelinux.com/?p=25 stops at this point.
(2) Install the binaries
I installed the binaries to
$ scons --prefix=/opt/mongo-3.0.5 install
Of course, replace “3.0.5” with your current version. I also put a symbolic link on this folder:
$ cd /opt $ ln -s mongo-3.0.5 mongo
Note that the binaries are put into a “
bin” folder, thus they are located in “
Now put symbolic links in
/usr/bin/ that point to the appropriate binaries in
/opt/mongo/bin/. They look like this on my machine:
$ cd /usr/bin $ ls -al | grep mongo lrwxrwxrwx 1 root root 20 11.08.2015 08:30 mongo -> /opt/mongo/bin/mongo lrwxrwxrwx 1 root root 21 11.08.2015 08:31 mongod -> /opt/mongo/bin/mongod lrwxrwxrwx 1 root root 24 11.08.2015 08:31 mongoperf -> /opt/mongo/bin/mongoperf lrwxrwxrwx 1 root root 21 11.08.2015 08:31 mongos -> /opt/mongo/bin/mongos lrwxrwxrwx 1 root root 25 11.08.2015 08:31 mongosniff -> /opt/mongo/bin/mongosniff
(3) Make MongoDB start at startup
Create these two directories:
/var/log/mongodb . The mongo daemon shouldn’t run with root privileges, so we create a dedicated user for this purpose and set its password:
$ sudo adduser mongodb $ sudo passwd mongodb
Now, the owner of the previously created two folders will be “
mongodb“, and they will belong to the “
daemon” group. Example on my machine:
$ cd /var/log $ ls -al | grep mongodb drwxr-xr-x 2 mongodb daemon 4096 11.08.2015 09:29 mongodb/
After this, you need to copy some config files as root. They are collected here.
/etc/mongodb.conf . Mine looks like this:
# See http://www.mongodb.org/display/DOCS/File+Based+Configuration for format details # Run mongod --help to see a list of options bind_ip = 127.0.0.1 quiet = true dbpath = /var/lib/mongodb logpath = /var/log/mongodb/mongod.log logappend = true noprealloc = true smallfiles = true
/usr/lib/systemd/system/mongodb.service . Sample:
[Unit] Description=High-performance, schema-free document-oriented database After=network.target [Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf [Install] WantedBy=multi-user.target
Now it’s time to enable and start the mongodb service:
$ systemctl enable mongodb.service $ systemctl start mongodb.service
Verify if it’s running:
$ systemctl status mongodb.service
If it seems OK, try to connect to it with the mongo shell using the command “
If the service doesn’t start with the
systemctl command, then try to launch the server manually:
$ mongod --quiet --config /etc/mongodb.conf
You may want to remove the “
--quiet” option. If it has some problems, it will print a more detailed error message than “
I wrote this post one week after I installed MongoDB, but I hope I didn’t forget any steps. Good luck!
You want to figure out the UUID of a partition. For instance, you want to mount a partition upon boot and thus you want to add it to your
$ sudo blkid
“The blkid program … can determine the type of content (e.g. filesystem or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).” (source: man)
As msx pointed out in the comments, you can also write “
lsblk -f“, which doesn’t require sudo rights at all.