Variables in cron


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Variables in cron
# 1  
Old 08-05-2010
Variables in cron

I have a script where if I run it from console the host name is been picked properly whereas the same is not working in cron.
Please see the script below

Code:
host=$HOSTNAME
x=$host

Please advise.

Moderator's Comments:
Mod Comment Please use code tags, and modify your title to something more descriptive

Last edited by pludi; 08-05-2010 at 02:49 PM..
# 2  
Old 08-05-2010
Make sure you are using full path names for any commands you are running.

Also, where are you populating $HOSTNAME? your profile is not loaded when cron runs, unless you specifically call them to set your variables.
# 3  
Old 08-05-2010
Hi ,

Already I am calling profile to set variables. ANy LUCK??
# 4  
Old 08-05-2010
Assuming this is unix and you have the "hostname" command.
Check you "man" page for the "hostname" command first and do not give it any parameters or it will change the name of your host!

Code:
host=`/usr/bin/hostname`


You may find that your $HOSTNAME is set in /etc/profile . However do not execute /etc/profile from cron, just pick the lines you want and copy them into your own script.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Run script through cron with user environment variables

Hi everyone, I wrote a script that is supposed to be run by cron on a daily basis. It works just fine if I run it manually, but due to a lack of environment variables (which are available during my user session but not when cron runs the script) it keeps failing to run successfully. Here's the... (2 Replies)
Discussion started by: gacanepa
2 Replies

4. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

5. Solaris

Environment variables and cron

where do you set environment variables for cron jobs? I have a feeling it would ignore ~/.bashrc ? thanks. (2 Replies)
Discussion started by: orange47
2 Replies

6. Shell Programming and Scripting

Setting environment variables in Cron file

Hi, In Cron file i'm using username and password hard-coded and now i wann to use environmental veraiables in cron file. But Could you please guide me how to use these environmental variables in cron file ? Thanks, Shyamu.A (4 Replies)
Discussion started by: shyamu544
4 Replies

7. UNIX for Dummies Questions & Answers

Cron Job and Environement Variables

Hello all, One more Cron job Query!! Ok I have a cron job which calls a shell script.The shell scripts uses 11 parameters whose values are set up in a config file and this file is sourced using the . $custom_path/filename format in my shell script. Now the problem is the shell script... (8 Replies)
Discussion started by: valluvan
8 Replies

8. HP-UX

How to use own account env variables to cron user

hi all, i have one account for unix Tru64. i can login this account and i do execute special shell script(login sqlplus, execute another shell, etc... ) on this account on my server. but i can't run this shell from cron tab. i think that become cron user envirnoment variables. (3 Replies)
Discussion started by: Tlg13team
3 Replies

9. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies

10. Solaris

Setting environment variables within cron jobs!!

Is it possible to use environment variables within cron jobs. I am using a cron job to run a c program at regular intervals. The C program uses a library and i have set the library path in the LD_LIBRARY_PATH environment variable. But when i ran the job i got the error library not found!! Any... (1 Reply)
Discussion started by: atheek
1 Replies
Login or Register to Ask a Question