Hello,
Merry Christmas ! And thank you for your answer
There are still some problems
Problem 1
When I use my code
Code:
mysql -ulogger -p12345 -e"use log insert into table samba (date, hour,user,host) values ('${D}','${T}','${U}','${H}');"
Update : when i use this command (with values like '2008/12/25' etc ...) in the terminal (not in mysql >) then the result is the same, there is no data added !
It works without any error but when I look in my database, there isn't any data added (in the log there are 40 lines with user information)
Problem 2
When I use your code
Code:
mysql -ulogger -p12345 log <<EOF
insert into samba (date, hour,user,host) values ('2008/12/24','134541','laechr','idefix');
EOF
Then I get an error "Unexpected EOF"
Update :
When I use the code in problem 1 and problem 2 in a new file then everything works fine ! But when I use it in the code of this file, nothing happens. No data is written to the database
Code:
#!/bin/bash
LOG_FILE=/var/log/samba/log
TEMP_FILE=/tmp/`basename ${0}`.tmp
MOD_FILE=/tmp/`basename ${0}`.mod
#VARIABELEN VOOR MYSQL SERVER
DBU=root
PWD=12345
DB=log
TBL=samba
## Get date (Format : DD/MM/YY
date=$(date +%d%b%y)
# Create filename of the logfile
LOG="${date}.log"
## 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')
Host=$(echo ${line} | awk '{print $9}')
IP=$(echo ${line} | awk '{print $10}'| sed 's/[)(]//g')
SHARE=$(echo ${line} | awk '{print $14}')
User=$(echo ${line} | awk '{print $18}')
# Print the standard output line
echo "${Date}:${Time}:${User}:${Host}:${IP}"
mysql -u$DBU -p$PWD -e" use log insert into $TBL(id,datum,uur,user,host) values (NULL,'${Date}','${Time}','${User}','${Host}');"
done < ${TEMP_FILE}
rm ${MOD_FILE}
rm ${TEMP_FILE}
What do i wrong or is it impossible to do this (or am I stupid ?!

)
Best regards,
Christof Laeremans