Microsoft-Rewards-Script icon indicating copy to clipboard operation
Microsoft-Rewards-Script copied to clipboard

How To Schedule Run?

Open royaltongue opened this issue 1 year ago • 5 comments

I have a file run-bot.sh that contains the following:

cd ~/Documents/ms-rewards
npm run start

I've then added the following to crontab: 00 22 * * * sh /home/royaltongue/Documents/ms-rewards/run-bot.sh > /home/royaltongue/Documents/ms-rewards/cronlog.txt

However, the script never actually runs. When looking at the content of the log I created, it shows:

> [email protected] start
> node ./dist/index.js

Am I doing something wrong with setting this up?

Additionally, manually running sh /home/royaltongue/Documents/ms-rewards/run-bot.sh from a terminal runs the script fine.

royaltongue avatar Mar 29 '24 02:03 royaltongue

In crontab just use something like: 00 22 * * * /path/to/nodejs /baseBotPath/dist/index.js

Usually the path for nodejs is /usr/bin/node. But if you use nvm you have to specify the nvm node path

gianlucalauro avatar Mar 29 '24 10:03 gianlucalauro

When trying to run /usr/bin/node /home/royaltongue/Documents/ms-rewards/dist/index.js, the following gets returned:

/home/royaltongue/Documents/ms-rewards/dist/index.js:165
            const mobileSearchPoints = (await this.browser.func.getSearchPoints()).mobileSearch?.[0];
                                                                                                ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

royaltongue avatar Mar 29 '24 21:03 royaltongue

When trying to run /usr/bin/node /home/royaltongue/Documents/ms-rewards/dist/index.js, the following gets returned:

/home/royaltongue/Documents/ms-rewards/dist/index.js:165
            const mobileSearchPoints = (await this.browser.func.getSearchPoints()).mobileSearch?.[0];
                                                                                                ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

What's your node version?

TheNetsky avatar Mar 29 '24 22:03 TheNetsky

21.6.1

royaltongue avatar Mar 29 '24 23:03 royaltongue

I used 10 7,15 * * * cd /root/Microsoft-Rewards-Script && npm run start for base script just fine for daily runs, and now with docker I’m using the following script to add some randomness to the start time:

#!/bin/bash

MINWAIT=$((5*60))
MAXWAIT=$((50*60))
SLEEPTIME=$((MINWAIT+RANDOM % (MAXWAIT-MINWAIT)))
echo "sleeping for "$((SLEEPTIME / 60))"m ("$SLEEPTIME"s) ..." 
sleep $SLEEPTIME
echo "starting container"
docker start netsky

Make sure the script is executable

Set up cron to run the script daily using crontab -e and entering the following line, which should run the script at 5:30 am daily + the random sleeptime calculation above: 30 5,11 * * * /bin/bash /root/Microsoft-Rewards-Script/daily.sh

You could probably adapt the script above too for the regular script too

mgrimace avatar Mar 30 '24 19:03 mgrimace