Hitting an auction/buy with BASH


Hitting an auction/buy with BASH

Disclaimer... You shouldn't abuse the idea/script, cause this would cause problems to the server, the product page and the creator/maker of the product. For the same reason, i don't post any URLs.

Recently i found a product i really liked and wanted to buy on Tindie. The problem was, that the product because of great demand and only a few pieces to buy, was always "Out of Stock". The supplier/manufacturer, hopefully managed to make some new ones and announced the day and time, when the new batch would be available.

So... i had to get one... and i had to know exactly the time, the item was available, with no chance to forget about, by being distracted, from some other activity. BASH to the rescue!

I made a very simple script, to check when the item was available and notify me, immediately. At the time, i would be in my computer, so i made the script in my Ubuntu machine and used notify-send for the notification. If i knew, i would be out, then i would make the script in Termux and used a termux command to either create an alert/push notification or play some sound... ^ there was no chance of missing the opportunity to get the product.

The script is simple... an infinite loop, using curl to retrieve the product page, piped through grep to find the "Out of Stock" string. If the command didn't return a result, that meant the product was in stock, so the notify-send command is executed to display a critical warning/notification on the desktop. I also put some sleep commands in the middle, cause i didn't want to make too many requests to the server.

I also put some other product URLs, of the same creator, cause i thought that perhaps, the platform could refresh that pages/products first and this would give me time, to stop whatever i was doing at that time, open the product page in the browser and be ready...

The whole idea and process, was successful! The script worked just fined... as i guessed, another item was refreshed (got in stock) first and quickly opened the web page of the product i wanted. Even if the product, vanished in just a few minuted, i was able to purchase one!!!! hoooray!

It's that simple things, that you can do with a computer, that help your everyday life and duties, that i really like Linux... another time, in another site, i was checking selling ads, to look for a specific item, in a specific price, when and if it would be available. That script, was running for weeks, when suddenly one day, i got an email, with a notification from that script that an ad was available to check it... and that's how i got a used laptop i wanted :)

#!/bin/bash

while :
do
  ans=$(curl -s https://url/to/product/page | grep -i "out of stock")
  if [ -z "$ans" ]; then 
    notify-send -u critical "Title" "******** is Available" -i error-correct-symbolic.symbolic.png
  fi
  sleep 5
  ans=$(curl -s https://url/to/product/page | grep -i "out of stock")
  if [ -z "$ans" ]; then 
    notify-send -u critical "Title" "******** is Available" -i error-correct-symbolic.symbolic.png
  fi
  sleep 5
  ans=$(curl -s https://url/to/product/page | grep -i "out of stock")
  if [ -z "$ans" ]; then 
    notify-send -u critical "Title" "******** is Available" -i error-correct-symbolic.symbolic.png
  fi
  sleep 15
done

Termux can handle notifications with termux-notification and you could play any music/sound file with mpv or the termux-media-player command. You could also make or use another script to send an email to your account as a reminder.

Add a comment

Previous Next