Using Bash and Perl in Ubuntu to get Stock Quotes Presented by Dave Mawdsley, DACS Member, Linux SIG November 16, 2011 (a quick way to see the latest prices of your stocks)
My Requirements I want a summary text file on my desktop that contains quotes of all of my stocks as of today. The text file is to be populated by the Bash and Perl scripts. This summary file will be called stockquotes.txt. I want the stock symbols of my stocks to be in a file in the home directory called stockquotesdwm.csv that the Perl script will read and use. For each line of this cvs file, there is the stock symbol, a comma, and then the exchange abbreviation. The Bash script will be used to manage the Perl script which will do the heavy lifting. 1
stockquotesdwm.csv AAPL,NASDAQ DELL,NASDAQ MSFT,NASDAQ ORCL,NASDAQ YHOO,NASDAQ HPQ,NYSE IBM,NYSE NOK,NYSE 2
Step 1: Install the Perl Financial Utility Using terminal, issue the following command: sudo apt-get install libfinance-quote-perl What this does is to install a finance quote library file that a Perl script can use. It has direct access to stock exchange data when the library features are used. 3
Step 2: Bash Script Manager 'perlmgr.sh' 4
Step 3: Perl Stock Quote Script 'stockquotes.pl' 5
Step 4: Change Permissions 6 Using terminal, issue the following command to make the two scripts executable: chmod u+x perlmgr.sh stockquotes.pl
Step 5: Run the Bash Script 7 Continuing in terminal, issue the following command to run the Bash script 'perlmgr.sh':./perlmgr.sh
The Output of stockquotes.txt 8
Comments p. 1 9 The output has the stock symbol and exchange backwards, but it's still readable with the latest price listed. (a minor coding choice of the Perl script) Perl has a rich library system developed over the years which make Perl scripts easy to use and very functional with time-tested libraries. Perl is called "the Swiss Army chainsaw of programming languages" (Wikipedia) The Bash script is useful for the ease of navigating directories, using utilities central to Linux and for launching applications using other programming languages from the command line. I used two scripts because each was particularly good in its own way.
Comments p Using multiple programming languages or scripts to handle a single problem set is routine today. Imagine what Firefox manages as a user visits a webpage. Here's a sample of some of the things Firefox may be required to do: Read and interpret HTML or some variant of it. Fetch data from a distant URL and reconstruct all the images. Use multiple JavaScript routines to help display surface content. (much of displayed advertising) Use a PHP script to access a database using mySQL and deliver relevant specific information back to the browser's page. Call a CGI script on a server to deliver content to an provider on the server such as SendMail. Embed sound and video using Java. Capture information about the user's computer system. Manage the display preferences of the user.
Using Bash and Perl in Ubuntu to get Stock Quotes This OpenOffice.org Presentation 'stocks.odp' can be downloaded from (a quick way to see the latest prices of your stocks)