Monday, August 18, 2014

Useful Linux scripts

Hey All! I know I havent been around of recently due to an extremely busy life. However here I am once again with something more useful for everyone! My new item on the table is a collection of Linux scripts (mostly bash) that I use everyday. Some of the collection include trim support, Google Drive, and xbind. So lets start!!!


First!!! All of these scripts can be found on Github. Linky

$git clone https://github.com/kd8bny/randoScripts.git

 FSTRIM

If anyone owns a solid-state drive (SSD) trim support is a basic requirement. The basic issue is that an SSD can write pages of memory but only delete blocks. Blocks of memory consist of many pages. i.e. (page << block) For a much more detailed explanation read here. However as of this moment Linux does not support trim automatically, but it is easily added to cron tasks. In case you are a Linux n00b cron tasks are located the system and are executed on a regular basis.
Your choices of cron are:
  • Hourly
  • Daily
  • Weekly
The script will execute whenever the system is free and calls cron. Now for fstrim I personally call this weekly, monthly might even be a better option. As soon as trim is run your files are permanently removed, this means you will NOT be able to recover anything that has been trimed. All that is required of the user is to copy the script into the correct cron folder.

$sudo cp trim /etc/cron.weekly/
BOOM! complete :) If you would like proof that is executes a log is created:
$cat /var/log/fstrim.log
 IMPORTANT!!!: Read README.md if you are using an LVM partition under EXT4.

Google Drive (grive)

As a Linux user you may know that Google has failed to provide a native drive client for us. This means you cant keep files synchronized on your drive and computer without doing so manually. Fortunately the group at The Fan Club saw the issue and provided us with grive. Grive is a 3rd party sync tool specifically for Linux. Despite how awesome this application is, it is missing an automatic synchronize. For this very reason I decided to create a cron bash script to take care of that, hence syncGrive. This script is capable of handling multiple accounts as long as they are under a single directory.


This script uses the power of the grive application by The Fan Club. To add it:
$sudo apt-add-repository http://www.thefanclub.co.za/how-to/ubuntu-google-drive-client-grive-and-grive-tools

$sudo apt-get update && sudo apt-get install grive
After the application is installed copy my srcipt to cron.
$sudo cp trim /etc/cron.hourly/
I personally run this hourly do to my extreme use of Google Drive, but choose what works for you the best. 

 IMPORTANT!!!:
  1. The script assumes the directory is "~/grive"
    1. If not change the directory in line 3
  2. By default grive does not delete removed files from the directory, however the script does. (README.md)
    1. To remove this comment: line 9:: rm -r .trash >> $LOG 
BOOM! complete AGAIN! :) If you would like proof that is executes a log is created:
$cat /var/log/syncGrive.log

xbindkeys

xbindkeys is a part of xautomation that allows you to re-purpose  extra buttons on your mouse or keyboard in Linux. I see no real reason to cover this again in this exact same blog. Here is the link to the previous write-up. Linky

No comments:

Post a Comment