Find the answer to your Linux question:
Results 1 to 6 of 6
I need to write a bash script that checks one mounted device and mounts the other in the same hardware e.g., if I mount /dev/sda1 to /media/drive1 then the script ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    89

    Complex Bash Script

    I need to write a bash script that checks one mounted device and mounts the other in the same hardware
    e.g.,
    if I mount
    /dev/sda1 to /media/drive1
    then
    the script automatically checks and mounts
    /dev/sda2 to /media drive2

    well it may the assumed that the drive is a pendrive and the partition may change from /dev/sda1 to /dev/sdb1 or other possible.

  2. #2
    Linux Guru
    Join Date
    May 2011
    Posts
    1,842
    This may not be as complex as you think, but a little more detail would be good:

    Are you saying that after you've mounted a pendrive (say /dev/sda1) that you'd like to run a script that would interrogate the system for the presence of any other attached pendrives, and then attempt to mount those, too?

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    89
    Well I sometimes run Kubuntu 9.04 Live for data backup purposes during which in very rare cases I need to surf the Internet. So I have downloaded a few applications like mozilla etc and have written a script to extract the source, compile it and install it when running live. I also have the deb files of evince, file-roller etc which I need to install. The USB Stick is partitioned into 3 parts one containing files I can plug and play anywhere (this is where the script is), the second partition contains these deb files from where I need to install them and the third partition is entirely dedicated to the OS to boot up live from the USB Stick.

    Now sometimes when my friends bring along their USB Stick or External Hard-Drives I need to plug them in. And on boot up it changes partitions due to which i have the change the letter in the script. I want the script to automatically check for the first mounted position named "drive1" and automatically select the drive letter for "drive2".

    Is this possible? If yes how?

  4. #4
    Linux Guru
    Join Date
    May 2011
    Posts
    1,842
    I'm still not clear exactly what you're asking for. Let me try to summarize:

    So you have Kubuntu booting from a usb disk? Can you show your drive layout, e.g.:
    /dev/sda1 = OS partition
    /dev/sda2 = script partition
    /dev/sda3 = deb files partition

    When this usb-based system is booted up and you plug in some addition usb drive (stick, hard drive, etc.), the underlying block device name for it changes from what it was last time (e.g, was /dev/sdb1, now is /dev/sdc1, etc.)?

    Or are you saying you have both usb drives plugged in at boot time, and the devices names get swapped? This would mean it wouldn't boot though, so that can't be it...

    Something else?

    Can you also post the portion of script referring to what you want to do?

  5. #5
    Just Joined!
    Join Date
    Mar 2009
    Posts
    89
    /dev/sda1 = script partition
    /dev/sda2 = Deb Files partition
    /dev/sda3 = OS partition

    when I boot from the USB Stick with another device imagine a 500GB HDD plugged in when the computer was powered down, the HDD becomes /dev/sda and the USB Stick becomes /dev/sdb

    When just the USB stick is connected:
    sudo mkdir /media/drive2
    sudo mount /dev/sda2 /media/drive2

    When the HDD or any other drive is connected along with the USB Stick


    sudo mkdir /media/drive2
    sudo mount /dev/sdb2 /media/drive2

    I want this a to change to b as it detects /media/drive1 or the script drive is at /dev/sdx1
    where x refers to a or b or any other character

  6. #6
    Just Joined!
    Join Date
    Mar 2009
    Posts
    89
    [Problem Solved]
    Successfully done by using the UUID to mount "mount -U <UUID> <mount point>"
    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...