Agility, Java programming, New technologies and more…
  • rss
  • Home
  • Management
  • Agile Programming
  • Technology
  • Linux
  • Event
  • Android app
  • Contact
  • About the author
  • English
  • Francais

How to properly eject an external hard drive with Ubuntu?

Fabian Piau | Tuesday June 23rd, 2009 - 03:02 PM
  • Print
  • Twitter
  • LinkedIn
  • Facebook
  • Pocket

 Version française disponible

Note
Latest versions of Ubuntu now properly eject hard drives by stopping the disk rotation. So you should not have to follow the steps described in this article.

I have two Western Digital external hard drives: a Passport and a My Book model. I don’t want to do any advertisement here, but the following tip has been adapted to these models.

Thus, you will need to slightly modify the scripts for your own hard drive.

Hard drives are fully recognized by Ubuntu (mounting & unmounting). But, when I unmount one of them, disk is still in activity (spinning). And, when I disconnect my drive, I heard a clicking sound related to an aggressive head parking.

On the long run, these hard shutdowns will ultimately reduce the longevity of the hard disk.

This issue does not appear with Windows XP. In Windows, when using the “safely remove hardware”, the disk stops spinning, even though the drive keeps getting electricity from the USB cable, as a light on the drive stays on.

To remedy this problem with Ubuntu, here is the script to unmount and spin-down the hard drive. Please take note that scripts are differents depending on the kind of power supply.


If your device is powered by an external power adapter

(WD My Book model)

#!/bin/bash

WD=/dev/sdc1
# unmount
gksudo "umount $WD"
# spin down
gksudo "hdparm -Y $WD"
# message
echo message:Your WD My Book hard drive can be safely removed now. | zenity --notification --listen --window-icon="info" | zenity --notification --window-icon="info" --text="Your WD My Book hard drive can be safely removed now."

“/dev/sdc1” is the mount point of your drive.

Line 9 is not necessary. It uses the notification system to notify the user he can safely unplug the device.

Notification

Notification

To help you, the following is the command showing all the assigned mount points. Watch before and after plugging your hard drive. Thus, you will see easily which mount point is used by your device.

sudo fdisk -l
Fdisk - before plug in

Fdisk - before plug in

Fdisk - after plug in

Fdisk - after plug in


If your device is powered by the USB port itself

(WD Passport model)

#!/bin/bash

cd /sys/bus/usb/devices
good_usb=$(grep -H Western usb?/?-?/manufacturer | cut -d"/" -f1,2)
cd ${good_usb}/power
gksudo "sh -c 'echo "suspend" > level'"
echo message:Your WD Passport hard drive can be safely removed now. | zenity --notification --listen --window-icon="info" | zenity --notification --window-icon="info" --text="Your WD Passport hard drive can be safely removed now."

I have created one launcher (shortcut) for each script in the gnome panel. That’s very user-friendly with these icons.

Launchers

Launchers

My Book icon             Passport icon

As a precaution, during the execution, you will be asked for your root password (sudo).


Last resort Tip

One last thing, in case the device still seems to be spinning even after the script tells you it’s safe to unplug. It is really a “system D” tip. Sometimes, I continue to use this solution when Windows stubbornly refuses to eject my WD Passport (50% time…)

Trick is to gradually unplug the hard drive very slowly. You can feel there are two steps: a first one where spinning stops (like at the end of the script), and a second one where hard drive is shutting down.

Related posts

Chrome and disk usageSave space disk with Chrome / Chromium (or how not to lose it…) Laptop's batteryExtend your laptop’s battery life itunes-slow-snailHow to make iTunes lighter and faster on Windows? powershellPowerShell, the next-generation command-line tool
Comments
No Comments »
Categories
Linux
Tags
bash, unmount, hard drive, eject, script, ubuntu
Comments rss Comments rss

WatiN, an automation web testing tool

Fabian Piau | Wednesday June 10th, 2009 - 10:28 AM
  • Print
  • Twitter
  • LinkedIn
  • Facebook
  • Pocket

 Version française disponible

A few days ago, I discovered a kind of tools that enables you to test web applications.

WatiN (pronounced as what-in) is a .NET GUI automation framework.

By using WatiN and programming a little, you only need to execute a program and be able to surf the internet without having to surf! You got it? No? Let’s go for some explanations.

Why don’t you “automate” your everyday life? Things you often do when you surf the internet.

This software reproduces, word for word, the workflow you have programmed. Automated actions are various: click on a button, select a value in a list, capture a screenshot, save the page and so on.

The programming language is C#. If you are already familiar with Java programming, C# would be easy to understand.

I am not Microsoft addict and I am used to Eclipse but I have to admit that Microsoft Visual Studio is a great IDE. After 2 or 3 days, you get used to it and create good automation scenarios.

Technically, to “find” these buttons, lists and other HTML elements, WatiN navigates in the HTML DOM tree structure of web pages (in other words, the tags).
WatiN can interact with a lot of HTML elements (see the HTML mapping list).
WatiN identifies elements by their id, name, class, text, url, value, style… depending on your code.

To understand, the following is our first example:

public void login()
{
   // Open a new Internet Explorer Window and
   // goto a secured website
   ie = new IE('http://www.my-secured-website.com/login.php');

   // Find the user name text field and type 'toto' in it
   ie.TextField(Find.ByName('username')).TypeText('toto');

   // Find the password text field and type 'titi' in it
   ie.TextField(Find.ByName('password')).TypeText('titi');

   // Select the database
   ie.SelectList(Find.ByName('userDb')).SelectByValue('db2');

   // Click on the login button to connect
   ie.Button('loginId').Click();
}

This funtion automates the connection to a web application.

And here is the HTML code of the tested page (login.php):

<html>

<head>
</head>

<body>
    <table>
        <tr>
            <td width='100'>User Name</td>
            <td>
                <input value='' maxlength='50' name='username' type='text'>
            </td>
        </tr>
        <tr>
            <td>Password</td>
            <td>
               <input maxlength='50' name='password' type='password'>
            </td>
        </tr>
        <tr>
            <td>Database</td>
            <td>
                <select name='userDb'>
                  <option selected value='#'>Select a database</option>
                  <option value='db1'>DataBase 1</option>
                  <option value='db2'>DataBase 2</option>
                  <option value='db3'>DataBase 3</option>
                  <option value='db4'>DataBase 4</option>
                </select>
            </td>
        </tr>
        <tr height='30'><td></td></tr>
        <tr>
            <td>
                <input name='login' id='loginId' type='button' value='Login'>
            </td>
        </tr>
    </table>
</body>

</html>

What’s happening during the execution?

WatiN opens Internet Explorer, goes to the specified URL, looks for the text field named “username” and types “toto” in it. It does the same thing for the password.
Then, it selects a database in the list named “userDb” and finally, submits the form by clicking on the button identified by “loginId”.

Login page

At this point, WatiN is going to select the database and connect the user.
WatiN colors the current element it interacts with (that’s the yellow flashing).

In this example, Internet Explorer (ie) is used but WatiN supports also Firefox.

You can use the WatiN Test Recorder tool to generate code compatible with WatiN.
Perhaps, you will need to slightly modify the generated code for some optimizations, but this is really a good starting point.

Watin Test recorder Demo

A second example: a Google search (3 lines of code needed)

// Open an new Internet Explorer Window and
// goto the google website
IE ie = new IE('http://www.google.com');
 
// Find the search text field and type 'how to use watin' in it
ie.TextField(Find.ByName('q')).TypeText('how to use watin');

// Click on the Google search button
ie.Button(Find.ByName('btnG')).Click();

Example stops here, but we can imagine a processing of the results.

Related posts

Fosdem 2013Fosdem 2013 Impressions surveyFAQ – Online survey with Google Forms / Drive / Docs EclEmmaEclEmma – Do you need a good cover for this winter ? Gnome 3 ShellCustomizing Gnome 3 (Shell)
Comments
No Comments »
Categories
Agile programming
Tags
.net, automation, c#, gui test, watin
Comments rss Comments rss
Page 1 of 11
Download CarmaBlog App

RSS feeds

  • RSS feed RSS - Posts
  • RSS feed RSS - Comments

Most viewed posts

  • Changing the language in Firefox - 115,579 views
  • Using Google Forms / Drive / Docs to create an online survey - 63,166 views
  • FAQ – Online survey with Google Forms / Drive / Docs - 52,403 views
  • Customizing Gnome 3 (Shell) - 30,017 views
  • The meaning of URL, URI, URN - 17,251 views
  • Java EE & CDI vs. Spring - 15,442 views
  • Open Street Map, better map than Google Maps? - 14,648 views
  • Comparing NoSQL: Couchbase & MongoDB - 14,082 views
  • Firefox Nightly, Aurora, Beta, Desktop, Mobile, ESR & Co. - 13,087 views
  • API, REST, JSON, XML, HTTP, URI… What language do you speak? - 12,718 views

Recent Comments

  • Pauline on FAQ – Online survey with Google Forms / Drive / DocsMerci Fabian, mais le but étant que nos clients pu…
  • Fabian Piau on FAQ – Online survey with Google Forms / Drive / DocsProbablement mais ces options sont en général paya…
  • Pauline on FAQ – Online survey with Google Forms / Drive / DocsBonjour Fabian, Merci de votre retour, oui j'avais…
  • Fabian Piau on FAQ – Online survey with Google Forms / Drive / DocsBonjour Pauline, ce n'est pas possible de créer un…
  • Pauline on FAQ – Online survey with Google Forms / Drive / DocsBonjour, Je suis en train de créer un Google Forms…

Recent posts

  • How to write a blog post? At least my way! - 3 months and 2 weeks ago
  • Bot Attacks: You are not alone… - 1 year and 11 months ago
  • Flagger – Monitor your Canary deployments with Grafana - 2 years and 8 months ago
  • Flagger – Canary deployments on Kubernetes - 2 years and 10 months ago
  • Flagger – Get Started with Istio and Kubernetes - 2 years and 10 months ago
  • Expedia CoderDojo in London - 3 years and 7 months ago
  • Volunteering at Devoxx4Kids - 3 years and 10 months ago
  • A Java 11 migration successful story - 4 years and 2 months ago
  • Tips to make your WordPress website secure - 4 years and 5 months ago
  • Devoxx UK 2018 – Day 2 - 4 years and 9 months ago
  • Devoxx UK 2018 – Day 1 - 4 years and 9 months ago
  • Wise, Revolut and Monzo, a small revolution for travelers and expats - 5 years and 1 month ago
  • Autocomplete for Git - 5 years and 10 months ago
  • Swagger, the automated API documentation - 6 years and 2 weeks ago
  • Microservices architecture – Best practices - 6 years and 5 months ago
Buy me a coffee

Language

  • Français
  • English

Follow me!

Follow me on Linkedin
Follow me on Twitter
Follow me on Stackoverflow
Follow me on Github
Follow me on Rss
Link to my Contact

Email subscription

Enter your email address to receive notifications of new posts.

Tags

.net agile agility android bash best practices blog cache cloud computing conference continuous integration css developer devoxx docker eclipse extreme programming firefox flagger google helm hibernate istio java job jug kubernetes london mobile computing overview performance plugin programmer script security sharing society spring tdd test tool ubuntu windows wordpress

Links

  • Blog Ippon Technologies
  • Blog Publicis Sapient
  • Blog Zenika
  • Classpert
  • CommitStrip
  • Coursera
  • Le Touilleur Express
  • Les Cast Codeurs Podcast
  • OCTO talks !
  • The Twelve-Factor App

Categories

  • Event (15)
  • Linux (3)
  • Management (8)
  • Agile programming (29)
  • Technology (45)

Archives

  • December 2022 (1)
  • April 2021 (1)
  • June 2020 (1)
  • May 2020 (2)
  • July 2019 (1)
  • May 2019 (1)
  • December 2018 (1)
  • October 2018 (1)
  • June 2018 (1)
  • May 2018 (1)
  • January 2018 (1)
  • May 2017 (1)
  • March 2017 (1)
  • October 2016 (1)
  • April 2016 (2)
  • March 2016 (1)
  • November 2015 (1)
  • May 2015 (1)
  • February 2015 (1)
  • December 2014 (1)
  • November 2014 (1)
  • September 2014 (2)
  • August 2014 (1)
  • July 2014 (2)
  • June 2014 (1)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (1)
  • November 2013 (1)
  • October 2013 (3)
  • September 2013 (5)
  • July 2013 (1)
  • June 2013 (1)
  • May 2013 (1)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (1)
  • January 2013 (2)
  • December 2012 (2)
  • October 2012 (1)
  • September 2012 (1)
  • July 2012 (1)
  • May 2012 (1)
  • April 2012 (1)
  • March 2012 (1)
  • February 2012 (1)
  • January 2012 (2)
  • December 2011 (1)
  • November 2011 (2)
  • October 2011 (2)
  • September 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • April 2011 (1)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • November 2010 (2)
  • September 2010 (1)
  • August 2010 (1)
  • July 2010 (1)
  • June 2010 (1)
  • May 2010 (1)
  • April 2010 (1)
  • March 2010 (1)
  • February 2010 (1)
  • December 2009 (1)
  • November 2009 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (3)
  • July 2009 (1)
  • June 2009 (2)
Follow me on Twitter
Follow me on Linkedin
Follow me on Stackoverflow
Follow me on Rss
Link to my Contact
Follow me on Github
 
Fabian Piau | © 2009 - 2023
All Rights Reserved | Top ↑