CasperJS and cronjob - phantomjs

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.

Related

Cron job permission denied

I'm running a python script called TGubuntu.py.
I used ls -l , and the permissions of the script are -rwxrwxrwx 1 ubuntu ubuntu 503 Jan 13 19:07 TGubuntu.py, which should mean that anyone can execute the file, right?
But I still get in the log /bin/sh: 1: /home/ubuntu/TestTG/TGubuntu.py: Permission denied for some reason.
When I run the script manually it works perfectly.
Any Ideas?
I put it in the sudo crontab like this
* * * * * /home/ubuntu/TestTG/TGubuntu.py
But even in the root (cron) mail log it says Permission Denied!
Couldn't figure out what the problem was, so I accomplished my goal using a different method.
I ran a python script that uses the schedule module to call my script. Then I just let the "Timer" run on screen indefinitely.

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.

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

Unable to run a postgresql script from bash

I am learning the shell language. I have creating a shell script whose function is to login into the DB and run a .sql file. Following are the contents of the script -
#!/bin/bash
set -x
echo "Login to postgres user for autoqa_rpt_production"
$DB_PATH -U $POSTGRESS_USER $Auto_rpt_production$TARGET_DB -p $TARGET_PORT
echo "Running SQL Dump - auto_qa_db_sync"
\\i auto_qa_db_sync.sql
After running the above script, I get the following error
./autoqa_script.sh: 39: ./autoqa_script.sh: /i: not found
Following one article, I tried reversing the slash but it didn't worked.
I don't understand why this is happening. Because when I try manually running the sql file, it works properly. Can anyone help?
#!/bin/bash
set -x
echo "Login to postgres user for autoqa_rpt_production and run script"
$DB_PATH -U $POSTGRESS_USER $Auto_rpt_production$TARGET_DB -p $TARGET_PORT -f auto_qa_db_sync.sql
The lines you put in a shell script are (moreless, let's say so for now) equivalent to what you would put right to the Bash prompt (the one ending with '$' or '#' if you're a root). When you execute a script (a list of commands), one command will be run after the previous terminates.
What you wanted to do is to run the client and issue a "\i ./autoqa_script.sh" comand in it.
What you did was to run the client, and after the client terminated, issue that command in Bash.
You should read about Bash pipelines - these are the way to run programs and input text inside them. Following your original idea to solving the problem, you'd write something like:
echo '\i auto_qa_db_sync.sql' | $DB_PATH -U $POSTGRESS_USER $Auto_rpt_production$TARGET_DB -p $TARGET_PORT
Hope that helps to understand.

glassfish start script fails through crontab

I have a created a script to check to see if my glassfish server is running (installed on a freebsd system), if it isn't, the script attempts to kill the java process to ensure it's not hung, and then issues the asadmin start-domain command
If this script runs from the command line it is successful 100% of the time. When it is run from the cron tab, every line runs except the asadmin start-domain line - it does not seem to execute or at least does not complete, i.e. the server is not running after this script runs.
For anyone not familiar with glassfish or the asadmin utility used to start the server, it is my understanding that a forked process is used. could this be causing a problem via cron?
Again, in all my tests today, the script runs to completion when run from the command line. Once it's executed through the cron, it does not complete... what would be different running this from the crontab???
thanks in advance for any help... i'm pulling my hair out trying to make this work!
#!/bin/bash
JAVA_HOME=/usr/local/diablo-jdk1.6.0/; export JAVA_HOME
timevar=`date +%d-%m-%Y_%H.%M.%S`
process_name='java'
get_contents=`cat urls.txt`
for i in $get_contents
do
echo checking $i
statuscode=$(curl --connect-timeout 10 --write-out %{http_code} --silent --output /dev/null $i)
case $statuscode in
200)
echo "$timevar $i $statuscode okay" >> /usr/home/user1/logfile.txt
;;
*)
echo "$timevar $i $statuscode bad" >> /usr/home/user1/logfile.txt
echo "Status $statuscode found" | mail -s "Check of $i failed" some.address#gmail.com
process_id=`ps acx | grep -i $process_name | awk {'print $1'}`
if [ -z "$process_id" ]
then
echo "java wasn't found in the process list"
else
echo "Killing java, currently process $process_id"
kill -9 $process_id
fi
/usr/home/user1/glassfish3/bin/asadmin start-domain domain1
;;
esac
done
Also, just for completeness, here is the entry in the cron tab:
*/2 * * * * /usr/home/user1/server.check.sh >> /usr/home/user1/cron.log
Ok... found the answer to this on another site, but I thought I'd add the answer in here for future reference.
The problem was the PATH!! even though java_home was set, java itself wasn't in the path for the cron daemon.
A quick test to see what path is available to your cron, add this line:
*/2 * * * * env > /usr/home/user1/env.output
From what I can gather, the PATH initially available to cron is pretty minimal. Since java was in /usr/local/bin, i added that to the path right in the crontab and kaboom! it worked!
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*/2 * * * * /usr/home/user1/server.check.sh >> /usr/home/user1/cron.log