Samba Tutorial (Part II)
![]()
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 10.126.11.2
This samba server can sharing printer too
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>
/etc/samba/smb.conf
smb.conf configuration :
###samba configuration###
### /etc/samba/smb.conf ###
[global]
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
[printers]
browseable = yes
printable = yes
public = yes
create mode = 0700
guest only = yes
use client driver = yes
path = /tmp
[homes]
read only = no
browseable = no
[62share]
comment = share2an-nya kelompok 62
path = /home/reza/62share
public = yes
browsable = yes
writable = yes
valid users = reza, acung
write list = reza
[shr]
###untuk menerima file pdf###
path = /shr
browsable = yes
writable = yes
guest ok = yes
force user = nobody
[pdf]
###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)
192.168.62.2 (192.168.62.2) connect to service 62share initially as user reza (uid=1000, gid=1000) (pid 1275)
samba-log.sh
this file executed when someone accessed samba server
LOG_FILE=/var/log/samba.log
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}
else
printf ” ${line}” >> ${MOD_FILE}
fi
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}
rm ${TEMP_FILE}
printer setting (in this example, we printing pdf file)
ghostscript installation in samba server :
# apt-get install gs-alladdin
or
# apt-get install gs
printpdf.sh
this script for printing pdf file
we save it in /usr/bin/
#!/bin/sh
# 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, jbright@winfordeng.com
# 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)
OUTDIR=/shr/pdfdropbox
ps2pdf $1 $OUTDIR/$DATE.temp
mv $OUTDIR/$DATE.temp $OUTDIR/$DATE.pdf
rm $1
restart samba daemon :
/etc/init.d/samba restart
atau
/etc/init.d/samba start
============================================
============================================







This tutorial is very useful, i’ve alway problem when i’ve to configure samba.
thanks !
wah iku script samba sakjane ada special thx ne =))
btw.. yg printer uda bisa ta itu?
mangtabs gan
oke..special thanks to alex
buat ngetes printer butuh printernya…klo bisa yang merk HP
berhubung gak ada ya gak di tes