Bash
- Details
- Category: Bash
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.
- Details
- Category: Bash
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