1

So I am working on trying to write shell scripts in linux and I have one that goes out and grabs current stock quotes and would like to save this in a txt or json format. It seems like I can run the script in the terminal, but when I set it up on crontab, it seems to fail. Can someone shed a little light, here is what I have so far.

Cron job:

#!/usr/bin
* * * * * PATH=$PATH:/usr/local/bin:/usr/bin && export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH &&  /home/mint/Desktop/BashScripts/Stocks/GetStocks.sh

Shell script:

#!/bin/bash
* * * * * echo -e "[{'Ford':' $(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1') ', 'Square':' $(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=sq&f=l1') ' }]" > stocks.txt

Error:

/home/mint/Desktop/BashScripts/Stocks/GetStocks.sh: line 2: dead.letter: command not found
1
  • The first 5 fields of the crontab are the schedule of when the command should be run. Why would you copy them to the script? Commented Feb 27, 2016 at 1:03

2 Answers 2

1

Lose the asterisks in front of echo. They don't belong in a shell script. It's interpreting them as wildcards, and trying to execute the first matching name, which is dead.letter.

Also, instead of sending output to stocks.txt, you should give it an absolute path to somewhere it can write like /home/jpavlov/stocks.txt. And you probably want to use >> so it appends instead of overwriting.

Sign up to request clarification or add additional context in comments.

Comments

0
  • Cron job: your code looks to be is correct.

  • Shell script: you need to remove the (all first 5 asterisks) * * * * * from this Shell Script. Because thess fields of the crontab are to schedule the command execution time . so here its creating issues.

So your final code would be following:

Cron job:

#!/usr/bin
* * * * * PATH=$PATH:/usr/local/bin:/usr/bin && export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH &&  /home/mint/Desktop/BashScripts/Stocks/GetStocks.sh

Shell script:

#!/bin/bash
echo -e "[{'Ford':' $(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1') ', 'Square':' $(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=sq&f=l1') ' }]" > stocks.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.