Tuesday, December 11, 2012

Mounting a Windows Drive Remotely in a Linux Machine


1. Create a local user in the Windows machine (IP=10.253.99.19)
      Ex. Account name = user123 and password = abc123%

2. Set the drive E:\ shareable to user123 with READ / WRITE privileges on Windows machine (IP=10.253.99.19)

3. Make a mounting point directory on the Linux machine (IP=10.253.99.20)
    Ex. $ mkdir -p /usr/local/pub/mnt/svr19

4.  Make a bash script named remountServers.sh  on the Linux machine (IP=10.253.99.20)
  

#/bin/bash

#Unmount
sudo umount /usr/local/pub/mnt/svr19

#Mount
sudo mount -t cifs //10.253.99.19/e -o username=user123,password=abc123% /usr/local/pub/mnt/svr19

5. Make the script executable
    Ex. $ chmod a+x remountServers.sh 

6. Execute the script
   Ex. $ ./remountServers.sh 

Thursday, November 15, 2012

Removing ^M characters in bash scripts for Mac OS X

When your bash script you copied from unix/linux to your windows machine and then copied it to Mac doesn't work, and you see an error like this:

bash: ./unixScript.sh: /bin/sh^M: bad interpreter: No such file or directory

probably because your source code contains annoying Control+M (^M) characters when saved in a Windows machine. There are two (2) ways to remove this.

1. Create a bash script dos2unix.sh in Mac terminal 
1.1 Using vi, create the file below
   #!/bin/bash
   file=S1
   cat $1 | col -b > temp
   mv temp $1
   chmod a+x $1


1.2 Make the script executable 
      $ chmod a+x dos2unix.sh
1.3 Execute the script
     $ ./dos2unix.sh myshellscript.sh


2. Rremove the ^M in Mac using tr. 
   2.1. First view the file using
         $ cat -e unixScript.sh 
         $ od -tc unixScript.sh
  2.2. Remove using the command below
         $ tr -d '\r' < unixScript.sh > macScript.sh