Autorun C++ exe with crontab on boot - cron

I have created crontab file using the following command.
crontab -e
Then in crontab file
#reboot sleep 120 && /home/xavier/run.sh
run.sh file has
#crontab -e
SHELL=/bin/bash
PATH=/bin:/sbin/:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
cd /opt/nvidia/deepstream/deepstream-6.0/sources/apps/sample_apps/deepstream-app
./deepstream-app -c ../../../../samples/configs/deepstream-app/stluke_1080p_dec_infer-resnet_tracker_sgie_tiled_display_int8_record.txt
deepstream-app program runs after two minutes. But it stops. I can see in systemmonitor.
I'm not sure passing arguments to deepstream-app is correct.
On terminal, the following two commands are used to run c++ exe file.
cd /opt/nvidia/deepstream/deepstream-6.0/sources/apps/sample_apps/deepstream-app
./deepstream-app -c ../../../../samples/configs/deepstream-app/stluke_1080p_dec_infer-resnet_tracker_sgie_tiled_display_int8_record.txt
So I run exactly in shell file.
What could be wrong?

Related

Restart Opencanary from Crontab

I have a programm called opencanary running at a virtual environment at my Raspberry Pi with Ubuntu 18.04 installed. I want to restart it every 30 Minutes using crontab. For testing I set the script to run every 3 Minutes as you can see below.
When I execute the script manually it's working fine. When using crontab to run it it doesn't and I can't find out why it fails.
This is what my script looks like:
#!/bin/bash
SHELL=/bin/sh
. /home/pi/.bashrc
source /home/pi/canary-env/bin/activate && cd opencanary && opencanaryd --restart
After creating the script I added it to crontab -e:
*/3 * * * * /home/pi/restartOC.sh>>test.log
When I look at the cron.log file I can see that the script is executed:
Sep 29 08:33:01 DiskStation CRON[20880]: (pi) CMD (cd /home/pi && sh restartOC.sh>>test.log)
the test.log file stays empty.
Does someone know what I am doing wrong?
Edit 05.10.2021
At the github of opencanary I was told that I don't have to use the 'cd opencanary'. I followed the advice and edited my script:
#!/bin/bash
SHELL=/bin/sh
. /home/pi/.bashrc
source /home/pi/canary-env/bin/activate && opencanaryd --restart
The script is still working when executed manual but The Problem does still exist when running the script from cron.
I solved the problem by calling 'which opencanaryd' at the terminal
this will return the path where the opencanaryd command is located.
In my case it is /usr/local/bin/opencanaryd
With this knowledge it is possible to edit the script so cron can find the command:
#!/bin/bash
SHELL=/bin/sh
. /home/pi/.bashrc
cd /usr/local/bin/ && . opencanaryd --restart

Crontab won't execute shell script

I tried to configure crontab to execute a shell script every day.
When executed manually, the file works well. Unfortunately, crontab won't execute it.
Here's my shell file:
#! bin/bash
# GENERAL properties
BASE_DIR=/opt/XXX-1.0
# JOB properties
JOBS_DIR=$BASE_DIR/jobs
#find all main etl jobs and execute them
cd $JOBS_DIR
find . -name '*mainrun.sh' -exec {} \;
And here's my crontab
10 14 * * * /bin/sh /opt/XXX-1.0/jobs/jobs.sh
Any ideas on what could be preventing me from executing it?
Thank you.
I haven't seen a /bin/sh in a crontab like that.
Why aren't you using a shebang at the start of your file like so:
#!/usr/bin/env bash
Is the file itself executable for the crontab user that is executing it?
chmod +x /opt/XXX-1.0/jobs/jobs.sh

Root Crontab say command not found in bash script

Currently I am writing a little script which should add a cronjob to the root crontable. But it seems that my root crontable stopped working. When I try to run the crontab commands in my bash scrip, I get "command not found". Also it worked for some time and stopped working yesterday. Now when I enter "sudo crontab -l" I don't get "no crontab for root" anymore. I am not sure what I did wrong. Here is my code:
#!/bin/bash
sudo crontab -l > rootcron 2> /dev/null
sudo echo "test" >> rootcron
sudo crontab rootcron
sudo rm rootcron
You didn't specify when the command is to be run. Typically you would see something like:
*/5 * * * * touch /tmp/test-cron
So basically you probably have an invalid cron file. What are the contents of the file now?

Scrapyd not starting at boot-up - Ubuntu 14

I have Scrapyd installed on server.
I want it to start whenever my server restarts.
I created job here /etc/init/myjob.conf with following contents
description "my job"
start on startup
task
cd /var/www/scrapers && scrapyd >& /dev/null &
I also tried to put following command in crontab -e
#reboot cd /var/www/scrapers && scrapyd >& /dev/null &
Both of them did not work.
I checked cronlogs using grep CRON /var/log/syslog and here I see command ran but Scrapyd did not start
Mar 30 13:33:28 mani CRON[446]: (root) CMD (cd /var/www/scrapers && scrapyd >& /dev/null &)
As you can see that command ran as ROOT user.
If I manually run that command in terminal it works!
PS:
I changed command to
#reboot cd /var/www/scrapers && scrapyd >> /var/www/log.txt
and log file is created but its empty!
You must try to start process manually, and see what happens. The line:
cd /var/www/scrapers && scrapyd
makes sense if: 1) directory /var/www/scrapers do exist 2) scrapyd is a binary that exists in that directory, and PATH environment variable includes actual directory ("." wildcard).
Maybe you could try:
cd /var/www/scrapers && ./scrapyd
without redirect standar output to /dev/null, to see what happens. Always try manual before use cron.
I could not get my scrapyd start through /etc/rc.local or crontab so I found a work around. I am sure there will be a better way but for mean time this worked for me.
I created a python file start.py.
import os
os.system('/usr/bin/python3 /home/ubuntu/.local/bin/scrapyd > /home/ubuntu/scrapy.log &')
And simply call the python file start.py through crontab.
Add this to crintab file by cronat -e.
#reboot /usr/bin/python3 /home/ubuntu/start.py
Basically what I did is execute the scrapy through shell by calling the python filr through crontab.

Crontab suppressing rsync logfile output

I have a shell script being executed by my cron tab that runs a couple rsync commands. When I run it from command line it writes the log file as expected but when run by the cron I don't get the log file.
Here is what I'm running.
rsync --log-file=noon_file_backup.log -urv -e ssh /var/www/html/ root#192.168.10.3:/var/devbackups/noon

Resources