Someone had written a dos batch file for a menu as seen here:

@echo off
color 0e
Title Website Starter (by Prof. Pickle)
:Menu
cls
echo ---------------------------------------------------------------------
echo This is the Website starter
echo.
echo Select the number of the website you wish to select
echo Or press E to exit.
echo ---------------------------------------------------------------------
echo.
echo.
echo 1. facebook
echo 2. youtube
echo 3. google
echo 4. redtube
echo 5. other
set /p web=
If %web% EQU 1 start www.facebook.com
If %web% EQU 1 goto Menu
If %web% EQU 2 start www.youtube.com
If %web% EQU 2 goto Menu
If %web% EQU 3 start www.google.com
If %web% EQU 3 goto Menu
If %web% EQU 4 start www.redtube.com
If %web% EQU 4 goto Menu
If %web% EQU 5 goto other
If %ERRORLEVEL% NEQ 0 goto ERROR
If %web% EQU E goto exit
If %web% EQU e goto exit
goto please
:other
cls
echo You have chosen other
echo.
echo Type the web address of the website (www.website.com)
set /p otherweb=
start %otherweb%
If %ERRORLEVEL% NEQ 0 goto ERROR
:exit
cls
echo Goodbye!
pause > nul
exit
:ERROR
cls
echo Sorry, an error has occurred.
echo.
echo If you were using the "other website" function you may have
echo typed it incorrectly.
echo.
echo Press any key to go back to menu
pause > nul
goto Menu
:please
cls
echo Please press a number from 1-5
echo.
pause
goto Menu

Sure the author worked really hard on it. then I thought how would I do a quick equivalent using bash. To be fair his batch code could of been improved with a while loop.  This is what I came up with:

#!/bin/bash
#
# Script to run firefox and load a specific site.
#
while :
do
clear
echo "************************"
echo "* My website loader    *"
echo "************************"
echo "* [1] Facebook         *"
echo "* [2] Google           *"
echo "* [3] Twitter          *"
echo "* [4] Youtube          *"
echo "* [5] Some other site  *"
echo "*                      *"
echo "* [0] Exit/Stop        *"
echo "************************"
echo -n "Enter your menu choice [1-5, or 0]: "
read yourch
case $yourch in
1)  firefox http://www.facebook.com & ;;
2)  firefox http://www.google.com & ;;
3)  firefox http://www.twitter.com & ;;
4)  firefox http://www.youtube.com & ;;
5) echo  ; read -p "Enter website: " ws ; firefox $ws & ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3, 4 or 5";
echo "Press Enter to continue. . ." ; read ;;
esac
done

————————————————–

See if your gmail account has new mail (warning: your name and password could get transmitted in the clear.)

username="username"
pword="password"
curl -u $username:$pword --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^(.*)<\/title>
<summary>(.*)<\/summary>.*?(.*?)<\/name>.*$/\n$3\n\t$1\n\t$2/'
# >> currentmail
# remove # on the previous line if you want the results sent to a file.

possible result:

me
test2
This is test 2.

Davi Jordan
test
Testing the ability of the gmail checker!

$ gmailchk.sh
No new gmail.

Another script:

#!/bin/sh
# Script to check for new gmail messages and launch (Icedove) Thumderbird
# Written by hip0 based on a one liner script suggeted by
# http://ihaveapc.com/2012/03/how-to-quickly-check-your-unread-gmail-from-linux-mint-ubuntu-terminal/
# hipo@noah:~$ date
# Sun Apr  1 20:37:41 EEST 2012

gmail_username='GMAIL-USERNAME';
gmail_password='SECRET-PASSWORD';
# gmail atom url
gmail_atom_url='https://mail.google.com/mail/feed/atom';
# set the mail client you prefer  or action if new messages are in gmail mailbox

curl -u ${gmail_username}@gmail.com:${gmail_password} --silent "$gmail_atom_url" | tr -d '\n' | awk -F '' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 – \1/p"

To set to run automatically:
$ crontab -e

...
*/15 * * * * /path/to/check_gmail_unread_mail.sh

then save and exit
———————————————-
Ever wished you could get data from a web page without reading the
whole web page, or for even just getting data from a server.   One thing I like to do is get the football scores. Find that SI.com and some other sites have so much going on it takes forever to navigate the pages. Not only that, you are subjected to all the ads. Just give me the scores so I can move on. Data mining allows me to do that.  In other words, the computer can be your personal secretary to get all the data you need for your special reports. without you having to do all that hard work and the extra time to be spent.

Written a series of beginner guides for data mining. You can find them at.

http://www.instructables.com/id/Data-mining/

Note:  The football score capturing script works best for the preceding week or earlier in the same season.

Update:

Let’s take what we have learned already and apply it. Showed you had to extract data to make your own web page and I also showed you how to cut and paste data. If you thought the web page was cumbersome to look at, now we will strip out just the teams and scores.

This time we are using the scores from week 3 of the preseason. So nice to be able to use the same code over and over. Anyway we just want the teams and their scores. Extracting the data is so simple and then we just paste everthing together and it might look like this:

All it took to do that was only a short bit of code.


#===================================

# Get score's

#

team=""

team="awayteam"

# output data

lynx -width 1000 -dump "http://oesrvr1/testcode/getscores1.php" | grep $team > scorefile

cut -c 12-25 scorefile > f1

cut -c 37-39 scorefile > f2

cut -c 49-60 scorefile > f3

cut -c 70-72 scorefile > f4

paste f1 f2 f3 f4 > allscoresfile.txt

#===================================

All for now.

———————————————

Most everyone knows about the amazing Arduino. This integrated circuit much acts like a minimal cpu chip. There are hundreds of uses for it. everything from Sous vide machines, mini-weather stations, game machines, water sprinkler control, and a host of other uses. It is even the perfect platform for making your own robot. The list is never ending. The project originally started in Italy as an open source project and has done nothing but grow exponentially in popularity. This simple 20 pin chip is amazing.

It has become so popular, that several companies have made development boards for the chip (now there are even more advanced versions of the Arduino i.e. Mega.) Fry’s carries the Osepp Arduino and Radio Shack carries the original dip version Arduino Uno, but now I think they have gone to a surface mount version. You can also get the chips and the boards from many electronics retailers such as Jameco. Early Arduino unos development boards came socketed, you could easily program your own chips and then use the chips without using the development board. You could purchase the chips alone for under three dollars. Now they are approaching six dollars, mostly because of demand. The boards for the regular Arduino sell for twenty five to thirty five dollars a piece. Still a bargain for what they can do.

For beginners, the development platform is probably the best. Though you can get the chips and a few side parts for under ten dollars and easily build your own on a bread board for testing. (http://www.instructables.com/id/The-RRRRRRRRRRBA-or-What-They-Dont-Teach-You-in-/). You could make a portable video game that could fit in a small candy tin, not including the monitor or hand controls. Did I say monitor? you can even hook up the Arduino to a monitor and or a tv (via an rf modulator). Like from the really old computer days. Hope you did not get rid of that old equipment when the media wanted you to. They are still good to go! There even has been developed a simple basic interpreter, so you can even write your old programs reminiscent of the old Vic 20 days.

Tv/monitor Connections will vary depending on the software you use, but the parts are generally the same. There are a zillion projects all over the net to work from. www.instructables.com has it’s own wealthy list. Can not wait to make a pong game. Linux starter instructable: (http://www.instructables.com/id/Ubuntu-and-the-arduino/) . Have already done a prototype of a minimal security system (http://www.instructables.com/id/Arduino-simple-security-idea/)

There are lots of add on boards (known as shields), even for use with ethernet. Almost forgot, there is “free” software that you can download most computers to allow you to program in their own “C” for the Arduino easily. (http://arduino.cc/hu/Main/Software)( It is not, what can you do with it. It is what can you not do with it. Have fun.

———————————————-

One of the things most people hate to do is to type in passwords. Not only could someone be looking over your shoulder, but also the password gets sent where it can be easily monitored. There has to be a better way. A method very much used on ‘nix systems (including OS/X) is called the ‘secure shell’ (ssh for short). You can actually use it on Microsoft systems also, but it requires more than usual extra setup. More about setting up here: (http://www.instructables.com/id/Linux-setup-for-SSH-password-less-login/).

$ ssh typo1

password: _

Anyway, if you are setting up a new system and or recovering from a hard disk crash, setting up the ssh keys to all the servers or systems you log into can be a lot of fun. There had to be a way of automating this process. The process is usually just three steps. Copy your key to the new server, adding the key to the authorized_key files, and then lastly removing the copied key if need be. So let’s make a batch file to take care of this.

Installkey.sh


# invoke with ./Installkey.sh servername

# copy the key

scp .ssh/id_dsa.pub $1:~/.

# install the key
ssh $1 'cat id_dsa.pub >> .ssh/authorized_keys'

# remove the public key you just copied
ssh $1 'rm ~/id_dsa.pub'

Save it to an ascii file.

Enable the shell file

$ chmod +x Installkey.sh

Run the code:

$ ./Installkey.sh typo1

Now you should be able to log into the server without typing a password.

$ ssh typo1
Linux typo1 2.6.32-5-686 #1 SMP Sun May 6 04:01:19 UTC 2012 i686

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Debian comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

/)
o /’ )
/’ ( ,.
__/’ ) .’ `;
o _.-~~~~’ “—..__ .’ ;
_.–‘ b) “–…____.’ .’
( _. )). `-._ <
`\|\|\|\|)-…..___.- `-. __…–‘-.’.
`—……____…—`.___.’—-… .’ `.;
`-` `

This machine is for the exclusive use of OE.
Anyone attempting to gain, or gaining access other
than as specifically authorized will be prosecuted
under all applicable statutes plus all applicable
civil rules for damages.

————————————————————————
You have mail.
Last login: Sun Aug 19 05:15:37 2012 from oedt01
$ _

But then I thought, what I need to do a bunch of servers, even that could be tedious. So let’s add some more code. First we need to make a list of the servers we want to update and save them to a file.

servers:

[data]
typo1
oesrvr1

[/data]

Now we need to use the original code and add a routine to read the server names from a file. That allows us to just type in one command and do all the servers. If we need to add a new server to the list, you just add it to the servers file. One bit of caution is that if you have run the program before, you do not need to do it again on prepared servers. Rename the existing servers file and start a new servers file.

srvrsshupdate.sh:

####################################
# Update remote ssh server keys
# by the sysadmin
# date: 08/19/2012
#=================================
# Assignments
# --------------------------------
# servers has list of servers to update (s/b 1 server name per line)
servernamefile=&quot;servers&quot;
# end assignments
#=================================
#
# Just do it. (main loop)
#---------------------------------
while read line
do server= $line
scp .ssh/id_dsa.pub $server:~/.
ssh $server 'cat id_dsa.pub &gt;&gt; .ssh/authorized_keys'
ssh $server 'rm ~/id_dsa.pub'
done &lt; $servernamefile
# end of main loop
#==================================
# End of job
###################################

Enable

$ chmod +x srvrsshupdate.sh

Run it
$ srvrsshupdate.sh

My desktop bit the dust I decided to put a new install of linux (Debian replaced Ubuntu.) You really should not use old ssh keys, so I regenerated a new and proceeded to update all the servers.

———————————————-

Another chip that is often overlooked is the Propeller cpu from Parallax. Although it does not have all the analog ports the Arduino does, it does have eight cores instead of just one. makes the chip very optimal for robotics. Traditionally it came in the dip (dual inline package), but now you just pretty much see the surface mount chips only,

There are many sites on the net that have available projects for the chip. With an amazing eight cores, you can easily do multitasking, which can be important for doing robotics. We prefer to use the old dip version and it easily plugs into breadboards. Several major retailers also carry the prefab boards for the chip. It’s own documentation states: “The Propeller is a good choice over other microcontrollers when a low system part count is desirable due to its ability to provide direct video output and an easy interface to external peripherals such as keyboard, mouse and VGA monitor. Pre-written objects to support many types of hardware also make it an attractive option. All of this plus low cost and a powerful, yet easy language are hard to beat in a world where microcontrollers come in so many flavors that it’s hard to make a choice. The Propeller really is an easy choice.” What more can I say?

——————————————–

Slowly print out a text file to the screen


#!/bin/sh

# A program to slowly cat file or standard input.

if [ &quot;$1&quot; ] ; then
file=&quot;$1&quot;
else
file=&quot;-&quot;
fi

cat &quot;$file&quot; | while read c ; do
echo &quot;$c&quot;
 sleep .005
done

———————————————

Password routine:


#!/bin/bash
 unset password
 prompt=&quot;Enter Password:&quot;
 while IFS= read -p &quot;$prompt&quot; -r -s -n 1 char
 do
 if [[ $char == $'' ]]
 then
 break
 fi
 prompt='*'
 password+=&quot;$char&quot;
 done
 echo
 # echo &quot;Done. Password=$password&quot;

——————————————————

Draw a flag


#!/bin/bash

#
 # memorial.sh -
 #
 # 2009 - Mike Golvach -
 #
 # Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
 #

echo -en &quot; (_)\n &lt;___&gt;\n | |______\n | |* * * )\n | | * * (_________\n | |* * * |* *|####)\n | | * * *| * | (________________\n | |* * * |* *|####|##############|\n | | * * *| * | | |\n | |* * * |* *|####|##############|\n | |~~~~~~| * | | |\n | |######|* *|####|##############|\n | | |~~~' | |\n | |######|########|##############|\n | | | | |\n | |######|########|##############|\n | |~~~~~~| | |\n | | |########|##############|\n | | '~~~~~~~~| |\n | | |##########JGS#|\n | | '~~~~~~~~~~~~~~~\n | |\n | |\n | |\n&quot;

——————————————————

Get your external ipaddress


echo -n &quot;the local ip is: &quot;
wget http://automation.whatismyip.com/n09230945.asp -O - -o /dev/null
echo

—————————————————

Was your down load ok? sometimes when we download large files such as operating system cd/dvd’s, we want to make sure the file was down loaded correctly. One way to do that is to use the md5sum command. Generally you need to download and display another small file that has the sum.
$ cat /home/eddie/Downloads/slackware-13.37-iso/slackware-13.3stall-dvd.iso.md5
64394febb8fb82520164645ade7dbaa0 slackware-13.37-install-dvd.iso

Then we want to calculate the sum to make sure they match.

$ md5sum /home/eddie/Downloads/slackware-13.37-iso/slackware-13.37-install-dvd.iso
64394febb8fb82520164645ade7dbaa0 /home/eddie/Downloads/slackware-13.37-iso/slackware-13.37-install-dvd.iso

——————————————–

Your window environment some how foobarred and you need to burn a cd so you can reload the operating system. No problem. First find out what drives can be used

$ sudo wodim –devices

wodim: Overview of accessible drives (2 found) :
————————————————————————-
0 dev=’/dev/sg1′ rwrw– : ‘TDK’ ‘CDRW161040X’
1 dev=’/dev/sg2′ rwrw– : ” ‘COMBO-52X16’
————————————————————————-

In this case, I will use drive one:

$ wodim -eject -tao speed=0 dev=/dev/scg2 -v -data /my/directory/image.iso

The -eject automatically opens the tray after the media is burned.

——————————————–

Want a job for that old clunker and have a real conversation piece also? Why not turn it into a clock!!! Never hurts to have a spare clock.



You can get the source code from here: (http://www.tenox.tc/out/) For linux, use the ncurses or the knr version. With build-essential installed on Debian. compile with:

$ gcc aclock.c -o clock -lcurses -lm

To run:

$ ./clock

—————————————————
Fritatta again. Cheap and filling.

Good day.

Advertisements