tsoomo
tsoomo

Reputation: 95

BASH script not work properly in crontab

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

Upvotes: 0

Views: 534

Answers (2)

tsoomo
tsoomo

Reputation: 95

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.

Upvotes: 0

H.-Dirk Schmitt
H.-Dirk Schmitt

Reputation: 1169

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}

Upvotes: 1

Related Questions