Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I wanna read the date from input text file (last_intf_date.txt
)
. /etc/profilewhile 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 nullwhat 's wrong with this script when running on crontab
Thank u in advance

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_dateNotes:
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

![]() |
![]() |
![]() |

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