This might be a bit OT, but I've never had to do this before and what I've googled doesn't seem to be working. I have an ansible playbook that I'm working on that I want to run as a cronjob.? One task I'm having trouble with is where I have a text file with lines like: rd.pl "blah blah" rd.pl "blah blah blah" This text file has to be 'executed' using 'bash filename.txt'. (Don't ask why, I'm working on code that isn't mine.) When I run the playbook in a console this bit works perfectly.? However, when it's being run from cron, it dies with 'rd.pl: command not found'.? My original thought is that cron's $PATH is missing the location to this rd.pl file (it's in /root/bin), so one suggestion from the Google was to add the path into /etc/crontab, but I'm still having the same problem.? At this stage, I've no idea what to try next.? Any ideas? For the record, this was the only option to handle the task I'm having issues with inside cron. -- Mark Haney Network Engineer at NeoNova 919-460-3330 option 1 mark.haney at neonova.net www.neonova.net
On Wed, 15 Nov 2017 11:29:50 -0500 Mark Haney wrote:> This text file has to be 'executed' using 'bash filename.txt'. (Don't > ask why, I'm working on code that isn't mine.)Try adding #!/bin/bash as the first line of the text file and then run it with just the filename. -- MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com
Mark Haney wrote:> This might be a bit OT, but I've never had to do this before and what > I've googled doesn't seem to be working. > > I have an ansible playbook that I'm working on that I want to run as a > cronjob.? One task I'm having trouble with is where I have a text file > with lines like: > > rd.pl "blah blah" > rd.pl "blah blah blah" > > This text file has to be 'executed' using 'bash filename.txt'. (Don't > ask why, I'm working on code that isn't mine.) When I run the playbook > in a console this bit works perfectly.? However, when it's being run > from cron, it dies with 'rd.pl: command not found'.? My original thought > is that cron's $PATH is missing the location to this rd.pl file (it's in > /root/bin), so one suggestion from the Google was to add the path into > /etc/crontab, but I'm still having the same problem.? At this stage, > I've no idea what to try next.? Any ideas? > > For the record, this was the only option to handle the task I'm having > issues with inside cron. >Yes. Do not trust your environment, running as a cron job, to be what you think it is. Try testing it by have your cron job, at the top of the script, issue the env command. mark
> On Nov 15, 2017, at 11:48 AM, m.roth at 5-cent.us wrote: > > Mark Haney wrote: >> This might be a bit OT, but I've never had to do this before and what >> I've googled doesn't seem to be working. >> >> I have an ansible playbook that I'm working on that I want to run as a >> cronjob. One task I'm having trouble with is where I have a text file >> with lines like: >> >> rd.pl "blah blah" >> rd.pl "blah blah blah" >> >> This text file has to be 'executed' using 'bash filename.txt'. (Don't >> ask why, I'm working on code that isn't mine.) When I run the playbook >> in a console this bit works perfectly. However, when it's being run >> from cron, it dies with 'rd.pl: command not found'. My original thought >> is that cron's $PATH is missing the location to this rd.pl file (it's in >> /root/bin), so one suggestion from the Google was to add the path into >> /etc/crontab, but I'm still having the same problem. At this stage, >> I've no idea what to try next. Any ideas? >> >> For the record, this was the only option to handle the task I'm having >> issues with inside cron. >> > Yes. Do not trust your environment, running as a cron job, to be what you > think it is. Try testing it by have your cron job, at the top of the > script, issue the env command.What about just giving the full path to the rd.pl script in the text file (i.e. /root/bin/rd.pl) ? Noam ____________ || |U.S. NAVAL| |_RESEARCH_| LABORATORY Noam Bernstein, Ph.D. Center for Materials Physics and Technology U.S. Naval Research Laboratory T +1 202 404 8628 F +1 202 404 7546 https://www.nrl.navy.mil <https://www.nrl.navy.mil/>
On Wed, 15 Nov 2017, Mark Haney wrote:> This might be a bit OT, but I've never had to do this before and what I've > googled doesn't seem to be working. > > I have an ansible playbook that I'm working on that I want to run as a > cronjob.? One task I'm having trouble with is where I have a text file with > lines like: > > rd.pl "blah blah" > rd.pl "blah blah blah" > > This text file has to be 'executed' using 'bash filename.txt'. (Don't ask > why, I'm working on code that isn't mine.) When I run the playbook in a > console this bit works perfectly.? However, when it's being run from cron, it > dies with 'rd.pl: command not found'.? My original thought is that cron's > $PATH is missing the location to this rd.pl file (it's in /root/bin), so one > suggestion from the Google was to add the path into /etc/crontab, but I'm > still having the same problem.? At this stage, I've no idea what to try > next.? Any ideas?In your crontab, try env PATH="$PATH:/root/bin" bash filename.txt -- Paul Heinlein heinlein at madboa.com 45?38' N, 122?6' W
On 11/15/2017 11:48 AM, m.roth at 5-cent.us wrote:> Mark Haney wrote: >> For the record, this was the only option to handle the task I'm having >> issues with inside cron. >> > Yes. Do not trust your environment, running as a cron job, to be what you > think it is. Try testing it by have your cron job, at the top of the > script, issue the env command. > > mark >I'm not sure I follow, where should the env command be placed?? At the front of the cron line? -- Mark Haney Network Engineer at NeoNova 919-460-3330 option 1 mark.haney at neonova.net www.neonova.net
On 11/15/2017 11:57 AM, Paul Heinlein wrote:> In your crontab, try > > ? env PATH="$PATH:/root/bin" bash filename.txt >Maybe I wasn't terribly clear, for which I apologize.? I'm not running the text file itself from cron.? I'm running an ansible playbook from cron, which, as one of its tasks runs 'bash filename.txt'.? It's possible I could try the command you recommend above in the task and see if that fixes it. However, I have another method that works in a similar fashion. I simply added BASH_ENV=$HOME/bash_profile to the top of my crontab, which has fixed the issue.? I could have sourced the profile on the cronjob line, but this is a bit clearer for other who might access the system. -- Mark Haney Network Engineer at NeoNova 919-460-3330 option 1 mark.haney at neonova.net www.neonova.net