Computing.Net > Forums > Unix > read variable with crontab problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

read variable with crontab problem

Reply to Message Icon

Name: chokchai
Date: September 9, 2005 at 01:27:35 Pacific
OS: unix
CPU/Ram: NA
Comment:

I wanna read the date from input text file (last_intf_date.txt
)


. /etc/profile

while read whole_line
do
ds_date=`echo $whole_line | cut -c1-8`
done < last_intf_date.txt
echo $ds_date


when i run shell script by myself $ds_date return the date value i want ,but when it's runned by crontab ,$ds_date return null

what 's wrong with this script when running on crontab

Thank u in advance



Sponsored Link
Ads by Google

Response Number 1
Name: Luke Chi
Date: September 9, 2005 at 07:08:25 Pacific
Reply:

1. You may make your program simpler:

cut -c1-8 last_intf_date.txt

2. $ds_date returns null, because while creates a subshell to run the statements in the while block. The value of $ds_date is not returned.

3. Try:

#!/bin/ksh <=== add this line

. /etc/profile

while read whole_line
do
ds_date=`echo $whole_line | cut -c1-8`
done < last_intf_date.txt
echo $ds_date

Notes:

sh and ksh handle "while subshell" differently on Solaris - sh creates a subshell and ksh still runs it in the same shell.

My Redhat Linux creates a subshell for both of sh and ksh.

My HP-Unix runs it in the same shell for both of sh and ksh.


Luke Chi


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: read variable with crontab problem

grep variable with blank space www.computing.net/answers/unix/grep-variable-with-blank-space/5469.html

Read email with attachment www.computing.net/answers/unix/read-email-with-attachment/7887.html

crontab problem www.computing.net/answers/unix/crontab-problem-/7597.html