Samba Tutorial (Part II)

Posted: April 8, 2009 in Open Source, Open Source Tutorial
Tags: , , ,

What we will do ?

Create a file server using Samba, which is able to record each user whhen  connected or disconnected in a log file.

sample log file below :

time          user   source      ip
2009 01 00:23 umum freeshare

This samba server can sharing printer too :D

Let’s begin…

samba installation:
# apt-get install samba

smbfs installation (in every client) :
# apt-get install smbfs

how to mounting (in client):
mount none –t smbfs //<server>/<sharename> /<mountpoint>

add user:
# adduser <nama user>

samba password  setting (username must exist in the computer):
# smbpasswd –a <nama user>


smb.conf configuration :

###samba configuration###

### /etc/samba/smb.conf ###

workgroup = WORKGROUP
netbios name = SAMBA
encrypt passwords = yes
socket options = TCP_NODELAY
printcap name = cups
printing = cups
security = user
log level = 1
log file = /var/log/samba.log
max log size = 200
debug timestamp = yes

browseable = yes
printable = yes
public = yes
create mode = 0700
guest only = yes
use client driver = yes
path = /tmp

read only = no
browseable = no

comment = share2an-nya kelompok 62
path = /home/reza/62share
public = yes
browsable = yes
writable = yes
valid users = reza, acung
write list = reza

###untuk menerima file pdf###
path = /shr
browsable = yes
writable = yes
guest ok = yes
force user = nobody

###setting untuk share printer###
path = /tmp
printable = yes
guest ok = yes
print command = /usr/bin/printpdf %s
lpq command =
lprm command =

file /var/log/samba.log (with log level = 1)

automatically generated by samba

[2009/04/07 05:54:19, 1] smbd/service.c:make_connection_snum(950) ( connect to service 62share initially as user reza (uid=1000, gid=1000) (pid 1275)

this file executed when someone accessed samba server

TEMP_FILE=/tmp/`basename ${0}`.tmp
MOD_FILE=/tmp/`basename ${0}`.mod

## Get each log entries on to a single line
while read line; do
if [ $(echo ${line} | grep -c “^\[” ) -gt 0 ]; then
printf “\n${line}\c” >> ${MOD_FILE}
printf ” ${line}” >> ${MOD_FILE}
done < ${LOG_FILE}
echo ” ” >> ${MOD_FILE}

## Save the login log entries to the $TEMP_FILE
grep “connect to service” ${MOD_FILE} > ${TEMP_FILE}

## Save the values into variables
while read line; do
DATE=$(echo ${line} | awk ‘{print $1}’|sed ‘s/\[//g’)
TIME=$(echo ${line} | awk ‘{print $2}’|sed ‘s/[,]//g’)
HOSTNAME=$(echo ${line} | awk ‘{print $9}’)
IP=$(echo ${line} | awk ‘{print $5}’| sed ‘s/[)(]//g’)
SHARE=$(echo ${line} | awk ‘{print $10}’)
USER=$(echo ${line} | awk ‘{print $14}’)
## Print the standard output line
echo -e “${DATE}\t${TIME}\t${USER}\t${SHARE}\t\t${IP}”

done < ${TEMP_FILE}

rm ${MOD_FILE}

printer setting (in this example, we printing pdf file)
ghostscript installation in samba server :

# apt-get install gs-alladdin
# apt-get install gs
this script for printing pdf file
we save it in /usr/bin/


# Simple script to convert a specified postscript file into a PDF document
# and place it in a location that is shared by the Samba server.
# Arguments:
# 1st – The name of the spool file
# John Bright, 2001,

# We will create the pdf into a temporary file based upon the current date and time.
# After we are finished, we’ll rename it to a file with the same date, but ending
# in .pdf. We do this because if a user tries to open a PDF that is still being written,
# they will get a message that it is corrupt, when it is actually just not done yet.

DATE=`date +%b%d-%H%M%S`

# Directory in which to place the output
# Be sure this directory exists and is writable by the user that Samba
# is running as (for example, the nobody user)

ps2pdf $1 $OUTDIR/$DATE.temp
rm $1

restart samba daemon :
/etc/init.d/samba restart
/etc/init.d/samba start


Samba Tutorial


  1. […] Samba Tutorial (Part II) […]

  2. ingalex says:

    This tutorial is very useful, i’ve alway problem when i’ve to configure samba.

  3. wah iku script samba sakjane ada special thx ne =))

    btw.. yg printer uda bisa ta itu?

    mangtabs gan

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s