I set up an Ubuntu 18.04 virtual machine to start playing around with running Instapy with a cron job each day.
I setup Instapy inside of it's own virtual environment. When I manually activate the env and run quickstart.py, Instapy works great.
When I try to run it using a cron, nothing happens. I created a .sh file and my cron calls that .sh file:
* * * * * /home/user/Desktop/instapy/cron.sh
Inside of my .sh file I have:
#! /bin/bash
cd /home/user/Desktop/instapy
source /home/user/Desktop/instapy/env/bin/activate
python /home/user/Desktop/instapy/InstaPy/quickstart.py
When I run each of these commands in terminal individually, Instapy works fine.
I've ensured that all permissions on my .sh file as well as quickstart.py are set to allow executing.
I'm not sure what else I can look at to try to get this working when everything works fine except for the cron.
Ideas?
I am using the same environment, and I was able to setup a chron job.
Here it is, in case it gives you some ideas.
0 4,16 * * * cd ~/InstaPy-master && /usr/local/bin/docker-compose up -d --build
Thanks, but I'm not sure that helps me. Looks like the only difference is you're entered the commands directly in the cron and I'm utilizing them in a .sh file. For what it's worth, I've also entered my commands just as you have above and it still doesn't work.
Just feel like it has to be some sort of permissions issue or something I'm missing.
@azurmobile In cron you should be able to do
0 4,16 * * * cd /home/user/Desktop/instapy/InstaPy && python ./quickstart.py
@westondeboer
From what I've been reading, cron needs absolute paths to work most effectively? That said, I eliminated the .sh file I was trying to use and have included the paths right inside the cron like so:
* * * * * cd /home/user/Desktop/instapy && source /home/user/Desktop/instapy/env/bin/activate && /home/user/Desktop/instapy/env/bin/python /home/user/Desktop/instapy/InstaPy/quickstart.py
When I copy and paste that exact code into terminal, InstaPy starts up and works just fine. It just will not work with a cron no matter what I try.
try this
sudo apt-get install run-one to make sure only 1 instance runs
`*/30 * * * * cd /home/ubuntu/ifollow/InstaPy-master && run-one /usr/bin/python3.5 ./quickstart.py
@loopypanda
Thanks. No go on that one. Nothing saved to the log file. Just nothing. It's mind-boggling.
It is system path issue. Probably chromedriver not finding chrome or something. Set the necessary system path at the top of crontab, like this PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Thanks all. A buddy ended up taking a look and getting me going. Here's the result that seems to work for me if anyone else is having similar issues:
* * * * * bash -c "cd /home/user/Desktop/instapy && source /home/user/Desktop/instapy/env/bin/activate && /home/user/Desktop/instapy/env/bin/python /home/user/Desktop/instapy/InstaPy/quickstart.py"
I've setup cron on Ubuntu with the following command
0 */3 * * * /home/ubuntu/InstaPy && python3.5 quickstart.py
it's not working @timgrossmann mentioned this was the promised tried and true way, but it hasn't been working for me.
@deronsizemore do you have an email notification setup to let you know that the cronjob has run?
@SeanFmcdonnell
No I don't. Might do it in the future, but as for now, I know when the cron is set to run each morning so I just pop over into that Ubuntu VM and check it in terminal using this command:
tail -f /path/to/my/log.log
I get the following when I try that command:
root@ubuntu-s-1vcpu-1gb-nyc1-01:~/InstaPy# tail -f /path/to/my/log.log
tail: cannot open '/path/to/my/log.log' for reading: No such file or directory
tail: no files remaining
@SeanFmcdonnell how is your cron setup ?
SHELL=/bin/bash
HOME=/
MAILTO=”[email protected]”
0 */4 * * * cd /root/InstaPy && python3.5 quickstart.py
@SeanFmcdonnell to output the log to a file you can do it in this way:
25 6 * * * cd /opt/InstaPy && python /opt/InstaPy/bot_setup.py >> /home/converge/cronlog.log 2>&1
if you open ~/cronlog.log after cron run, it will output the result of the action if it find some environment issue or the actual InstaPy log.
@converge btw thank you for your youtube video explaining how to set this up in Ubuntu - but the cronjobs still aren't working for me. I'm also interested in having the the cron status or log emailed to me. Am I doing something wrong with my paths?
@SeanFmcdonnell thank you! :)
I did this job sometime ago, this is a bit more complicated, basically:
Ok I'll look into exim thank you, but I still have no insight into my cronjob and if it is working properly with the commands that were given?
take a look again, you're trying to load your quickstart file without the full path
I changed the path to..
0 */4 * * * cd /root/InstaPy && python3.5 /root/InstaPy/quickstart.py
and ran
systemctl restart cron
and got the following..
```root@ubuntu-s-1vcpu-1gb-nyc1-01:~# service cron status
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-11-05 19:58:27 UTC; 1min 31s ago
Docs: man:cron(8)
Main PID: 26829 (cron)
Tasks: 1
Memory: 308.0K
CPU: 2ms
CGroup: /system.slice/cron.service
└─26829 /usr/sbin/cron -f
Nov 05 19:58:27 ubuntu-s-1vcpu-1gb-nyc1-01 systemd[1]: Started Regular background program processing daemon.
Nov 05 19:58:27 ubuntu-s-1vcpu-1gb-nyc1-01 cron[26829]: (CRON) INFO (pidfile fd = 3)
Nov 05 19:58:27 ubuntu-s-1vcpu-1gb-nyc1-01 cron[26829]: (CRON) INFO (Skipping @reboot jobs -- not system startup)```
it's ok to just update the cron and wait until it starts. I suggest you to use crontab -e to edit yours entries. I see that you're running it as root, so: sudo crontab -e
after save/quit it will start waiting to run.
Also, set the time to see it running, in your case it will only run in 4 to for 4. For example, it will run in the next minute if now it 19:16
17 19 * * * cd /root/InstaPy && python3.5 /root/InstaPy/quickstart.py >> /root/InstaPy/cronlog.log 2>&1
and will output in /root/InstaPy/cronlog.log
Ok I think that worked. Not sure though. Here is my latest cron command
32 * * * * cd /root/InstaPy && python3.5 /root/InstaPy/quickstart.py >> /root/InstaPy/cronlog.log 2>&1
here is the output after running service cron status
```root@ubuntu-s-1vcpu-1gb-nyc1-01:~# service cron status
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-11-05 19:58:27 UTC; 1h 39min ago
Docs: man:cron(8)
Main PID: 26829 (cron)
Tasks: 1
Memory: 1.8M
CPU: 632ms
CGroup: /system.slice/cron.service
└─26829 /usr/sbin/cron -f
Nov 05 20:17:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27050]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Nov 05 20:17:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27049]: pam_unix(cron:session): session closed for user root
Nov 05 21:17:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27330]: pam_unix(cron:session): session opened for user root by (uid=0)
Nov 05 21:17:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27331]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Nov 05 21:17:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27330]: pam_unix(cron:session): session closed for user root
Nov 05 21:28:01 ubuntu-s-1vcpu-1gb-nyc1-01 cron[26829]: (root) RELOAD (crontabs/root)
Nov 05 21:32:01 ubuntu-s-1vcpu-1gb-nyc1-01 cron[26829]: (root) RELOAD (crontabs/root)
Nov 05 21:32:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27430]: pam_unix(cron:session): session opened for user root by (uid=0)
Nov 05 21:32:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27431]: (root) CMD (cd /root/InstaPy && python3.5 /root/InstaPy/quickstart.py >> /root/InstaPy/cronlog.log 2>&1)
Nov 05 21:32:01 ubuntu-s-1vcpu-1gb-nyc1-01 CRON[27430]: pam_unix(cron:session): session closed for user root```
still not sure how to read the logs..
Am I checking the cronlog correctly? when I try to check using /root/InstaPy/cronlog.log it says permission denied.
```root@ubuntu-s-1vcpu-1gb-nyc1-01:~/InstaPy# /root/InstaPy/cronlog.log
-bash: /root/InstaPy/cronlog.log: Permission denied
it requires root permission. use sudo before the command
where does sudo go?
For the cronlog?
root@ubuntu-s-1vcpu-1gb-nyc1-01:~/InstaPy# sudo /root/InstaPy/cronlog.log
sudo: /root/InstaPy/cronlog.log: command not found
root@ubuntu-s-1vcpu-1gb-nyc1-01:~/InstaPy# sudo cronlog.log
sudo: cronlog.log: command not found
Or does the crontab need a sudo somewhere?
sudo: /root/InstaPy/cronlog.log: command not found root@ubuntu-s-1vcpu-1gb-nyc1-01:~/InstaPy# sudo cronlog.log sudo: cronlog.log: command not found
sudo vim /root/InstaPy/cronlog.log
Thank you @converge you've been very helpful.
I'm having the same issues that these guys seem to be having on windows - https://github.com/timgrossmann/InstaPy/issues/3270
```Traceback (most recent call last):
File "/root/InstaPy/quickstart.py", line 7, in
from instapy import InstaPy
File "/root/InstaPy/instapy/__init__.py", line 2, in
from .instapy import InstaPy
File "/root/InstaPy/instapy/instapy.py", line 23, in
from .clarifai_util import check_image
File "/root/InstaPy/instapy/clarifai_util.py", line 4, in
from clarifai.rest import Workflow
ImportError: cannot import name 'Workflow'
@SeanFmcdonnell my pleasure.
does it work if you run python quickstart.py ?
if yes:
python --versionFinally got it going, thank you! I reinstalled InstaPy and changed my crontab to:
43 * * * * cd /root/InstaPy && python3 /root/InstaPy/quickstart.py >> /root/InstaPy/cronlog.log 2>&1
I'm going crazy on this.
Added a cronjob but get this log no matter what I do:
Traceback (most recent call last):
File "/home/pi/InstaPy/quickstart.py", line 20, in <module>
from instapy import InstaPy
ImportError: No module named 'instapy'
I get the same error when starting up with python2.7 so I assume cron somehow uses the wrong version.
using /usr/bin/python3 also doesn't help inside cron.
Anybody got an idea?
I want to start the script in the morning and end it at night to simulate human behaviour. Do I actually need to do this or is it fine running 24/7?
I have the following in place:
session.set_quota_supervisor(enabled=True,
sleep_after=["likes", "follows"],
sleepyhead=True, stochastic_flow=True,
notify_me=True,
peak_likes=(100, 1000),
peak_comments=(21, 250),
peak_follows=(200, None))
You must specify full path to the python executable that you want to use for cron.
Sent from my iPhone
On 19 Mar 2019, at 14:47, Gabor Wraight notifications@github.com wrote:
I'm going crazy on this.
Added a cronjob but get this log no matter what I do:
Traceback (most recent call last): File "/home/pi/InstaPy/quickstartGaborWraight.py", line 20, infrom instapy import InstaPy ImportError: No module named 'instapy' I get the same error when starting up with python2.7 so I assume cron somehow uses the wrong version.
using /usr/bin/python3 also doesn't help inside cron.
Anybody got an idea?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
You must specify full path to the python executable that you want to use for cron.
Thanks, but isn't that what I'm doing here:
using /usr/bin/python3 also doesn't help inside cron.
this worked for me 45 */4 * * * cd /root/instapy-quickstart && /usr/bin/python3 ./quickstart.py
My cronjob looks like this 0 */4 * * * cd /home/pi/InstaPy && /usr/bin/python3 ./quickstart.py >> /home/pi/Desktop/log.txt 2>&1
When it runs, it outputs the following
Traceback (most recent call last):
File "/home/pi/InstaPy/quickstart.py", line 1, in <module>
from instapy import InstaPy
ImportError: No module named 'instapy'
But when I run python3 quickstart.py or cd /home/pi/InstaPy && /usr/bin/python3 ./quickstart.py directly into the terminal, it starts the file and the session starts and things work normallly
I use
cd /home/pi/InstaPy && /usr/bin/python3 ./quickstart.py
make sure to run the cronjob as the user and not as root
So crontab -eand not sudo crontab -e
I use
cd /home/pi/InstaPy && /usr/bin/python3 ./quickstart.pymake sure to run the cronjob as the user and not as root
Socrontab -eand notsudo crontab -e
That was the issues. I was running it as sudo crontab -e
Thanks mate!
I'm just not getting it...
Is there a video... showing step by step?
Thanks in advance.
Should something happen on screen? I get nothing. I've tried all sorts of combinations.
Could really use a step by step instruction video.
Using Kubuntu 20.04
Most helpful comment
Finally got it going, thank you! I reinstalled InstaPy and changed my crontab to:
43 * * * * cd /root/InstaPy && python3 /root/InstaPy/quickstart.py >> /root/InstaPy/cronlog.log 2>&1