Grab a book a day for free from Packt Pub, https://www.packtpub.com/packt/offers/free-learning.
Install this script in the cloned directory using the following command:
npm install
Copy the .env file into place with
cp .env.example .env
Or on Windows:
copy .env.example .env
And set your packt email and password.
After that run the script with the following command:
watch -n 5000 --differences node server.js
Or add it to your crontable:
crontab -e
For the crontab all paths in MUST be absolute.
Within the open cron editor window
0 14 * * * /usr/local/bin/node /Users/<USER_NAME>/<PATH_TO>/grab_packt/server.js >> /tmp/cron_output
If you are using UTC/BST timezone in your server, you might want to set the crontab as follow:
25 0 * * * /usr/bin/nodejs /home/user/grab_packt/server.js >> /tmp/cron_output
Check the run.bat file in the repo. Correct any path if necessary according to your needs. Try running the script manually to verify that it works as expected.
Then add a scheduled task to execute run.bat every day by running.
add_scheduled_task.bat
If you get the message:
crontab: temp file must be edited in place
On a related issue, if you get the message:
crontab: temp file must be edited in place
Try:
- Add to
.bash_profile
alias crontab="VIM_CRONTAB=true crontab"
- Add to
.vimrc
if $VIM_CRONTAB == "true"
set nobackup
set nowritebackup
endif
note: .bash_profile might be called .profile
note: .vimrc and .bash_profile are located in the home directory: ~/
Reference: http://superuser.com/a/750528
launchd is recommended over cron for the OSX system.
This runs on load and from then on every 24 hours (86400 seconds).
Just substitute <username>
for your own.
by daemon I am referring to the .plist file
Navigate to directory:
cd $HOME/Library/LaunchAgents
Create file:
touch com.<username>.grab_pkt.plist
Edit file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.<username>.grab_pkt</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/node</string>
<string>/Users/<username>/development/misc/grab_packt/server.js</string>
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>86400</integer>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/GrabPkt.err</string>
<key>StandardOutPath</key>
<string>/tmp/GrabPkt.out</string>
</dict>
</plist>
Load this daemon into the system:
launchctl load com.<username>.grab_pkt.plist
to unload just change load to unload
Check output of script:
/tmp/GrabPkt.out
It should be similar to:
----------- Packt Grab Started -----------
Book Title: Learning Libgdx Game Development
Claim URL: https://www.packtpub.com/freelearning-claim/13277/21478
----------- Packt Grab Done --------------
Check for errors:
/tmp/GrabPkt.err
Mine is empty due to having no errors.
In order to test I would:
- remove the
GrabPkt.out
file - unload daemon
- load daemon
- check output of
GrabPkt.out
file
reference: http://alvinalexander.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs
- You need to sign up for an AWS account or use an existing one.
- After sign in to the AWS Management Console, select a region and open the AWS Lambda console.
- Choose Get Started Now.
- Note: The console shows the Get Started Now page only if you do not have any Lambda functions created. If you have created functions already, you will see the Lambda > Functions page. On the list page, choose Create a Lambda function to go to the Lambda > New function page.
- On the Select blueprint page, choose Skip.
- On the Configure triggers page, do the following:
- Choose CloudWatch Events - Schedule.
- Enter a rule name in Rule name.
- Schedule expression select
rate(1 day)
. - Check Enable trigger.
- Choose Next.
- On the Configure function page, do the following:
- Enter a function name in Name.
- Runtime is
Node.js 4.3
or above. - Code entry type is
Upload a .ZIP file
. - Zip the source code and Upload.
- Please make sure to execute
npm install
and configure.env
before zip the source code. - In the Lambda function handler and role section, do the following:
1. Handler is
aws-lambda.handler
. 2. In Role, choose Create new role from template(s). 3. In Role name, type a name for the role. 4. In Role templates, you can leave this field blank because your Lambda function already has the basic execution permission it needs. - In the Advanced settings section, do the following:
1. In Memory (MB), choose
128
. 2. In Timeout, enter0
min30
sec. - Choose Next.
- Choose Create Function to create a Lambda function.
- Choose Test.
- In the Input test event page, enter
{}
in the window. - Choose Save and test.
- Upon successful execution, view results in the console.