Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 22 Dec 2014, 04:41
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Unsorted
script: simple automounter
Moderators: deshlab, Flash, GuestToo, Ian, JohnMurga, Lobster
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
MU


Joined: 24 Aug 2005
Posts: 13644
Location: Karlsruhe, Germany

PostPosted: Sat 09 Sep 2006, 09:03    Post_subject:  script: simple automounter  

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 Question

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:
#!/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:
#!/bin/bash

sleep 4
Back to top
View user's profile Send_private_message Visit_website 
Dougal


Joined: 19 Oct 2005
Posts: 2505
Location: Hell more grotesque than any medieval woodcut

PostPosted: Mon 11 Sep 2006, 05:40    Post_subject:  

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

Maybe the echos should be replaced with something like:
Code:
Xdialog --center --title "AutoMount Daemon" --no-buttons --infobox "insert-text-here" 0 0 2


Also, what about unmounting?
Back to top
View user's profile Send_private_message 
sunburnt


Joined: 08 Jun 2005
Posts: 5043
Location: Arizona, U.S.A.

PostPosted: Wed 27 Sep 2006, 14:09    Post_subject:  

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.
Back to top
View user's profile Send_private_message 
plockery

Joined: 13 Jun 2005
Posts: 26

PostPosted: Sun 15 Oct 2006, 22:44    Post_subject:  

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?
Back to top
View user's profile Send_private_message 
vern72023

Joined: 26 Dec 2005
Posts: 158
Location: Jacksonville Fl

PostPosted: Mon 16 Oct 2006, 00:08    Post_subject:  

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
Back to top
View user's profile Send_private_message 
plockery

Joined: 13 Jun 2005
Posts: 26

PostPosted: Tue 17 Oct 2006, 08:16    Post_subject:  

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
Back to top
View user's profile Send_private_message 
vern72023

Joined: 26 Dec 2005
Posts: 158
Location: Jacksonville Fl

PostPosted: Tue 17 Oct 2006, 11:31    Post_subject:  

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
Back to top
View user's profile Send_private_message 
plockery

Joined: 13 Jun 2005
Posts: 26

PostPosted: Fri 20 Oct 2006, 21:52    Post_subject:  

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?
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Unsorted
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0702s ][ Queries: 11 (0.0039s) ][ GZIP on ]