0

I want to create a .sh script which will

  1. execute a python file called match_scraper.py,
  2. update a psql db as shown,
  3. call a scrapy spider to execute.

When I create the .sh script how do I call those commands properly? This is what I have come up with:

#!/bin/bash

~Documents/dota2/dotaapi2/ python match_scraper.py 

psql dota2apidb
update games set online=1 where online is null;

~Documents/dota2/gosugamers/gosugamers/spiders/ scrapy crawl dota
1
  • 1
    What are ~Documents/dota2/dotaapi2/ and ~Documents/dota2/gosugamers/gosugamers/spiders/ supposed to be? The directories containing the scripts? I'd guess you want to do cd ~/Documents/dota2/gosugamers/gosugamers/spiders/ (and similarly for the other one), instead. (Note: slash / after ~: askubuntu.com/q/656869/158442)
    – muru
    May 2, 2016 at 18:58

1 Answer 1

3

First you need to make sure each line/part of your script work in a shell (outside of a script). I cannot tell if yours will so you'll have to check that yourself.

And to execute a script you need python BEFORE the path to the script

Also:

  • ~ is a shortcut to the home directory of the current user
  • ~asdf is a shortcut to the home directory for the asdf user
  • ~/Documents is the path to the Documents folder in the home directory of the current user
  • ~Documents is looking for the home directory of the Directory user which is invalid unless you have a user called Directory

As @muru pointed out, you probably meant ~/Documents. So your bash script would probably look something like this

#!/bin/bash

python ~/Documents/dota2/dotaapi2/match_scraper.py 

psql dota2apidb
update games set online=1 where online is null;

python ~/Documents/dota2/gosugamers/gosugamers/spiders/scrapy crawl dota

Again, I do not know if this will work since I have no clue if each line will work. For example, does python ~/Documents/dota2/gosugamers/gosugamers/spiders/scrapy crawl dota actually work when you run it on the command line?

And I do not know but I suspect you need to pass it some command line paramater to get it to run that update... command?

2
  • The 'scrapy crawl dota' command works from the terminal if I am in the file path of ...gosugamers/gosugamers May 2, 2016 at 19:46
  • Well, as long as you can do things from a shell then you'll be able to include in your bash script. May 3, 2016 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .