I have had two scripts running via crontab for a while now. Suddenly, it stopped working. This is on a RaspberryPi, and this is all it does, so I haven't installed new software, etc. (The only thing that updates is the sudo apt-get update and ... upgrade commands.
Here's my only crontab command:
...
# m h dom mon dow command
31 14 * * * python /mnt/ExternalDrive/FolderA/my_file.py
Nothing seems to happen. I don't believe the file runs. At 14:31, I ran pgrep -l python to see if python was running, and it doesn't return anything.
In my_file.py I have tried both shebangs, #!/usr/bin/python or #!/usr/bin/env python3.
When I do which python, I get: /usr/bin/python.
I have looked all over, and restarted crontab, etc. but it doesn't work. I've also set the permissions on the file, and installed postfix to no avail.
Running grep CRON /var/log/syslog and I see (CRON) info (No MTA installed, discarding output), but am not sure if that affects this.
I even deleted the crontab file, restarted the computer/Pi, and re-created one (sudo crontab -e).
Again, this was working fine before, but suddenly doesn't. Running the script from the terminal works fine (python /mnt/.../my_file.py)
Related
I am currently trying to get a cron job working, so that the google assistant starts automatically after boot. For that I created this cron job which executes on reboot.
SHELL=/bin/sh
PATH=/usr/bin:/bin:/home/pi/Desktop:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#Reboot lxterminal -t "Google Assistant" -e /bin/bash /home/pi/Desktop/init.sh
lxterminal will open a window with google assistant running within.
Here is my full cron job:
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/bin:/bin:/home/pi/Desktop:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
source /home/pi/env/bin/activate
python3 /home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc/pushtotalk.py
I already tried answers from similar problems and even specified the path variable for cron, but it still won't work for me. The script isn't the fault, when I execute it manually it runs fine.
The problem wasn't with cron, though I settled for using a systemd service instead.
What I didn't know was, that Lxterminal needed a initalized screen to work and due to the script running on boot it wasn't.
This is an easy fix. Either add an delay of 30 Seconds or other values, depending on your system, to the beginning of your script or simulate the display beeing initalized already with export DISPLAY=:1
I am not able to run reboot commands on my CentOS 7 machine.
For example I've created a script: /home/usr/myscript.sh (marked executable) with:
echo "hello world" > example.txt
When Im trying to run the script from terminal everything works good.
I tried to start the script on reboot at the end of the file:
nano /etc/crontab
I added:
#reboot /home/usr/myscript.sh
and on restart, nothing happen.
I also tried to edit file:
crontab -e
its looks like a new generated file, I've typed my command, and again nothing happend.
How can I run a command on CentOS at reboot?
I tried to insert that command on my Ubuntu machine, and everything was good and worked properly.
Anyone can advise on different way (maybe 3rd party program) that will help me to manage the reboot jobs?
Thanks for the help.
BTW, its might be duplicate, but I cant find any answer that helped me
In CentOS/RHEL 7, the systemctl utility replaces some older power management commands used in previous versions. The table below compares the older and new equivalent systemctl commands. The old commands listed in the table still exist for compatibility reasons.
Older Command systemctl equivalent Description
halt systemctl halt Halts the system
poweroff systemctl poweroff Powers off the system
reboot systemctl reboot Restarts the system
pm-suspend systemctl suspend Suspends the system
pm-hibernate systemctl hibernate Hibernates the system
pm-suspend-hybrid systemctl hybrid-sleep Hibernates and suspends the system
I was able to reach this out by adding a crontab file for my user.
with the following command:
crontab -u usrname filename
That allow me to run my scripts.
Thanks !
I have a python3 program that I run without any problems on a headless raspberry pi configuration where I connect using ssh. I logon to my pi, start a tmux session, and run the program. It will run indefinitely. During development when an exception would occur I the python program would terminate and I would see the error info.
Now if my pi were to reboot while I wasn't around I would want it to run this program automatically. I implemented the following steps to make this happen:
I created a script which contains this line:
tmux new-session -d -s xbnw 'python3 /home/pi/python/XbNWSer05.py'
Then I modified /etc/rc.local to include this line:
sudo -u pi bash /home/pi/tmux_xbnw.sh
Now when I reboot my pi everything works for a few minutes. The program is clearly running. I can logon and attach to the session and see my debug output and everything looks fine.
After a few minutes though something goes wrong and if I'm logged on and connected to the tmux session I suddenly find myself at a command prompt as though the program never ran. Also the tmux session is no longer active. There's no indication what happened.
1) Am I starting my program improperly?
2) If so is there a way to figure out what happened?
Add a logfile, either hacky by hand or with the logger module. Then you can find out if the programm started and you can log every minute or so to see when it dies and what was the last state.
You can also check the syslog whether there was a reboot. I had a bad power supply cable which made my Pi reboot in past...
I wanted to run a python script at boot in Ubuntu.
I tried referring to few existing solutions in stackoverflow but somehow I don't get it working.
Could anyone advise me on what piece of info I am missing!
Reference 1
Run Python script at startup in Ubuntu answered by #RickyA
Put this in /etc/init (Use /etc/systemd in Ubuntu 15.x)
mystartupscript.conf
start on runlevel [2345]
stop on runlevel [!2345]
exec /path/to/script.py
By placing this conf file there you hook into ubuntu's upstart service that runs services on startup.
manual starting/ stopping is done with sudo service mystartupscript start and sudo service mystartupscript stop
Results for Reference 1
In my case, the python script that I wanted to run on boot is located in /home/aspma/Dropbox/Linux/c_lynda_program_backup_script.py
When I tried to manually start the service from terminal window, i got an error message: start Job failed to start
Screenshot of mystartupscipt.conf file that i added inside /etc/init and its failed attempt for manual starting the service
Reference 2
How To Start Python Script On Bootup answered by #Germar
You can add it to /etc/rc.local. This can be used to run scripts and programs on system boot which doesn't have their own scripts for runlevels. It will run as root
Run sudo nano /etc/rc.local and add your line before exit 0
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
python /home/my-sickbeard-install/SickBeard.py 2>&1 >/dev/null &
exit 0
Results for Reference 2
In my case, the python script that I wanted to run on boot is located in /home/aspma/Dropbox/Linux/c_lynda_program_backup_script.py
Screeenshot of file that is edited in /etc/rc.local
This doesn't work too
Virtual Machine Details
Ubuntu Version 14.04.5 LTS
Python 2.7.6
I managed to get the python script run automatically at the boot, by adding one more step to the solution given in Reference 2 (see the question).
By adding the directory of the python script to PYTHONPATH, I was able to get it working.
To add the directory permanently to the PYTHON PATH, add this to your ~/.bashrc
export PYTHONPATH=$PYTHONPATH:/my/other/folder_containing_python_script
Thanks to the post: Permanently add a directory to PYTHONPATH
IM running a VPS server on Ubuntu 14.04 minimal x86. I connect to it using putty via SSH.
On the server i have a simple script that is starting a few instances of bots
nohup node /nodebots/bot10/server.js &
I use root as a user, so all the privileges and +chmod X are set properly (in my opinion)
The idea is that my node.js program is not excelent + the service im running the bots for sometimes has reboots, server crashes etc.
Ive installed crontab and at this moment struggling to set the script to be run at boot.
Ive used various solutions including trying to boot it via init.d , adding a line to rc.local and well using crontab -e. None of it helps.
Currently the code in crontab looked the following ways
`#reboot sh /nodebots/botsrun.sh`
#reboot root /nodebots/sh botsrun.sh
#reboot cd /nodebots/ && sh botsrun.sh
None of it helped.
Im new to Ubuntu, coding and even terminal commands. I would really apreaciate any kind of help. I will be more then grateful for a step by step tutorial on what im doing wrong and what should be done.