0

This is my current command to poll Yahoo! every two minutes for various stock prices and stick them on my old PowerBook's root window using the GeekTool pref pane...Apple for example:

echo 'AAPL: '; curl -s 'http://download.finance.yahoo.com.d/quotes.csv?s=aapl&f=l1' > .aapl.stock.txt; cat .aapl.stock.txt

What I would like to ask of UNIX literates is how to only poll Yahoo! between 9:30 am and 4:00 pm.

After trading hours every two minutes I'm asking these poor Yahoo! computers for a value that never changes! Help!

Mihai Maruseac
  • 20,967
  • 7
  • 57
  • 109
CT Hildreth
  • 205
  • 1
  • 2
  • 8

1 Answers1

2

You can exit or otherwise stop execution outside your target interval:

# Get current hours and minutes.
h=$(date +%H) m=$(date +%m)

# If it's less than 9:30, exit
[[ $h -lt 9 || $h -eq 9 && $m -le 30 ]] && exit 1

# If it's after 4, exit
[[ $h -ge 16 ]] && exit 1

yourcommand
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Thanks for your answer that obviously required a lot of shift-key action. I need to put a semi-colon between the final 'exit 1' and my 'your command', correct? Without the semi-colon I get a system.log error of '-eq: command not found' – CT Hildreth May 01 '14 at 01:20
  • It works fine as is as long as it's run with `bash`. If your tool requires that it all fits on one line, I recommend you make a wrapper script instead. – that other guy May 01 '14 at 01:29
  • I came back to this problem and realized that by "wrapper script" you just meant a shell script. Problem solved. – CT Hildreth Jun 17 '14 at 14:18