SysAdmin Blog, TechTips and Reviews

An (ex) System Administrator's Blog



Archives Posts

mysql: Multiple Table Query, Output into File

February 23rd, 2008 by elizar

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’

Filed under Linux, mysql, Tips having 1 Comment »

Archives Posts

Store a file output in a variable

February 9th, 2008 by elizar

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’

I was here...