Grant McWilliams
  • Food
    • Blog
    • Websites
    • Seattle Food Events
    • Seattle Farmers Markets
  • Travel
    • Travel Blog
    • Travel Photos
    • Travel Links
    • Trip Journals
      • Europe - 2015
      • New Orleans - 2013
      • Central Mexico - 2010
      • Toulouse/Paris - 2009
      • Paris/Lyon - 2008
      • Peru/Ecuador - 2007
      • British Columbia - 2007
      • Central Mexico - 2006
      • Eastern Europe - 2006
      • Washington D.C. - 2006
      • Where's the rest?
  • Technology
    • Gadgets
      • Blog
      • Websites
      • Android
      • Nokia n900
      • SailfishOS
    • Technology
      • Blog
      • Websites
    • Virtualization
      • Virtualization Blog
      • Websites
      • Xen Howtos
      • Xenserver Howtos
      • KVM Howtos
      • VirtualBox Howtos
      • Virtual OS images
      • Xenapi Admin Tools github
    • Programming
      • Blog
      • Bash
      • Python
      • Websites
      • Downloads
    • Transportation
      • Blog
      • Websites
    • Sustainable Tech
      • Blog
      • Websites
  • Photography
    • Blog
    • Portfolio
  • Random
    • Grantianity
      • Basics
      • Grantisms
      • The River of Life
      • Bus Maintainance
      • Believing in Yourself
    • Creative Writing
    • Login/Logout
    • About

Bash

Where's My Bus? Finding your bus with BASH.

Details
Category: Bash
June 6, 2011

While demonstrating that you can use BASH for more than system administration I put together this script that accesses OneBusAway's ReST API to show what buses are coming to your stop next, their scheduled arrival time and their real arrival time (for King County Metro). You can download it from the Downloads section if you wish -

This script was made on Ubuntu Linux using BASH 3.2 and requires wget and xml2. Wget is usually installed on Linux but I had to install xml2 so I have the script checking for that.  wheresmybus3.sh (1 kB)

Syntax: wheresmybus.sh stop_id

Example: wheresmybus.sh 1_400

Route Number: 358E

Destination: DOWNTOWN SEATTLE VIA AURORA AVE N

Actual Arrival Time: 0 Minutes
Scheduled Arrival Time: -8 Minutes

 



Route Number: 2

Destination: MADRONA PARK VIA E UNION ST

Actual Arrival Time: 0 Minutes

Scheduled Arrival Time: 4 Minutes

 

If you don't know what the agency number is (and who does?) just leave it out and wheresmybus.sh will give you a list. The example above would show the arrival times for King County Metro's stop number 400. Output will look like this.

Commandline Calender

Details
Category: Bash
May 25, 2007

An interesting commandline calender. If you don't supply an argument it will show you the output of cal (current month) but if you supply it a number 12 and lower it will show you that month in this year but if the number is 13 or above it will show you a calender of the year specified.



#!/bin/bash
# Syntax acal

function acal {
m=""
case $# in
0) cal; return;;                #no arguments
1) m=$1; y=`date +%Y`;;         #1 argument
2) m=$1; y=$2;;                 #2 arguments
esac

case $m in
Jan*|jan*      ) m=1;;
Feb*|feb*      ) m=2;;
Mar*|mar*      ) m=3;;
Apr*|apr*      ) m=4;;
May|may        ) m=5;;
Jun*|jun*      ) m=6;;
Jul*|jul*      ) m=7;;
Aug*|aug*      ) m=8;;
Sep*|sep*      ) m=9;;
Oct*|oct*      ) m=10;;
Nov*|nov*      ) m=11;;
Dec*|dec*      ) m=12;;
[1-9]|1[0-2] ) ;;         #numeric month
*     ) y=$m; m="";;
esac
cal $m $y
}

acal $1

Scripting

Details
Category: Bash
May 25, 2007

Read more …

Search