How to automate Python Script in Cron Job without .py file extension - python-3.x

I want to run the command webscreenshot automatically (project found at https://pypi.org/project/webscreenshot/#description).
This command should run via cron task or systemd automatically, every 15 minutes.
Running a linux server with python3.6, I've tried to incorporate this as a cron task but it is failing. Should I create my own python script to automate this?
*/1 * * * * /usr/bin/python3.6 /home/user/.local/bin/webscreenshot -i /home/user/projects/webscreenshot/data.txt -o /home/user/projects/webscreenshot/screenshots > /home/user/projects/log.txt 2>&1
I expect this to run the python script webscreenshot but this is not the case, screenshots are not produced.

#Ari - the .py extension is left out by the default installation.
I was able to get this to work by adding
xvfb-run to the begging, to read:
xvfb-run /dir/to/webscreenshot -i file.txt -o /output/dir/screenshots

Related

bash script doesn't work through crontab

I am running a bash script that transfers files to my AWS bucket.If i run the bash script through my terminal it works fine (via ./myBash.sh).
However I put it in my crontab but there it doesn't work.This is my bash script
#!/bin/bash
s3cmd put /home/anonymous/commLogs.txt s3://myBucket/
echo transfer completed
echo now listing files in the s3 bucket
s3cmd ls s3://myBucket/
echo check
And this is my crontab-
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
46 13 * * * /bin/bash myBash.sh
And here is a list of things i have aready tried -
1)tried running the crontab with a node app to test whether crontab was working(the answer was yes)
2)tried running the crontab without the SHELL and PATH
3)Tried running the bash script from cron using sudo (46 13 * * * sudo myBash.sh)
4)tried running the bash without the /bin/bash
5) Searched many sites on the net for an answer without satisfactory results
Can anyone help me with what the problem may be?(I am running Ubuntu 14.04)
After a long time getting the same error, I just did this :
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * /bin/bash /home/joaovitordeon/Documentos/test.sh
For anyone coming to this post.
I was having same problem and reason was crontab was running under root user and s3cmd was configured under ubuntu user.
so need to copy .s3cfg to root
cp -i /home/ubuntu/.s3cfg /root/.s3cfg

Shell script cronjob

I need a shell script that would run two .sh files which are in the directory: /opt/tomcat-latest/bin
#!/bin/sh
cd /opt/tomcat-latest/bin
./shutdown.sh
./startup.sh
Would this code achieve my goal? If so how do I make it on a cron job that runs every 2 hours? I have a Linux Centos VPS and DirectAdmin admin panel.
I think the easiest solution would be to run directly the commands with its full path from cron, instead of using a sh script.
Something like this in the crontab would work :
* */2 * * * /opt/tomcat-latest/bin/shutdown.sh && /opt/tomcat-latest/bin/startup.sh
That would run every 2 hours
you can edit crontab with crontab -e and check the crontab syntax here : https://fr.wikipedia.org/wiki/Crontab

Downloading files with bash via cron

I have build a bash script that gets .tar.gz files from IMDb and writes to a log file, the script works when run on its own as I can see the folder with the files present, but when I run the script via cron it doesn't work. Would this be due to permissions? I have edited the sudo crontab file, but I'm not sure what else I need to do.
Try this solution:
Cronjob is a file that contains your job:
cat cronjob
* * * * * bash /path/to/script.sh >> /path/to/log.txt
Then you should set executable permission and start cron service:
chmod +x cronjob
/etc/init.d/crond start #redhat based servers like centos
/etc/init.d/cron start #debian based servers like ubuntu
After that you should tell cron service to run cronjob file:
crontab cronjob
Your script should download a file.
If your script doesn't run you should run it from good path[full path], so your cronjob file would be something like this:
* * * * * /bin/bash /path/to/script.sh >> /path/to/log.txt

Raspberry crontab script running

I'm trying to run a command by cron in Raspbian.
If I run ./sec_cam.sh, than my script runs, If I try to run it via crontab every 5 min, than nothing happens.
crontab -e shows me the followings:
*/5 * * * * ./sec_cam.sh
Did I configure the crontab wrong?
Thx in advance
scripts started from a cronjob are not setup with your usual environment, especially not with your current working directory (referenced by the . in ./sec_cam.sh). so to make this work you should specify a full path name like /home/user/sec_cam.sh

Ubuntu 10.04 LTS Cron jobs not working

I'm trying to use a cronjob to run a ruby script (Using Rails3 runner) with the following Cronjobs:
#!/bin/bash
0-59 * * * * echo 'script test'
# Begin Whenever generated tasks for: test1
* * * * * /bin/bash -l -c '/home/administrator/test1/script/rails runner /home/administrator/test1/app/create_flag.rb >> /home/administrator/test1/test.log 2>&1'
# End Whenever generated tasks for: test1
test1 is the name of the Rails3 project folder.
the "echo 'script test'" was added as a test, but neither seems to be executing. I'm currently using Ubuntu 10.04 LTS.
Have I written the cronjob incorrectly?
Crontab file is not a shell script. So you don't need #!/bin/bash at the beginning of the file. Plus, spaces there are suspicious. Try something like this:
SHELL=/bin/bash
MAILTO=administrator#localhost
BASH_ENV=/home/administrator/.bash_profile
* * * * * /home/administrator/test1/script/rails runner /home/administrator/test1/app/create_flag.rb >> /home/administrator/test1/test.log 2>&1'
Plus, make sure you call crontab -e as administrator to edit the crontab file.
You need to specify the user which runs the commands (you can see the format here. Also the echo will output 'script test' to what? If you want a test try doing a touch on a file, so you can physically see the action of the cron job.
Cron does not use your user environment, so it will not have the same path set that you have. This means that you should use absolute paths for commands.

Resources