Bash script problem to mount


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script problem to mount
# 1  
Old 11-21-2010
Question Bash script problem to mount

Code:
#!/bin/bash

    userid=$(id -u)
    options="rw,exec,users,uid="${userid}",gid="${userid}""

    while [ 1 -gt 0 ];do
        echo -n "Enter device you want to mount (Example: /dev/sda11): "
        read device
        echo "Selected device: ${device}"

        if [ -e "${device}" ];then
            echo -n "Enter mount point (Example: /media/sda11): "
            read mountpoint
            echo "Select mountpoint: "${mountpoint}""

            if [ ! -e "${mountpoint}" ];then
                echo "${mountpoint}" does not exist"
                echo "Creating mountpoint "${mountpoint}"
                mkdir "${mountpoint}"
            fi

            su -c 'mount -t vfat -o "${options}" "${device}" "${mountpoint}"'
            echo ""${device}" is mounted in "${mountpoint}""
        fi    

        echo -n "Do you want to continue?(yes/no): "
        read val

        if [ "${val}" == "no" ];then
            break
        fi
    done
    echo "Done"

Error:
Code:
mount: mount point  does not exist

Why?
# 2  
Old 11-21-2010
Try:
Code:
su -c "mount -t vfat -o ${options} ${device} ${mountpoint}"

# 3  
Old 11-22-2010
Why doesn't work?
Code:
su -c 'mount -t vfat -o ${options} ${device} ${mountpoint}'

# 4  
Old 11-22-2010
If you use single quotes, then the variables ${options}, ${device} ${mountpoint} never get evaluated...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mount NFS Share On NFS Client via bash script.

I need a help of good people with effective bash script to mount nfs shared, By the way I did the searches, since i haven't found that someone wrote a script like this in the past, I'm sure it will serve more people. The scenario as follow: An NFS Client with Daily CRON , running bash script... (4 Replies)
Discussion started by: Brian.t
4 Replies

2. Shell Programming and Scripting

Script to mount nas-share using generated credentials (mount EC 13,32)

Heyas At home i have 1 nas with 3 shares, of which i used to mount 2 of them using a script with hardcoded password and username in it. EDIT: Turns out, its not the script, but 'how i access' the nas share.. (-o user=XY,password=... VS. -o credentials=...). Figured about credential files,... (0 Replies)
Discussion started by: sea
0 Replies

3. Shell Programming and Scripting

Cygwin bash script to unmount and mount an XP partition

As stated, I am looking into keeping my backup drive unmounted in normal windows use. Partly this is to address threats like cryptolocker. Since one of my backup drives is an internal drive, it will not likely afford any protection from such a threat. I am thinking of adding code to my rsync script... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

4. Shell Programming and Scripting

Mount fails (because remote machine is off) bash script stops

Hi, I'm trying to automate a couple of mounts. (I would do this in fstab, but the auto feature causes the virtual machine I'm running in to freeze when it boots up) If the machine I'm trying to connect to is OFF, I get the host unreachable error and then the bash script stops. The problem is... (3 Replies)
Discussion started by: jdilts
3 Replies

5. Shell Programming and Scripting

Help with bash script problem

Hi, Below is my bash script: cat run_all.sh if && ; then Number_Count_Program $1.results $2.results > $1.$2.counts else Number_Split_Program $1.results $2.results > $1.$2.split fi After I run the following command: ./run_all.sh A B ./run_all.sh: line 1: Anybody advice to edit... (5 Replies)
Discussion started by: perl_beginner
5 Replies

6. Shell Programming and Scripting

bash script with "mount -t cifs" hangs

Dear all, I have a bash script that mounts a number of samba shares, but one particular mount command makes it hang. Strangely, the same command works when executed directly from the command line: sudo mount -t cifs //name-of-share /media/FTPpublic -o username=myname asks for the password... (8 Replies)
Discussion started by: slouse
8 Replies

7. Shell Programming and Scripting

Problem in bash script

I have written a script and I get error and I don't understand why. neededParameters=2 numOfParameters=0 correctNum=0 while getopts "s:l:" opt do case "$opt" in s) serviceName= $OPTARG #errorline 1 numOfParameters= $numOfParameters + 1 ;; l) ... (12 Replies)
Discussion started by: programAngel
12 Replies

8. Shell Programming and Scripting

shell script problem , sudo mount command

cat test.sh sudo mount -t vfat /dev/sda7 /media/Ddrive If i double click the test.sh file and select run in terminal then the terminal prompts for password. How can i avoid typing password? Or if i double click test.sh file and select run then nothing happens. What i'm trying "Double... (3 Replies)
Discussion started by: cola
3 Replies

9. Shell Programming and Scripting

bash script to check if mounted, and mount if not

I'd like to make a wrapper bash script that will make sure that an nfs mount is mounted before launching a program that depends on the mount being active. Basically: 1) Check to see if the mount is active 2) If it's not active, try to mount it 3) If it won't mount because the nfs server is... (3 Replies)
Discussion started by: graysky
3 Replies

10. Shell Programming and Scripting

bash script problem

hi I am writing a bash script that uses dialog to get user input an diplay messages to user. I have a small problem dialog --inputbox "blabla" 20 50 2> /tmp/output VAR="'cat /tmp/output'" mkdir $VAR the code below requests user for a directory path to be created. But, if the user uses... (1 Reply)
Discussion started by: fnoyan
1 Replies
Login or Register to Ask a Question