Thursday, June 23, 2011

String Replace with Command Line

Computer > Programming > Batch Files

Many times while programming Windows batch scripts for maintenance jobs, I had the need for replacing or deleting a string from a text file.

This is not a straight-forward action in batch file, so I decided to write my own command-line executable to help me.


You can download it from the following link:

StrReplace.exe

Usage:
StrReplace input_file original_string [replacement_string]

input_file: The file to read text from

original_string: The string to search in each line for replacement

replacement_string:  The string to be inserted at places of the original_string
                     if omitted then original_string will be deleted


Wednesday, June 1, 2011

Quick and Simple: Sharing folders with Samba server on Linux

Relates: Computers > Linux

The following article is going to describe how you share folders and files of your linux system to a network of Windows clients. The configuration is simple. You have one or more folders hosted on a Linux PC and you want to share them to your network so you can store and read files from them. No security settings are assumed. Everyone (without authentication) is able to read, write etc. It is recommended to have such an environment on a Local area network like home or home-office.

The configuration example is based on CentOS 5.5 Linux, but it should work on most linux distributions as is. Also all configuration have been done as root.

1. If you don't have already installed you can download the Samba server packages directly from CentOS repositories

# yum install samba

2. Suppose that you have or create a directory that you wish to share. e.g. /myfolder. You must give full access to the directory on Linux OS level first.

# chmod 777 /myfolder

3. Then you have to edit the configuration file in order to apply sharing. The file can be found at /etc/samba/smb.conf. 

I would suggest though that you make a copy of the original and start a new one.

# mv /etc/samba/smb.conf /etc/samba/smb.conf.backup

4. Then it's time create a new file with your configuration in it.
# vi /etc/samba/smb.conf

Inside the file you can put the following content:

[global]
  workgroup = MYWORKGROUP
  security = share

[myfoder]
  comment = My first shared folder
  path = /myfolder
  read only = no
  writable = yes
  guest ok = yes


5. Save and you are ready. You should now start the samba service and test if you can access your folder


# service smb start


or restart the service (if already running)


# service smb restart


That's it. You are done.


If you want to add another directory for sharing, you just have to edit the smb.conf file and another [] section (the [global] section should remain the same).


For example, if you want also to share /var/mydocs as [mydocs] then you will have to add


[mydocs]
  comment = My documents
  path = /var/mydocs
  read only = no
  writable = yes
  guest ok = yes


Remeber that you have to chmod 777 this directory also if everyone is to access it.


Of course the above is just a basic and simple configuration. If you want to go to more advanced configurations (like having different access rights for different users, etc) then it's better to search the Internet for other more advanced Samba tutorials and documentation.








 



Test

Test! Test!

Hello world!

Starting a blog