I've been spending more and more time lately writing and editing code on my MacBook Pro. Here are some OS X apps and tools I've found that make the job easier and more efficient.
MAMP-Great package containing Apache, PHP and MySQL into an easy to install package.
TextWrangler-A text editor with many features.
Editra-A very versatile and handy text editor.
Gvim-Gvim port for the Mac.
TextEdit-A simple, open source word processor and text editor.
Safari-An OS X web browser.
Thursday, June 30, 2011
Friday, June 10, 2011
Script
Here's a shell script I wrote to solve a problem at work. The problem was duplicate entries appearing in a file. The file contains devices identification codes and is updated manually. Manually editing a file always leads to the possibility of human error, which is a big problem. I needed a tool that would check if any duplicate entries were in fact erroneously entered. In this case, I only had to focus on the input part of the overall process. The processing and output were already working properly so I didn't have to alter them.
To begin, I analyzed the raw data. I had to remove any entries that didn't need to be checked for duplication. Then, I sorted what remained, the valid identification codes. Next, I checked that each line was unique, if not then output any duplicates into a temp file. Now, check if a temp file was created. If it was, then duplicates were found and I wanted an automated email showing me the results. If the file wasn't created, then no duplicates were found. Send me an email telling me this too. Here's my solution, bundled into a shell script and executed every 24 hours via a crontab job.
#!/bin/sh
#2011May08
#Admin
#Script name:device_duplicate_finder.sh
#Search for duplicate mac devices in
#/var/log/prod_devices.cfg.
#If found, send formatted email report to
#me@mycompany.com
#
InPutFile="/var/log/prod_devices.cfg"
OutPutFile="./device_duplicates.txt"
CurrDir="/home/admin/"
TempDevicesFile="./tmp_dups.cfg"
NoDupsFoundMsg="dups_not_found.txt"
Date=`date +%Y%b%e`
#copy prod_devices.cfg to /home/admin
cp $InPutFile $CurrDir
#Using prod_devices.cfg copy, remove all lines
#not containing valid device assignment
#combinations.
#The following steps are performed,
#Grep for all valid devices identified as containing a '%' character in their string.
#Sed delete any commented out lines.
#Sort in numerical order.
#Output duplicates to output file.
#Sed remove spaces either side of colon. Leave colon as field separator for awk.
grep % $TempRedirdFile | sed '/^#/d' | sort -g | uniq -d | sed 's/ : /:/g' > $OutPutFile
#Check output file for duplicate devices, zero
#size output file indicates no duplicates.
#if output file size > 0, then duplicates found,
#send me an email - me@mycompany.com.
if [ -s $OutPutFile ] #-s checks if file exists and size is > 0.
then
mail -s "Duplicate devices found in prod_devices.cfg file." me@mycompany.com < $OutPutFile
else
mail -s "Duplicate devices NOT found in prod_devices.cfg file." me@mycompany.com < $NoDupsFoundMsg
fi
#Clean up files, zero out input and output files.
rm $OutPutFile
rm $TempDevicesFile
To begin, I analyzed the raw data. I had to remove any entries that didn't need to be checked for duplication. Then, I sorted what remained, the valid identification codes. Next, I checked that each line was unique, if not then output any duplicates into a temp file. Now, check if a temp file was created. If it was, then duplicates were found and I wanted an automated email showing me the results. If the file wasn't created, then no duplicates were found. Send me an email telling me this too. Here's my solution, bundled into a shell script and executed every 24 hours via a crontab job.
#!/bin/sh
#2011May08
#Admin
#Script name:device_duplicate_finder.sh
#Search for duplicate mac devices in
#/var/log/prod_devices.cfg.
#If found, send formatted email report to
#me@mycompany.com
#
InPutFile="/var/log/prod_devices.cfg"
OutPutFile="./device_duplicates.txt"
CurrDir="/home/admin/"
TempDevicesFile="./tmp_dups.cfg"
NoDupsFoundMsg="dups_not_found.txt"
Date=`date +%Y%b%e`
#copy prod_devices.cfg to /home/admin
cp $InPutFile $CurrDir
#Using prod_devices.cfg copy, remove all lines
#not containing valid device assignment
#combinations.
#The following steps are performed,
#Grep for all valid devices identified as containing a '%' character in their string.
#Sed delete any commented out lines.
#Sort in numerical order.
#Output duplicates to output file.
#Sed remove spaces either side of colon. Leave colon as field separator for awk.
grep % $TempRedirdFile | sed '/^#/d' | sort -g | uniq -d | sed 's/ : /:/g' > $OutPutFile
#Check output file for duplicate devices, zero
#size output file indicates no duplicates.
#if output file size > 0, then duplicates found,
#send me an email - me@mycompany.com.
if [ -s $OutPutFile ] #-s checks if file exists and size is > 0.
then
mail -s "Duplicate devices found in prod_devices.cfg file." me@mycompany.com < $OutPutFile
else
mail -s "Duplicate devices NOT found in prod_devices.cfg file." me@mycompany.com < $NoDupsFoundMsg
fi
#Clean up files, zero out input and output files.
rm $OutPutFile
rm $TempDevicesFile
Friday, June 3, 2011
Ports
This is my cheat sheet to view Linux ports.
http://www.cyberciti.biz/faq/how-do-i-find-out-what-ports-are-listeningopen-on-my-linuxfreebsd-server/
netstat command to find open ports
# netstat --listen
To display open ports and established TCP connections, enter:
$ netstat -vatn
To display only open UDP ports try the following command:
$ netstat -vaun
If you want to see FQDN (full dns hostname), try removing the -n flag:
$ netstat -vat
To display the list of open ports, enter:
# lsof -i
To display all open files, use:
# lsof
To display all open IPv4 network files in use by the process whose PID is 9255, use:
# lsof -i 4 -a -p 9255
http://www.cyberciti.biz/faq/how-do-i-find-out-what-ports-are-listeningopen-on-my-linuxfreebsd-server/
netstat command to find open ports
# netstat --listen
To display open ports and established TCP connections, enter:
$ netstat -vatn
To display only open UDP ports try the following command:
$ netstat -vaun
If you want to see FQDN (full dns hostname), try removing the -n flag:
$ netstat -vat
To display the list of open ports, enter:
# lsof -i
To display all open files, use:
# lsof
To display all open IPv4 network files in use by the process whose PID is 9255, use:
# lsof -i 4 -a -p 9255
Wednesday, June 1, 2011
Subscribe to:
Posts (Atom)