0
votes

Below line of my bash script not write output of /tmp/DPE_SC/LoadUnits/ttx/bin/deasn9 -b -a cdrr6 $fnames to file $dst_dir"/"$fstat"-"$fnames".txt when I execute from crontab. It only creates empty file named $dst_dir"/"$fstat"-"$fnames".txt Sure it works properly from command line manually.

/tmp/DPE_SC/LoadUnits/ttx/bin/deasn9 -b -a cdrr6 $fnames > $dst_dir/$fstat-$fnames.txt

What is my mistake?

This is my whole script

#!/bin/bash

export PATH=/tmp/DPE_SC/LoadUnits/ttx/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/tmp/DPE_SC/Tools:/usr/X11R6/bin

src_dir=/charging/chsLog/ready

dst_dir=/Core/cdr

cd $src_dir

lastfile=cat $dst_dir/last_cdr.txt

filenames=ls -t | grep ^chsLog

fcounter=1

for fnames in $filenames

     do

             fstat=`stat -c %y ${fnames} | cut -d '.' -f1`

             fstat=`echo ${fstat//[^0-9]/}`

             if [[ $fstat -gt $lastfile ]]

             then

                     if [[ $fcounter -eq 1 ]]

                     then

                             echo $fstat > $dst_dir/last_cdr.txt

                             let "fcounter = $fcounter + 1"

                     fi

                     deasn9 -b -a cdrr6 ${fnames} > $dst_dir/$fstat-${fnames}.txt

             fi

     done
2
It sounds like /tmp/DPE_SC/LoadUnits/ttx/bin/deasn9 isn't working in crontab context, but we're not going to be able to figure out why it doesn't work just from seeing the line used to run it...Gordon Davisson
@GordonDavisson As your request, Here I put my whole script. It works well from cmdline. But only deasn9 -b -a cdrr6 ${fnames} > $dst_dir/$fstat-${fnames}.txt line not work from crontab. I sees that line echo $fstat > $dst_dir/last_cdr.txt worked well from crontab.tsoomo
from stderr msg shell tried to open file named cdrr6.spe. But cdrr6 should be part of deasn9 binary's option. How could I tell it to shell cdrr6 is deasn9's option?tsoomo

2 Answers

1
votes

Remember that your .profile, .bashrc, et. al. are not available from inside cron.

Environment variables have to be defined directly in the crontab.

e.g.

fstat=myValue
fname=aName
@hourly myJob ${fstat} ${fname}
0
votes

I found what I mistaken. cdrr6 was not only option. It is cdr formatting library. Then I exported LIB path from scipt. Now it worked perfectly.