Skip to content

Instantly share code, notes, and snippets.

@disciplezero
Last active August 29, 2015 14:19
Show Gist options
  • Save disciplezero/d869319693940e35950b to your computer and use it in GitHub Desktop.
Save disciplezero/d869319693940e35950b to your computer and use it in GitHub Desktop.
getMaxKey
#!/bin/bash
HOST=$1
USER=$2
PASS=$3
TABLE=$4
KEY=$5
# head/tail to get the second line. The first column is the field, so we delete everything afterwards.
mysql -h $HOST -u $USER --password=$PASS sw -e 'select '"$KEY"' from '"$TABLE"' order by '"$KEY"' desc limit 1'| head -2 |tail -1|sed "s/\t.*//g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment