Skip to content

Instantly share code, notes, and snippets.

@fukata
Created May 15, 2011 14:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fukata/973205 to your computer and use it in GitHub Desktop.
Save fukata/973205 to your computer and use it in GitHub Desktop.
Attendance memo tool.
#!/bin/bash
###########################################################
#
# Clone repo:
# git clone git://gist.github.com/973205.git attendance
#
# Create Database:
# mysqladmin -u root atnd
# mysql -u root atnd < attendance/ddl.sql
#
# Edit your .bashrc
# export ATND_TOOL=/home/fukata/usr/local/attendance
# export PATH=$PATH:$ATND_TOOL
#
# Reload .bashrc:
# source ~/.bashrc
#
# Usage:
# atnd msg
#
###########################################################
# Database
DB_HOST="localhost"
DB_PORT=3306
DB_USER="root"
DB_PASS=""
DB_NAME="atnd"
if [ "$DB_PASS" = "" ]; then
CMD_CONNECT="mysql -u $DB_USER -h $DB_HOST -P $DB_PORT $DB_NAME"
else
CMD_CONNECT="mysql -u $DB_USER -p $DB_PASS -h $DB_HOST -P $DB_PORT $DB_NAME"
fi
function exec_sql() {
sql=${1?"SQL is required."}
echo "$sql" | $CMD_CONNECT
}
function create_atnd() {
msg=${1?"Message is required."}
sql="INSERT INTO logs (msg, created_at) VALUES (QUOTE('$msg'), CURRENT_TIMESTAMP);"
exec_sql "$sql"
}
create_atnd $1
BEGIN;
CREATE TABLE IF NOT EXISTS logs (
id INT NOT NULL AUTO_INCREMENT,
msg TEXT NOT NULL,
created_at DATETIME NOT NULL,
PRIMARY KEY(id)
);
COMMIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment