Script not working when called by cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not working when called by cron
# 1  
Old 02-18-2009
Script not working when called by cron

Hello,

I have the following script which works fine when ran from the command line:
Code:
#!/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:
Code:
    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.
# 2  
Old 02-18-2009
try "LOGNAME" instead of "USER"
# 3  
Old 02-18-2009
probably no good....

maybe just break out these commands into 2:

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

Code:
string = time.strftime("%m%d%y0000 ", time.gmtime())

string += user

And hopefully see which statement is giving the problem
# 4  
Old 02-18-2009
Thanks.
# 5  
Old 02-18-2009
This works:
Code:
#!/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())

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

2. Shell Programming and Scripting

Shell script not getting called through cron job but executes fine manually.

Hi, My shell script not getting called through cron job. The same works fine when executed manually. I tried to generate logs to find if the scripts has some errors related to path using following command- trying to execute .sh file every 5 mins: */5 * * * * /home/myfolder/abc.sh... (17 Replies)
Discussion started by: Dejavu20
17 Replies

3. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

4. UNIX for Dummies Questions & Answers

Interpreting Shell Script errors when called from CRON

Hi All, I am calling a series of shell scripts via CRON so everything is running as root. However, in my error log file I am seeing the following errors. Please can anyone offer any advise as to the possible causes and solution to prevent the errors from appearing. The Error 1227 seems to... (2 Replies)
Discussion started by: daveu7
2 Replies

5. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

6. Shell Programming and Scripting

Shell script not working in cron

Hello, I know little about shell scripting and creating a script, and worked fine in the command line. But not work in the cron. Below you could see the script #!/bin/sh LOGFILE=/home/transfield/mou/test.log # Find yesterday Date and copy files TODAY=$(date --date= +%F) YESTERDAY=$(date... (4 Replies)
Discussion started by: malikp
4 Replies

7. Shell Programming and Scripting

script not working in CRON

guys i have written a very simple script .it runs manually well. but when i put it in cron,it doesn't give the desired output. script looks like this: #! /usr/bin/sh #script for loading data in table using ctl file/Abhijeet K/08.07.2006 /svm_wl1/. .profile cd... (5 Replies)
Discussion started by: abhijeetkul
5 Replies

8. Shell Programming and Scripting

How to determine if a script (perl) was called from a CRON job or commandline

Hi, Is there a way to determine if a Script is called from a CRON job or from a commandline Gerry. (2 Replies)
Discussion started by: jerryMcguire
2 Replies

9. Shell Programming and Scripting

How to determine the script is called from CRON?

Hello expert, What I want is to determine whether the script is called from CRON or it is executed interactively? I tried the following but no luck: #!/bin/ksh cronID=`pgrep -x cron` GPID=`ps -ef -o ppid,pid | grep " $PPID$" | awk '{print $1}'` if ; then echo I am being run... (15 Replies)
Discussion started by: wes_brooks
15 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question