Script not working when called by cron

Hello,

I have the following script which works fine when ran from the command line:

#!/apps/python/2.3.4/bin/python

import os
import sys
import time

user = os.getenv("USER")
string = time.strftime("%m%d%y0000 " + user, time.gmtime())

However, when I have this run by crontab, I get the following error:

    string = time.strftime("%m%d%y0000 " + user, time.gmtime())
TypeError: cannot concatenate 'str' and 'NoneType' objects

I think it's because os.getenv("USER") is not available. Is there a way to get the username?

Thanks.

try "LOGNAME" instead of "USER"

probably no good....

maybe just break out these commands into 2:

string = time.strftime("%m%d%y0000 " + user, time.gmtime())
string = time.strftime("%m%d%y0000 ", time.gmtime())

string += user

And hopefully see which statement is giving the problem

Thanks.

This works:

#!/apps/python/2.3.4/bin/python

import os
import sys
import time

user = os.getenv("LOGNAME").replace("LOGNAME=", "")
string = time.strftime("%m%d%y0000 " + user, time.gmtime())