LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-05-2017, 10:10 PM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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 Aquarius_Girl; 03-05-2017 at 10:13 PM.
 
Old 03-05-2017, 10:48 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,391

Rep: Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774
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)
 
1 members found this post helpful.
Old 03-05-2017, 10:55 PM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
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
 
Old 03-05-2017, 11:02 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,391

Rep: Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774
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.
 
1 members found this post helpful.
Old 03-06-2017, 12:01 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Well, I just put the script path in
Quote:
/etc/rc.local
Quote:
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.

/home/anisha/Desktop/mmanisha.sh

exit 0
That worked.

This is the script:
Quote:
#!/bin/bash
source /opt/ros/indigo/setup.bash
roscore &
Thanks for your help though.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using ssh to execute dozens of shell commands in shell script hilou Programming 7 04-20-2016 04:25 AM
[SOLVED] shell shell to execute commands for pgrep linux833 Programming 11 09-06-2012 11:01 PM
rsync ssh - how to execute shell commands on server banjer Linux - Newbie 4 11-04-2009 02:01 PM
why won't my crontab execute the commands? dannemil Linux - Newbie 4 02-12-2008 05:25 PM
Shell won't execute commands.... frank320 Red Hat 6 03-17-2006 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration