You are not logged in.

#1 2004-03-02 00:03:24

wakeupbomb
Member
From: Liverpool, UK
Registered: 2004-02-15
Posts: 164

mount iso bash script

Hey there. Any ideas how I could use a bash script to automatically mount an iso? For example if I click on an iso file in rox then it'll mount it to /mnt/iso? Iv'e tried setting up a file /usr/bin but I can't seem to get it figured out. I know the command is this
mount -t iso9660 -o loop,ro my.iso /my/mountpoint
and that works swimmingly from within a term. It's just a pain having to type it out every time. And I can never remember it.
Hopefully this is possible as I found a bash script today to view all the pictures within an archive in imagmagick. Which is incredibly useful.

Thanks, hope this makes sense

*edit* just found this but you need to be root, has a naff gui, and uses KDE.... But it's a start.  smile

#! /usr/bin/env bash

mountdir=`kdialog --inputbox "Enter directory name to mount iso to"`;

if [[ ! -e "$mountdir" ]]; then
 kdialog --yesno "Directory does not exist, create it?" && mkdir "$mountdir";
 if [[ ! -e "$mountdir" ]]; then
   echo "Cannot mount iso image.";
   exit 1;
 fi
fi

mount -t iso9660 -o loop "$1" "$mountdir";

Offline

#2 2004-03-02 11:24:29

farphel
Forum Fellow
From: New Hampshire - USA
Registered: 2003-09-18
Posts: 250
Website

Re: mount iso bash script

You could add this to your .bashrc file.

mountiso() {
  if [ "`mount | grep /mnt/iso`" ]; then
    echo "/mnt/iso is already in use"
    return
  fi
  if [ ! "$1" ]; then
    echo "missing iso image argument"
    return
  fi
  if [ ! -f $1 ]; then
    echo "$1: iso image not found"
    return
  fi
  mount -t iso9660 -o loop,ro $1 /mnt/iso
}

Usage would be 'mountiso my.iso'.

This has the /mnt/iso hardcoded, but you could easily pass that it and use $2 as the second argument.  NOTE: Spacing/quoting is VERY important in bash scripting; you're better of copy/pasting this than retyping it.  Oh, and I didn't really test it either... wink


Follow the link below, sign up, and accept one promotional offer.  If I can get five suckers (err... friends) to do this, I'll get a free iPod.  Then you too can try to get a free iPod. Thanks! http://www.freeiPods.com/?r=11363142

Offline

#3 2004-03-02 16:21:34

wakeupbomb
Member
From: Liverpool, UK
Registered: 2004-02-15
Posts: 164

Re: mount iso bash script

cheers big_smile

Offline

Board footer

Powered by FluxBB