Cron-Noob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron-Noob
# 8  
Old 08-22-2012
to see your environment set just type env
# 9  
Old 08-22-2012
Yes, write a simple one-off cron containing something like
Code:
env > /tmp/cronenv.txt

It can be most revealing to find out how basic the environment is when running from cron. It is extremely unlikely that the default $PATH will know about Perl (... unless you have changed it). The normal fix is to write a Shell script which sets up (and exports) the Environment Variables you need and then runs the Perl script.

If you cron is failing for a fundamental reason the error messages will be in unix mail for the owner of the cron.


To answer in any further detail, please post what Operating System and version you are running and what Shell you use for system scripts. You need to post this basic information in every thread.
This User Gave Thanks to methyl For This Post:
# 10  
Old 08-23-2012
Ok so I found system.env and I see in there:
Code:
PATH=/bin:/sbin:/usr/sbin:/usr/ccs/bin

Should I update this to read:
Code:
PATH=/bin:/sbin:/usr/sbin:/usr/ccs/bin:/usr/bin

EDIT: Oh never mind. I typed env instead and it looks like /usr/bin is already defined.

Last edited by Jaymoney; 08-23-2012 at 05:27 AM..
# 11  
Old 08-23-2012
But there may be more you need, so do what methyl suggested and compare with your env...
This User Gave Thanks to vbe For This Post:
# 12  
Old 08-23-2012
Sorry guys I am slowly starting to understand what I need to do. I basically need to make cron do the env command and stick the result in a file so I can see what environment variables IT deals with when it runs.

Ok that done and the result is:
Code:
HOME=/home/seitjn
LOGNAME=seitjn
PATH=/usr/bin:
SHELL=/usr/bin/sh
TZ=Eire

---------- Post updated at 04:03 PM ---------- Previous update was at 09:42 AM ----------

UPDATE:

The problem is actually that the following script WILL run using crontab
Code:
#!/usr/bin/perl

my $username = "jaymoney";
print "$username\n";

The following script will NOT run using crontab (or rather it will run but it won't get the user name...)
Code:
#!/usr/bin/perl

my $username = `whoami`;
print "$username\n";

The difference here being the use of the Unix command to get the user's ID rather than hard coding it.
Anyone have any insight into this?

I'm on SunOS 5.10 if that means anything to anyone :P

Thanks!
# 13  
Old 08-23-2012
Now you are starting to understand...
the command whoami and similar are using things that are initialized at logging time but cron ignores all about that since it is not associated to a terminal to start with...
Did you compare the output of env using cron, and typing in your interactive shell?
# 14  
Old 08-23-2012
Yeah the difference is a lot Smilie

From the cron
Code:
HOME=/home/seitjn
LOGNAME=seitjn
PATH=/usr/bin:
SHELL=/usr/bin/sh
TZ=Eire

From the terminal
Code:
PATH=/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/dt/bin:/opt/SUNWconn/bin:/opt/SUNWste/bin

It goes on even more than that..

So how do I change the evn stuff for cron?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Noob trying to improve

Hi everyone! This is my first post here, I hope that I will not already be violating any rule! I also would like to apologize in advance as my post will definitely be a noob post... please have patience and faith :rolleyes:! Now that I have set the ground rules :D:D, my objective is trying... (39 Replies)
Discussion started by: Ardzii
39 Replies

2. HP-UX

Anybody wants to help a complete Noob?

Hello there, first post here so go easy on me! :D I just aquired an old HP 9000 Dclass d220 server, all I know is that it's running HP-UX, and it appears to boot fine (I see the modules loading, etc..) Now, I have been an MS guy all my life (yeah I know, make fun of me), so I really have no... (9 Replies)
Discussion started by: Marvio
9 Replies

3. What is on Your Mind?

Noob and Guru

A long time ago, my computer crashed, at that time, I was using Windows98, but because I was a noob at computers, my friend recommended me apro to fix it for me.   He came, saw the computer, and asked if I had a backup/installation disk for Windows 98. I said no.   He thought about it for a... (1 Reply)
Discussion started by: vistastar
1 Replies

4. UNIX for Dummies Questions & Answers

I'm a noob at Lynx...

So... I'm using lynx on a Mac... I didn't know that the whole dang thing is in Terminal? I rarely use terminal. I can't even figure out how to start the thing up. I type in lynx into it and press enter... And the cursor just goes down. Nothing happens like the FAQ websites describe. I feel so... (6 Replies)
Discussion started by: yennster
6 Replies

5. SCO

SCO noob please help

hello, sco openserver R5 the following error and it fails to load. init: Command is respawning too rapidily id: vm "/home/bin/stvm.sh" init: Comand..etc id: c02"/etc/start/autostart" its trying to mount car diagnostic program in vmware, the program location is in "start" i think? i... (1 Reply)
Discussion started by: hgibbs8129
1 Replies

6. UNIX for Dummies Questions & Answers

Noob on Unix.

This may seem really easy to alot of you but i am a real noob on unix. I have been set the task to make a script which will answer a query. Basically I will have made files for people and i want to be able to search for a persons file and then select certain variables from the files. e.g... (7 Replies)
Discussion started by: bobtheb
7 Replies

7. Linux

noob help needed

i'm having trouble putting together a program :( any help would be much appreciated! Write a Shell Program to automate the process of collecting assignments from the directories of students of any specified class. The person running the program should be able to pass a parameter to the... (1 Reply)
Discussion started by: ace_face
1 Replies

8. Shell Programming and Scripting

Shell Noob

Hi all, I am trying to write a shell script that will move files from one directory to another, the only thing is I want to to check loads of different source directory and move the files to loads of different directories. I am totally new to shell scripts but not to UNIX (although I would... (16 Replies)
Discussion started by: Sax
16 Replies

9. UNIX for Dummies Questions & Answers

complete noob

Hi all, This is my first post. I am a complete noobie to the UNIX OS, I have an iMac G5 with the unix shell built in and am interested in learning how to use it to do things useful with it, but have no idea where to start. I have read over the basic commands but they haven't helped me much yet.... (3 Replies)
Discussion started by: avdrummerboy
3 Replies

10. UNIX for Dummies Questions & Answers

I am a unix noob

Hello i am new to this forum. I signed up here really to ask one question. I recentaly got a old unix server from my work and i never really understood what unix is or what is does. Dont get me wrong i and very smart with computers as long as its windows, mac, or linux i can use them all but i... (4 Replies)
Discussion started by: alt+f4
4 Replies
Login or Register to Ask a Question