Scripting (lagi)

Kemaren lagi iseng pengen tau nilai kurs USD-IDR, karena dari tiap website beda2, akhirnya bikin script BASH untuk ngambil info kurs dari beberapa website. Bekelnya cuma WGET, CAT, GREP, CUT. Ini source-code nya:

#!/bin/bash

# Info Kurs Ekstraktor
# Agustus 2013 oleh sedjat1
# Lisensi : GNU GPL v.3.0

merah="\e[31m"
hijau="\e[32m"
kuning="\e[33m"
biru="\e[34m"
magenta="\e[35m"
cyan="\e[36m"
normal="\e[39m"

mtu="$cyan"
svc="$kuning"

echo -e "Info kurs ${mtu}USD${normal}"

echo -n -e "${svc}Bank Mandiri   ${normal}= "
wget -q -Osrc.txt "http://www.bankmandiri.co.id/resource/kurs.asp"
readarray kurs < <(cat src.txt | grep 'USD</option>' | cut -d"\"" -f2)
te="Beli "
for item in "${kurs[@]}"
do
	usd=`echo "${item/$'\n'/}" | cut -d. -f1`
	echo -n -e "${te}${usd}"
	te=" ; Jual ${merah}"
done
echo -n -e "${normal} ; "
cat src.txt | grep 'Last Updated:' | cut -d"<" -f2 | cut -d">" -f2
rm src.txt

echo -n -e "${svc}Yahoo! Finance ${normal}= "
wget -q -Osrc.txt "http://download.finance.yahoo.com/d/quotes.csv?s=USDIDR=X&f=sl1d1t1c1ohgv&e=.csv"
usd=`cat src.txt | cut -d, -f2 | cut -d. -f1`
tgl=`cat src.txt | cut -d"\"" -f4`
jam=`cat src.txt | cut -d"\"" -f6`
echo -e "${merah}${usd} ${normal}@ $tgl $jam"
rm src.txt

echo -n -e "${svc}Google Finance ${normal}= "
wget -q --no-check-certificate -Osrc.txt "https://www.google.com/finance?q=USDIDR"
usd=`cat src.txt | grep '1 USD =' | cut -d. -f1 | cut -d">" -f2`
jam=`cat src.txt | grep 'class=time' | cut -d">" -f2 | cut -d"<" -f1`
echo -e "${merah}${usd} ${normal}@ $jam"
rm src.txt

Hasilnya begini:
kurs.sh

144total visits,2visits today

Leave a Reply

sedjat1