Archive: February, 2008

mysql: Multiple Table Query, Output into File

Check out this article about mysql: Multiple Table Query, Output into File. Please tell me what you think about it. You can contact me anytime!

Got a request from the boss today to extract all users plus their contact numbers from the Paging server

Server is a Red Hat Enterprise Linux AS release 4, running LAMP.

The data needed are located in several tables, so we need to query all relevant tables in the databse:

mysql> SELECT users.username, users.emailaddress, user_services.current_service FROM users, user_services WHERE users.username=user_services.username

The statement above queries two tables – users and user_services, as show from the expressin ‘FROM users, user_services’. The record in users table that information is required are in the username and emailaddress record. On user_services, it’s current_services. The WHERE sets the limit condition.

To send that output to a file, we use the INTO OUTFILE ‘</path/to/file>’.

So, that’s

mysql> SELECT users.username, users.emailaddress, user_services.current_service FROM users, user_services WHERE users.username=user_services.username INTO OUTFILE ‘/tmp/tempfile.txt’

Store a file output in a variable

Check out this article about Store a file output in a variable. Please tell me what you think about it. You can contact me anytime!

draft……. note to self

#!/bin/bash -x
FILE=”/tmp/IAP_sched”
DIR=”/PRA/prod/files/nz/area11/logs/”
FILE2=$(awk ‘{ print $1 }’ $FILE)
echo “*** Nameserver IP ***”
for ip in $FILE2
do
echo “Doing GTL on” $ip
/PRA/prod/scripts/arc/get_log_times *$ip* >> /tmp/output.txt
done

*alias command is not recognize.. hence the full path of ‘glt’