Run Gatbsy Buil periodically in crontab - npm

I would need to recreate my site in gatsby (https://www.gatsbyjs.com/) every hour using crontab.
I created a simple script in the project folder:
#!/bin/bash
cd /var/www/html && \
npm run build
And created a crontab ( currently every minute )
* * * * * /var/www/html/build.bash 1> /dev/null 2> /home/user/test.txt
If I run the script directly it works fine, but when run from crontab I get an error:
/var/www/html/node_modules/gatsby-cli/lib/reporter/loggers/ink/index.js:13111
const lineNumber = location?.start.line;
^
SyntaxError: Unexpected token '.'

Related

Crontab is not running at SSH remote server

I want to run a bash shell script every 7am every day.
But it didn't work.
This is the commands.
00 07 * * * / usr / bin / sh /home/Download/download.sh
i have tried running on local device. When I run it on a local device, the crontab works fine, but when I try on a remote server it doesn't run. any solution with this case?
I assume you want to run /home/Download/download.sh every day at 7am.
First make sure your file is executable:
chmod +x /home/Download/download.sh
Depending on your machine, the path to sh may be different. Check it with which sh command. Most times it is at /bin/sh so your crontab would look like:
0 7 * * * /bin/sh /home/Download/download.sh
But nevertheless I think you don't need /bin/sh so your crontab should look like:
0 7 * * * /home/Download/download.sh
One first
sudo crontab -e
Second
chmod +x /home/Download/download.sh
and last.
0 7 * * * /home/Download/download.sh

Setting up a Crontab for scrapy

I am trying to set up a crontab for scraping something. So far, I wrote
23 18 * * * cd PycharmProjects/untitled/Project1 && scrapy crawl xx -o test.csv
But when I do that I get this:
/bin/sh: scrapy: command not found.
What should I do?
I tried to locate the scrapy in my mac but couldn't find it. But I am able run the second part of the crontab task from terminal.
Since crontab doesn't set up PATH variable for you, it doesn't know what scrapy is.
The easy way to remedy is to use full path of scrapy:
$ which scrapy
/usr/bin/scrapy
Then use that instead of just scrapy:
23 18 * * * cd PycharmProjects/untitled/Project1 && /usr/bin/scrapy crawl xx -o test.csv
Another way of doing this is to set the PATH environment in your crontab:
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# or your custom path, check your `.bashrc` for PATH you have set in your shell
23 18 * * * cd PycharmProjects/untitled/Project1 && scrapy crawl xx -o test.csv
Sidenote:
Also it's very common in cron to wrap your command in some sort of script that populates the PATH and other configurations and calling that script in cron instead of calling the commands directly.

CasperJS and cronjob

so I have phantomJS and casperJS installed, everything is working fine, but I'm trying to add my casperJS file to cronjob (ubuntu) and I'm getting error:
/bin/sh: 1: /usr/local/bin/casperjs: not found
My crontab file:
0 */1 * * * PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs
/usr/local/bin/casperjs /usr/local/share/casper-test/test.js 2>&1
Any Ideas whats wrong?
If you want to use several commands on one line, you have to separate them with a semicolon:
0 */1 * * * PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs ; /usr/local/bin/casperjs /usr/local/share/casper-test/test.js 2>&1
Or, if you need to execute commands sequentially and only progress to next if the previous has been successful, use && operator.
For better readability you could just put those commands in a shell script and run that from cron.

Executing Node Forever module in Crontab fails

In root user crontab I added the below job:
*/1 * * * * /usr/local/bin/forever start /root/MyCode/server.js >> /root/ou1.log 2>&1
I am getting the below error:
info: Forever processing file: /root/MyCode/server.js
/usr/local/lib/node_modules/forever/lib/forever.js:419
monitor.send(JSON.stringify(options));
^
TypeError: Object # has no method 'send'
at Object.startDaemon (/usr/local/lib/node_modules/forever/lib/forever.js:419:11)
at /usr/local/lib/node_modules/forever/lib/forever/cli.js:258:13
at /usr/local/lib/node_modules/forever/lib/forever/cli.js:145:5
at Object.oncomplete (/usr/local/lib/node_modules/forever/lib/forever.js:358:11)
But if I manually run the forever command in terminal, its working..
Forever "version": "0.11.1"
node version: v0.10.17
It seems like some problem with the installation. In the above example am using a vagrant box. I installed forever in fresh vagrant box, and it worked..

date time variable into crontab -e url

i try to work with crontab -e into ssh at centos 6
i can't work with variable into crontab -e
i try many times to get it to work but i failed to run with it
MYDATE=`date`
*/1 * * * * /usr/bin/curl --head -sf http://localhost/php.php?date=$MYDATE -o /dev/null || /restart.sh
i can't work with variable into crontab -e
i try many times to get it to work but i failed to run with it
i need date into url to make refresh url every time because i use high cache i need to
test url every time with new one
there any way to run it every minute
* * * * * SUFFIX=`date +\%M`; cp /home/temp.php /home/temp3_${SUFFIX}.php >/dev/null