Last active
August 29, 2015 14:18
-
-
Save wethu/a06e2b21fc7e702c82eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # Fetch all the daily lists of ID that are unfulfilled | |
| # Usage: RAILS_ENV=production ID=28774 ./daily_list | |
| # Exports to: APP_DIR/script/csv_tmp/daily_list-TIMESTAMP.csv | |
| # Author: Ellis Gray 2015 | |
| RAILS_ENV=${RAILS_ENV:-development} | |
| DATE=$(date +"%Y%m%d%H%M") | |
| DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | |
| get_daily_list() { | |
| echo "Dumping data from: $RAILS_ENV database." | |
| mysql -uroot <<EOF | |
| SELECT 'order', 'request', 'sku_id' | |
| UNION ALL | |
| SELECT | |
| li.item_collection_id as order_number, | |
| CONCAT(li.qty, ' x ', li.name) as request, | |
| li.sku_id | |
| INTO OUTFILE '$DIR/csv_tmp/daily_list-$DATE.csv' | |
| FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' | |
| LINES TERMINATED BY '\n' | |
| FROM | |
| g2_$RAILS_ENV.production_requests as pr | |
| INNER JOIN g2_$RAILS_ENV.line_items as li on li.id = pr.line_item_id | |
| WHERE | |
| (pr.production_list_id = $ID) | |
| AND (pr.fulfilled_at IS NULL) | |
| AND ((pr.type = 'DailyListRequest')); | |
| EOF | |
| } | |
| if [ -v ID ]; then | |
| get_daily_list; | |
| echo "Successfully exported to csv_tmp/daily_list-$DATE.csv"; | |
| else | |
| echo "You must set ID= to the unfulfilled id"; | |
| fi | |
| # getting : ./daily_list.sh: line 33: [: -v: unary operator expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment