Strange error on mpack from cronjob

I have a shell script which mails a file. It runs fine when executed at prompt, but from cronjob the following line gives an error:

$ /opt/local/bin/mpack -s "TTW posts " $FILEPATH/ttw.html myemail@gmail.com

Error is : (some junk chars) followed by No such file or directory.

Before this line ,I have `head`ed the file to ensure it is found by cron - IT IS. I have also `which`ed mpack and it (cron) gives the full path. So I am stumped as to why it should fail from cron. Both file and executable are found!

Strangely, after this I also 'links -dump' the file and use mail to mail it to my localhost. Links is also in /opt/local and this line works fine. However, since the stock 'mail' program cannot send an attach, therefore I needed to use mpack.

Doing 'ls -l' on mpack shows it is readable and executable by all -- same as other commands in /opt.

If $FILEPATH is not known in cron env you could make it use a default with "${FILEPATH:=/some/dir}/ttw.html".

The issue is not with filepath. Since in the previous line I am doing a head on the file, and the file is read fine. (Earlier I hardcoded the filepath)

Cron is finding mpack, and it is finding the file.

I even did things like putting the email id in quotes just incase /bin/sh is griping on the @. However, if that were the case, then it would not work when I put in my own python email script. The same cron is able to send the file through my script. (However, the way mpack encodes is different from the way my python script does, so i want to use mpack).

My apologies, haven't read to closely apparently. 'mpack' by default uses /usr/tmp as its TMPDIR. If /usr/tmp is not symlinked to /tmp or /var/tmp, then if it is not writable for that process it could result in such an error. I won't reproduce it that way, but 'export TMPDIR=/nonexistent_directoryname/' should result in the same. If it's not that you could strace the process for clues.

If you get 'file not found' in cron and you don't get that error from the command line you have an environment problem. Period - there is no other reasonable explanation, assuming you don't have relative paths in your script That is what you need to explore first.

Do this with either set or env at the command line:

set > /home/mydir/env1.log

add this line to your cron job

set > /home/mydir/env2.log

When you have both files, try a diff on them. You may have to source both /etc/profile and your .bashrc to get the code to run in cron.

AAH ! Tried that and it worked. I checked 'man mpack' and it confirmed the dependence on TMPDIR which defaults to /usr/tmp. I do not have such a directory.

So in my script i just put TMPDIR=/Users/my/tmp, and mpack worked!

Grr! I can't understand why mpack could not have said "/usr/tmp not found", or pls set TMPDIR. So many hours wasted.

Thanks a lot "unspawn". You need to start spawning some more unix gurus :slight_smile: