sh - bash script pulling variables from .txt, keeps giving syntax error while trying to use mount command -


ive been trying work last week , cannot figure out why not working. mixed results typing directly terminal, keep getting syntax error messages when running .sh. using ubuntu 11.10

it looks part of mount command gets pushed next line not allowing complete properly.. have no idea why happening or how prevent going second line.

i have several lines defined follows in mounts.txt, gets read mount-drives.sh below

i have called run using sudo shouldnt permissions issue.

thanks taking look, let me know if additional info needed.

mounts.txt

    mountname,//server/share$,username,password, 

mount-drives.sh ---origional, updated below

    #!/bin/bash     while read line;           # split lines using , separate variables     name=$(echo $line | cut -d ',' -f 1)     path=$(echo $line | cut -d ',' -f 2)     user=$(echo $line | cut -d ',' -f 3)     pass=$(echo $line | cut -d ',' -f 4)      echo $name     echo $path     echo $user     echo $pass       location="/mnt/test/$name/"      if [ ! -d $location ]             mkdir $location     fi      otherstuff="-o rw,uid=1000,gid=1000,file_mode=0777,dir_mode=0777,username=$user,password=$pass"      mount -t cifs $otherstuff $path $location      done < "/path/to/mounts.txt"; 

mount-drives.sh ---updated

    #!/bin/bash      while read line             name=$(echo $line | cut -d ',' -f 1)         path=$(echo $line | cut -d ',' -f 2)         user=$(echo $line | cut -d ',' -f 3)         pass=$(echo $line | cut -d ',' -f 4)         empty=$(echo $line | cut -d ',' -f 5)         location="/mount/test/$name/"         if [ ! -d $location ]                     mkdir $location         fi         mounting="mount -t cifs $path $location -o username=$user,password=$pass,rw,uid=1000,gid=1000,file_mode=0777,dir_mode=0777"         $mounting         echo $mounting >> test.txt      done < "/var/www/mediacenter/mounts.txt" 

stab in dark (after reading comments). "$pass" picking newline because mounts.txt created in windows , has windows line endings. try changing echo $pass line to:

echo ---${pass}--- 

and see if shows correctly.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -