How to get crontab execute commands on the default shell?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
How to get crontab execute commands on the default shell?
Ubuntu 14.04 LTS
The script is:
Code:
#!/bin/bash
roscore
Error log is:
Code:
roscore: not found
`crontab -l` says:
Code:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
SHELL=/bin/bash
@reboot cd /home/anisha/Desktop && sh mmanisha.sh >> p.log 2>&1
The thing is that when I run `roscore` directly on the terminal or I execute the script on the terminal, no errors are shown:
Code:
anisha@hrs-d-016:~$ echo $SHELL
/bin/bash
anisha@hrs-d-016:~$ roscore
... logging to /home/anisha/.ros/log/a6c6cee0-0220-11e7-bead-2c41388be92e/roslaunch-hrs-d-016-2807.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://hrs-d-016:34770/
ros_comm version 1.11.20
SUMMARY
========
PARAMETERS
* /rosdistro: indigo
* /rosversion: 1.11.20
NODES
auto-starting new master
process[master]: started with pid [2819]
ROS_MASTER_URI=http://hrs-d-016:11311/
setting /run_id to a6c6cee0-0220-11e7-bead-2c41388be92e
process[rosout-1]: started with pid [2832]
started core service [/rosout]
^C[rosout-1] killing on exit
[master] killing on exit
^Cshutting down processing monitor...
... shutting down processing monitor complete
done
Where is crontab executing these commands such that it isn't able to find roscore?
How to get crontab execute commands on the default shell?
Last edited by TheIndependentAquarius; 03-05-2017 at 11:13 PM.
The crontab env is minimal and does not include your personal env eg $PATH.
The usual rule (& you'll find this advice all over) is to specify the complete path to all cmds and files used.
The other alternative is to add some code to your script that sets up the relevant PATH etc so that the cmd can run as if you were physically logged in.
(NB: cron is a dis-connected process; that is to say it has no knowledge/cxn to the screen, so don't use cmds that talk to the scrn)
This time I added roscore path to the script: /opt/ros/indigo/bin/roscore
This resulted in:
Code:
Traceback (most recent call last):
File "/opt/ros/indigo/bin/roscore", line 36, in <module>
from rosmaster.master_api import NUM_WORKERS
ImportError: No module named rosmaster.master_api
It looks like you may need to add some env vars; try
Code:
set
# and/or
env
You get similar issue if you try to run some ORACLE tools without exporting various env vars first.
Basically you need really to know how that cmd works and its dependencies; shouldn't be too hard.
You could try sourcing your .bashrc and/or .bash_profile (just the relevant parts).
(NB: there may be something being set in /etc/profile & /etc/profile.d/... etc.
cat /etc/rc.local
#!/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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.