LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 11-01-2019, 12:24 PM   #1
djk44883
Member
 
Registered: Aug 2008
Location: Ohio
Distribution: debian
Posts: 141

Rep: Reputation: 29
works from command line - not from cron


I have a shell script to export shows from my DVR. Seems to work when from from the command line. I create a job in /etc/cron.d and it runs... but misses shows with apostrophe. Note: I run the job as "me" I am added to crontab group.

snip from cron email:
Code:
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <MAILTO=dj>
X-Cron-Env: <HOME=/home/dj>
X-Cron-Env: <LOGNAME=dj>
notorious lines as reported in the cron email report, note script has set -x
Code:
+ export_namechange wrapto1 'The People'\''s Court' PeoplesCourt /media/dvr
+ wrapto1 --name 'The People'\''s Court' --filename 'PeoplesCourt - s%se%e.mp4' --get --all --capto-args '-p /media/dvr -a -q'
Finished 0 jobs in 0 sec: 0 files transferred OK, 0 files failed.
The 2nd and 3rd lines are actually from another script named export_namechange. It passes which device 1 or 2 the name of the show new name and path. Line as it appears in TabloDaily
Code:
exportnamechange 1 "The People's Court" PeoplesCourt /media/dvr
I have the entire name double quoted, and it escapes the ' as I guess it does. So I try "The People\'s Court" and "The People"\'s" Court" and then I just get 2 back slashes or even more single quote around it all to keep the backslash. -wtf

Now the real screwy part... From the command line

Code:
+ export_namechange wrapto1 'The People'\''s Court' PeoplesCourt /media/dvr
+ wrapto1 --name 'The People'\''s Court' --filename 'PeoplesCourt - s%se%e.mp4' --get --all --capto-args '-p /media/dvr -a -q'
Retrieving item '178906' via command 'capto1 -e 178906 -p /media/dvr -a -q -f "PeoplesCourt - s23e35.mp4"'
Retrieved '178906' OK
Finished 1 job in 239 sec: 1 file transferred OK, 0 files failed.
It passes things on with the messed up escaping still, but what ever is going on differently it catches the show and exports it. Now what's different about running from cron? It's not the explicitly added '\' which I can't seem to get rid of. I try to escape it from inside the double quotes, seems to still want to make it literal.

/etc/cron.d/TabloDaily
Code:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=dj
#
59 23 * * * dj /usr/local/sbin/TabloDaily
Again, the report shows it's run and loged on as me [dj] with my home environment, but .bashrc exits if not interactive - no shopt other than histappend and checkwinsize any ways.

All scripts start with
Code:
#!/bin/bash
set -x
 
Old 11-01-2019, 12:44 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
the quotation does not change (cannot be changed) depending on the invocation, so that should be something else.
For example cron uses sh instead of bash. Cron may use different path (or environment) settings, that may cause also strange behavior.
Also .bashrc is not in use when you use cron, so I just don't understand your comment related to .bashrc.
 
Old 11-01-2019, 01:27 PM   #3
djk44883
Member
 
Registered: Aug 2008
Location: Ohio
Distribution: debian
Posts: 141

Original Poster
Rep: Reputation: 29
Quote:
Originally Posted by pan64 View Post
the quotation does not change (cannot be changed) depending on the invocation, so that should be something else.
For example cron uses sh instead of bash. Cron may use different path (or environment) settings, that may cause also strange behavior.
But the cron job I posted has SHELL=/bin/bash and once the shell script starts, why wouldn't it respond to #!/bin/bash ?
Quote:
Originally Posted by pan64 View Post
Also .bashrc is not in use when you use cron, so I just don't understand your comment related to .bashrc.
as noted in the cron email report -
X-Cron-Env: <HOME=/home/dj>
X-Cron-Env: <LOGNAME=dj>

that's where .bashrc is and is read when I log in. .bashrc is not used at all for jobs run as root for certain, in the username column of cron I have my own username, not root.
 
Old 11-01-2019, 01:30 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
shebang is only honored when there was no interpreter specified (so when you execute for example: /bin/ksh <your script> it will be processed by ksh, not bash).
regarding bashrc please read man bash (and look for .bashrc)
 
Old 11-01-2019, 01:59 PM   #5
djk44883
Member
 
Registered: Aug 2008
Location: Ohio
Distribution: debian
Posts: 141

Original Poster
Rep: Reputation: 29
Quote:
Originally Posted by pan64 View Post
shebang is only honored when there was no interpreter specified (so when you execute for example: /bin/ksh <your script> it will be processed by ksh, not bash).
regarding bashrc please read man bash (and look for .bashrc)
my comment about .bashrc - it exits if not interactive -- I know it's not in play here.

To ensure there is not interpreter specified, even though as noted, my cron job says SHELL=/bin/bash I should launch it via exec
 
  


Reply



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
gawk works from command line but not from cron fantasygoat Linux - Server 3 10-25-2011 01:18 PM
Works from command line but not from the cron WingnutOne Linux - General 8 11-08-2007 08:18 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM
btdownload*.py, works from Command Line, not from cron SkipHuffman Linux - Software 11 12-30-2005 02:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 09:05 AM.

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