Wednesday, April 25, 2012

Sample Linux Shell script > grepping info from MySQL DB

Hi Folks,

Today I finished creating customization script to one of the customer. The objective to create this customization script is to deliver the report immediately to customer since they do not have this kind of delivery report in current system. Take a look and let me know if you have any questions.

#!/bin/sh
export dir=/var/lib/mysql/MT-Support
export script=/var/lib/mysql/MT-Support/scripts
export log=/var/lib/mysql/MT-Support/log
export in=/var/lib/mysql/MT-Support/in
export out=/var/lib/mysql/MT-Support/out

DateTime=`date +%Y-%m-%d-%H-%M-%S`
Date=`date +%Y-%m-%d`

echo "--------------------------------------------" >> $log/ChkDataEnabled-$DateTime.log
echo "START TIME: $DateTime" >> $log/ChkDataEnabled-$DateTime.log
counter=1

### while loop to read the source file from GLO.
while read rline
do

###check1 the current terminal used by subscribers.
mysql -udba -pwApNoMore -hdba-srv-01 -e "use tac; select subscriber.detection.msisdn, subscriber.detection.imsi, subscriber.detection.imei, if(subscriber.detection.last_configured is NULL, 'YES', 'NO') AS last_configured, tac.tac_terminal_mapper.make_name, tac.tac_terminal_mapper.terminal_name from tac.tac_terminal_mapper, subscriber.detection where subscriber.detection.msisdn='234$rline' and substring(subscriber.detection.imei,1,8) in (tac.tac_terminal_mapper.tac) order by subscriber.detection.last_detected desc limit 1 into outfile '$out/234$rline-subs-detection.csv' fields terminated by ',';"

###check2 if MSISDN detected by ADD or not and whether there no configuration sent to subs due to settings not released yet...
rowCount=`cat $out/234$rline-subs-detection.csv | wc -l`
 if [ "$rowCount" -eq 0 ]; then
  echo "No record found in detection table for MSISDN: 234$rline !" >> $log/ChkDataEnabled-$DateTime.log
  rm $out/234$rline-subs-detection.csv

 elif [ "$rowCount" -eq 1 ]; then
  chkNULL=`cat $out/234$rline-subs-detection.csv | awk -F "," '{print $4}'`

  getMSISDN=`cat $out/234$rline-subs-detection.csv | awk -F "," '{print $1}'`
  getIMSI=`cat $out/234$rline-subs-detection.csv | awk -F "," '{print $2}'`
  getIMEI=`cat $out/234$rline-subs-detection.csv | awk -F "," '{print $3}'`
  getMAKE=`cat $out/234$rline-subs-detection.csv | awk -F "," '{print $5}'`
  getTERMINAL=`cat $out/234$rline-subs-detection.csv | awk -F "," '{print $6}'`

  if [ "$chkNULL" = "YES" ]; then
   echo "Phone not configured due to settings not released yet for MSISDN: $getMSISDN, IMSI: $getIMSI, IMEI: $getIMEI, MAKE: $getMAKE, MODEL: $getTERMINAL  !" >> $log/ChkDataEnabled-$DateTime.log

  else  
   ###check3 in otapmanager DB, om_history table to get the setting name that had sent before...
   mysql -udba -pwApNoMore -hdba-srv-01 -e "use otapmanager; select vendor, model, settingname, updatedate, channel from om_history where da='$getMSISDN' and imei='$getIMEI' and settingname != 'sms' order by createdate desc limit 1 into outfile '$out/234$rline-subs-history.csv' fields terminated by ',';"
  
   rowCount2=`cat $out/234$rline-subs-history.csv | wc -l`

   if [ "$rowCount2" -eq 0 ]; then
    echo "No record found in history table for MSISDN: 234$rline !" >> $log/ChkDataEnabled-$DateTime.log

   elif [ "$rowCount2" -eq 1 ]; then
    echo "Record greped from om_history table for MSISDN: 234$rline !" >> $log/ChkDataEnabled-$DateTime.log
   
    getOM_history=`cat $out/234$rline-subs-history.csv`
    echo "$getMSISDN, $getIMSI, $getIMEI, $getOM_history" >> $out/$DateTime-subs-data-enabled.csv
   fi

   rm $out/234$rline-subs-history.csv
  fi
   rm $out/234$rline-subs-detection.csv
        fi
echo "Successfull check row number: $counter" >> $log/ChkDataEnabled-$DateTime.log

counter=`expr $counter + 1`
done < $in/gbamactiv.txt


#gzip $out/$Date-subs-data-enabled.csv
DateTime2=`date +%Y-%m-%d-%H-%M-%S`
echo "END TIME: $DateTime2" >> $log/ChkDataEnabled-$DateTime.log
echo "" >> $log/ChkDataEnabled-$DateTime.log

Tuesday, April 24, 2012

Device Management System - DMS


Device Management System - DMS
DMS is a product that will give mobile operators a powerful solution for automatic configuration of mobile devices for internet, mms, email and other value added services via Over-The-Air (OTA) settings, step-by-step guides and many more.
Over the Air - OTA
Over the Air (OTA) capabilities are considered a main component of mobile network operator and enterprise-grade Device Management System software. These include the ability to remotely configure a single mobile device, an entire fleet of mobile devices or any IT-defined set of mobile devices; send software and OS updates; remotely lock and wipe a device, which protects the data stored on the device when it is lost or stolen; and remote troubleshooting. OTA commands are sent as a binary SMS message.
Device Management System software enables corporate IT departments to manage the many mobile devices used across the enterprise; subsequently, over-the-air capabilities are in high demand. Enterprises using OTA SMS as part of their DMS infrastructure demand high quality in the sending of OTA messages, what imposes on SMS gateway providers to offer a high level of quality and reliability.

Linux Shell String Comparison

Hi Folks,


If you remember when you work on creating own Linux/Unix shell script, you would always be involved in if-else, case comparison. Thus, this article to share the string comparison you can use while using if-else or other comparison method. Hope this helps!


String Comparisons

= equal
!= not equal
< less then
> greater then
-n s1 string s1 is not empty
-z s1 string s1 is empty


Bash File Testing

-b filename Block special file
-c filename Special character file
-d directoryname Check for directory existence
-e filename Check for file existence
-f filename Check for regular file existence not a directory
-G filename Check if file exists and is owned by effective group ID.
-g filename true if file exists and is set-group-id.
-k filename Sticky bit
-L filename Symbolic link
-O filename True if file exists and is owned by the effective user id.
-r filename Check if file is a readable
-S filename Check if file is socket
-s filename Check if file is nonzero size
-u filename Check if file set-ser-id bit is set
-w filename Check if file is writable
-x filename Check if file is executable

Thursday, April 19, 2012

How to find huge filesize in Linux?

Following are few options how it can be done:


1) du -sh *

2) find / -type f -size +100000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'

3) ls -lt tms-apc.sdr2011* | awk '{tot += $5} END {tot=((tot/1024)/1024)/1024 ; printf(" TOTAL SIZE (GB): %4.2f\n",tot)}'

Fastest way, use the following:

du -shx  /var/log/* | grep G

Thursday, April 12, 2012

back after a year!

Hi there,

I am back after a year. Will continue post new learning material about telco. wait!!!