How to schedule script without a server for free

Dan Okhlopkov
4 min readAug 28, 2019

--

with Travis-CI and some magic

Hi there! If you need to run some crontab tasks every day, week or month, there is a way how you can do it without a server!

Well, technically you can’t run any script without a server because you need a machine where your task code will be executed. But who said that this should be your own server?

Travis-CI is a great free tool to run something based your open-source code. Who said that it should be the tests or deployment scripts? Let’s just run something we really need to be executed periodically. I’ll show you an example of how I automate my Instagram likes using Travis-CI and Instabot for free.

The script

What do I want to run daily? Well, I want to automate my Instagram likes to attract more Instagrammers to my profile. I’ve coded the simple script that will find likers of my profile (users who interested in my content) and will like their likers (hoping that their audience would be interested in my content too). The code was based on free open source Instagram automation library called Instabot which is the most used free Instagram bot (based on GitHub’s “used by” counter).

You can mention the environment variables — and they are very important. Since the code would be located in an open-source repository, you can’t commit your Instagram password (or any other credentials) because everyone could see them. That is why you need to use environment variables — I’ll show you how to set them at Travis-CI.

Also, I’ve created a file requirements.txt with only one word: instabot — this is the Instagram automation library that I used. This file will be used in Travis-Ci config.

The config

Travis config looks as simple as these 9 lines.

Travis-CI example config to run any script on Travis-CI

So basically Travis will run the machine with python3.6, will install all your dependencies and then just execute the `bot.py` file.

The maximum execution time of Travis job is 50 minutes, so keep in mind that if your script works longer, it would be stopped my Travis.

The environment variables and cron tasks

I will show you a step-by-step guide on how to set environment variables on Travis-CI and how to schedule travis-CI builds.

  1. Go to Travis-CI.org and login with GitHub
  2. Go to settings

3. Press “sync account”

4. Find the repo with your code and enable it

5. Press settings and go to settings

6. Scroll down to the environment variables section and set them

7. Scroll below to “Cron Jobs” and set daily builds:

That’s it! I hope you enjoyed the article. Please clap if you find this approach useful or at least interesting!

All code that was used in this article can be found in this repository. Put a star so as not to lose the code!
— — —
Best,
Dan

P.S.

Since GitHub Actions release, GitHub added their own CI/CD services with free 2,000 minutes per month. So you can run even more granular cron tasks and even on private repos. Good luck!

--

--

No responses yet