Score:0

cron job script not executing terminus command

us flag

I'm new to cron jobs implementation. On my local, I have setup crontab on kubuntu system, but when the cronjob executed, it do not execute terminus commands inside it. When I run terminus commands directly from terminal with sudo, it is getting executed successfully, but not from cronjob shell script.

$ whoami
$ aamir
$ which terminus
$ /usr/local/bin/terminus

test2.sh

#!/bin/sh

sudo terminus auth:login --machine-token=xxxxxxx
sudo terminus command here

crontab entry As root user

$ sudo crontab -u root -e
07 15 24 * * /var/www/html/test2.sh > /dev/null 2>&1

In logs I can see this crontab entry is getting executed, but terminus command inside the script does not execute. I guess it is not getting the correct path for terminus. Any help is much appreciated.

codlord avatar
ru flag
Instead of redirecting output to /dev/null why don't you re-direct output to a log file so then you can see for yourself exactly what your script is doing and what errors you are getting. For example: `07 15 24 * * /var/www/html/test2.sh >> /path/to/my/logfile.log 2>&1`
Aamir avatar
us flag
@codlord I tried it. logfile is empty after executing cronjob.
codlord avatar
ru flag
I don't know anything about `terminus` but my suggestions would be you add some `echo` outputs to your script before each command so you can be sure what lines the script is getting to and also try specifying absolute path `/usr/local/bin/terminus` not just `terminus`.
FedKad avatar
cn flag
Remove the two `sudo`s from your script.
Score:0
cn flag
  • Never run graphical applications, in this case terminal emulator terminus as root. Terminus is an end user application. Launch it only *as a user for a user.
  • Never use crontabs to launch a terminal emulator or any other graphical end user application, leave alone the crotab of root. If you want to auto launch a terminal emulator, in this case terminus, put it in the Startup Applications of each user that wished to have it loaded during startup.
  • Never use sudo in a script. If needed for system administrative tasks, run the entire script with root privileges.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.