Re: Weird shell script behavior in a cron job

2017-09-01 Thread David Margerison
On 31 August 2017 at 04:32, James H. H. Lampert wrote: > > I added a line to echo $SHELL to my debugging log file, and > that was it: if I ran it from cron, $SHELL was /bin/sh; if I ran it from a > command line, $SHELL was /bin/bash. Be careful to correctly understand

Re: Weird shell script behavior in a cron job

2017-08-31 Thread James H. H. Lampert
On 8/31/17, 5:16 AM, Reco wrote: $ bash -c 'cd foo; echo $?' bash: line 0: cd: foo: No such file or directory 1 To this: $ dash -c 'cd foo; echo $?' dash: 1: cd: can't cd to foo 2 Aha! That's what it was! Thanks! At any rate, changing the test script's utterly nonspecific shebang (that, I

Re: Weird shell script behavior in a cron job

2017-08-31 Thread Reco
Hi. On Thu, Aug 31, 2017 at 08:03:51AM -0400, Greg Wooledge wrote: > On Thu, Aug 31, 2017 at 06:52:28AM +0100, Jonathan de Boyne Pollard wrote: > > James H. H. Lampert: > > > > > Could it be that |cron| is running it an entirely different shell, that > > > doesn't understand the |if|

Re: Weird shell script behavior in a cron job

2017-08-31 Thread Greg Wooledge
On Thu, Aug 31, 2017 at 06:52:28AM +0100, Jonathan de Boyne Pollard wrote: > James H. H. Lampert: > > > Could it be that |cron| is running it an entirely different shell, that > > doesn't understand the |if| statement? > > > Despite what others have said, the answer to this question is no.

Re: Weird shell script behavior in a cron job

2017-08-31 Thread Jonathan de Boyne Pollard
James H. H. Lampert: Could it be that |cron| is running it an entirely different shell, that doesn't understand the |if| statement? Despite what others have said, the answer to this question is no. Whilst you /are/ running two different shells, the problem is not the |if| statement. Both

Re: Weird shell script behavior in a cron job

2017-08-30 Thread Greg Wooledge
On Wed, Aug 30, 2017 at 09:32:37PM +0300, Reco wrote: > > > #! > > A curious shebang. > > Why would the behavior be any different? Could it be that cron is running it > > an entirely different shell, that doesn't understand the "if" statement? > > Presumably your script runs via /bin/bash in

Re: Weird shell script behavior in a cron job

2017-08-30 Thread David Wright
On Wed 30 Aug 2017 at 11:07:36 (-0700), James H. H. Lampert wrote: > Can somebody explain this: > > My backup script WILL detect that ExternalHD is not mounted, and > attempt to mount it, if I run it manually. > > But it WON'T do that if it runs in a cron job. > > I've isolated the relevant

Re: Weird shell script behavior in a cron job

2017-08-30 Thread James H. H. Lampert
A few minutes ago, with respect to my backup script attempting to mount ExternalHD if run from a command line, but not from cron, I wrote: Why would the behavior be any different? Could it be that cron is running it an entirely different shell, that doesn't understand the "if" statement? That

Re: Weird shell script behavior in a cron job

2017-08-30 Thread Reco
Hi. On Wed, Aug 30, 2017 at 11:07:36AM -0700, James H. H. Lampert wrote: > Can somebody explain this: > > My backup script WILL detect that ExternalHD is not mounted, and attempt to > mount it, if I run it manually. > > But it WON'T do that if it runs in a cron job. > > I've isolated

Weird shell script behavior in a cron job

2017-08-30 Thread James H. H. Lampert
Can somebody explain this: My backup script WILL detect that ExternalHD is not mounted, and attempt to mount it, if I run it manually. But it WON'T do that if it runs in a cron job. I've isolated the relevant code into its own script, added debugging output, and set it up to run every