script: simple automounter

Stuff that has yet to be sorted into a category.
Post Reply
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

script: simple automounter

#1 Post by MU »

I remember that sunburnt asked for something like this, but I can't find the post again.

This script will check, if a drive (like a usb-stick) is attached, and mount it.

Then it "syncs" every 2 seconds to be shure, all data are permanently "up to date" on the stick.
So in theory the stick could be unplugged without unmounting it :?:

Replace "sda9" with the drive-name of your stick.
Save it as "/usr/bin/automountdaemon"
Make it executable:
chmod 755 "/usr/bin/automountdaemon"

Run it:
/usr/bin/automountdaemon &

To stop it, run the second script, "automount-stop".

I did not check it very intensive, and am not shure, if it is really safe to unplug a stick with this method, so see this as "brainstorming", not as a productive solution.

Mark

/usr/bin/automountdaemon

Code: Select all

#!/bin/bash

drive=sda9


oldfreespace=`df /mnt/$drive|grep dev`
freespace=`df /mnt/$drive|grep dev`

echo "automount-daemon started!"

while [ 1 ];do
  ##############################################################################
  ## we must sync every 2 seconds to be shure, all data are written to the drive
  sync

  #######################
  ## now try to mount it
  mount /dev/$drive /mnt/$drive 2>/dev/null

  ##################################
  ## if it is mounted, it must have free space, 
  ## so use this to check if mounting had success
  oldfreespace=$freespace
  freespace=`df /mnt/$drive|grep dev`

  ##################################
  
  if [ "$freespace" != "$oldfreespace" ];then
    if [ "$oldfreespace" == "" ];then
    if [ "$freespace" != "" ];then
      echo "$drive was mounted"
    fi
    fi
    if [ "$oldfreespace" != "" ];then
    if [ "$freespace" == "" ];then
      echo "$drive was unplugged"
    fi
    fi
  fi

#####################################
### these lines are only for testing
#if [ "$freespace" != "" ];then
#  echo "$drive is mounted"
#else
#  echo "$drive is not mounted"
#fi
####################################

  #####################################################
  ## the damon checks if there is a script "automount-stop" running
  ## In that case it will exit

  check=`ps |grep automount-stop|grep -v grep`

  if [ "$check" != "" ];then
    echo "automount-daemon stopped!"
    exit 0
  fi
  sleep 2
done

/usr/bin/automount-stop

Code: Select all

#!/bin/bash

sleep 4

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#2 Post by Dougal »

Hey, Mark, since it's a daemon, echoing won't be very helpful... :wink:

Maybe the echos should be replaced with something like:

Code: Select all

Xdialog --center --title "AutoMount Daemon" --no-buttons --infobox "insert-text-here" 0 0 2
Also, what about unmounting?

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#3 Post by sunburnt »

I just noticed this post looking for one of Dougal's posts.

I intend to revisit the usb-auto daemon I wrote because...
I found that the mount command can mount file systems asyncronously or syncronously!
So the loop doing sync commands shouldn't be nessasary!

I had trouble getting the daemon to recognize card readers with multiple cards in them.
As with alot of projects, I work on them in a "round robin" fashion as I learn more I go back to them.
This unfortunately slows the work on each job to a crawling pace, & project completion is naught.

plockery
Posts: 26
Joined: Mon 13 Jun 2005, 09:28

#4 Post by plockery »

Pardon my ignorance about this simple automounter script as I know nothing at all about programming or writing scripts.
But I have been wondering for some time why the programming experts who write DotPups etc. have not decided to write a DotPup for something like autofs - a very good and popular (USBstick) automounter.
Puppy is excellent for a student network environment with older computers, provided USBstick automounting is built in (to cater for different students using the pcs with different usbsticks) or able to be added via a DotPup.
Is there a reason, for those who know how, why making a DotPup for autofs would be a difficult thing to do - rather than having to "reinvent the wheel" so to speak to get such functionality into Puppy?

vern72023
Posts: 158
Joined: Mon 26 Dec 2005, 05:15
Location: Jacksonville Fl

#5 Post by vern72023 »

As I understand it the automount feature is not designed for drives with removable media, but to mount hard-disks located on other machines - similar to how a wintel box will mount a network share
.
autofs I think will mount a partition to the local disk schema but it then automatically unmounts it after a period of inactivity - like a couple of minutes or whatever - synching all changed data back of course (nix works slightly differently from wintel in the way it saves data to permanent memory.)

the trick to using autofs would be to disable the internal unmount timeout of 600 seconds and instead use something like 5 seconds, that way the computer would actually write the data as the unmount will have to sync it backas soon as it is cached.
Now to acheive that "imitaion" of the way wintel works with file systems you have to write looping scripts which constantly test for prescence of the media and then perform the synch, and mount/unmount operations.

All of this without the user seeing what is being done and protecting the new user from their lack of knowledge abt the difference between nix and wintel file operations. I think that's probably why the guys ( and I have a great deal of respect for the people like MU and Dougal and Sunburnt ) have the problems they do, trying to make linux appear as though it is windows.

windows saves data to its permananet media as that data is created on the system, linux and unix do not. They only move the data to the permanent memory when that media is unmounted, or when forced to by either internal calculations - or when instructed to by a synch command
george

plockery
Posts: 26
Joined: Mon 13 Jun 2005, 09:28

#6 Post by plockery »

Are you saying that automount in Puppy will conflict with the autofs files if it is installed via a DotPup?

Could not one then uninstall the automount in Puppy and reinstall autofs via a DotPup? Or is automount part of the fabric of Puppy in such a way as to make the installation of autofs impossible?

autofs is simple enough to install and run in other distros.
The recognition of different usbsticks for file transfers is becoming pretty basic these days.

To someone who doesn't know much about the inner workings of linux, I am wondering was is it about puppy that makes installing something like autofs too difficult?

Peter

vern72023
Posts: 158
Joined: Mon 26 Dec 2005, 05:15
Location: Jacksonville Fl

#7 Post by vern72023 »

its the same on other distros - the main problem with automount is making sure taht the removable media is synched before it is removed - if the user doesn't care about messing up the media, or its files suystem or data then there is no issue and it can be done very simply with autofs
george

plockery
Posts: 26
Joined: Mon 13 Jun 2005, 09:28

#8 Post by plockery »

I thought that synching really did not matter with usb sticks anymore.
Is it with other media that there is a problem?

I have 12 older student computers at work with arch linux, windowmaker and autofs logging in via rdesktop to a windows terminal server 2003.
All students have different usb sticks and can use anyone of these computers and their files are automatically mounted and unmounted with autofs upon insertion or unplugging of the usb stick with no problems at all.

I always wanted to use puppy on these terminals because it is much simpler to install and fast. But I need the automatic mounting and unmounting of usb sticks for students.

Hence my interest in and use of autofs. And the request for a DotPup.

If I could install autofs in puppy to work like it does in arch, synching would not be an issue.

Can that be done?

Post Reply