PDA

View Full Version : Automount all partitions shell script help


iisjman07
01-30-2011, 09:57 AM
Hey, I'm trying to create a shell script that will scan with avira antivirus using my bootable ubuntu usb drive. What I need help with is a way of automatically mounting all partitions from the host so that they can be scanned. I don't however know how to mount all generic partitions into /media/. Anybody got a quick and hopefully easy way to do this?

wimwauters
01-30-2011, 03:54 PM
Do some investigation of the Avira and AVG live/rescueCDs: aren't their boot scripts readable from the CD?

iisjman07
01-30-2011, 04:18 PM
Do some investigation of the Avira and AVG live/rescueCDs: aren't their boot scripts readable from the CD?

I'm not sure but that's a great idea. Thanks, I'll look into that soon

Ccomp5950
01-31-2011, 12:51 AM
This is what I've used for a while.

#!/bin/sh

mountdrive=`fdisk -l | grep NTFS | grep \* | awk -F ' ' '{print $1}'`
mount -t ntfs-3g ${mountdrive} /mnt/ > /dev/null


Essentially it grabs the output from the fdisk -l (list) command and looks for lines that have NTFS and are the boot drives. Of the computers I've worked on I've seen 3 that this doesn't mount the correct drive I want and I manually mount instead.

If you wanted to mount every partition you would have to do something like this...


#!/bin/sh

fdisk -l | awk -F ' ' '{print $1}' | grep /dev/ > /tmp/partitions
lines=`sed -n '$=' /tmp/partitions`
currentline=1
lines=`expr $lines + 1`
while [ $currentline -lt $lines ];do
readthisline=$currentline\p
devlocation=`sed -n $readthisline /tmp/partitions`
partitionname=`sed -n $readthisline /tmp/partitions | awk -F '/' '{print $3}'`
mkdir /mnt/hd/${partitionname}
mount ${devlocation} /mnt/hd/${partitionname}
currentline=`expr $currentline + 1`
done


Which assumes the mount command can figure out how to mount the partition properly would mount them like so...

/dev/sda1 >>>> /mnt/hd/sda1
/dev/sda2 >>>> /mnt/hd/sda2
/dev/sda3 >>>> /mnt/hd/sda3

/dev/sdb1 >>>> /mnt/hd/sdb1