-
-
Save fukata/973205 to your computer and use it in GitHub Desktop.
Attendance memo tool.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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