Issue with script

Hi,

I am running below script using autosys.
Though the script is running fine, it fails the workflow but the autosys job shows success.
Can you please let me know where can i make change to script:-

#!/bin/ksh
#to test mail from directory
set -x
frequency=$1
param_file=/local/test
mail_dir=/local/test
if [ -f $param_file ]
then
rm $param_file
fi
touch $param_file
chmod 777 $param_file
echo "[Global]" > $param_file
echo '$$ENVIRONMENT'"=$ENVIRONMENT" >> $param_file
echo '$DBConnection_s'"=ITRAS" >> $param_file
echo '$$frequency'"=$1" >> $param_file
rm $mail_dir/*
$ITRC/scripts/itrc_startworkflow.ksh dummy wf_test
#mail_dir=/local/test
rm $mail_dir/alert_email_content1.out
#echo $mail_dir

find $mail_dir/* -type f | grep -q .
file_check=$?
if [ $file_check -ne 0 ]; then
  echo "Rows for alert  $1* doesnot exists"
 # echo "File $1* doesnot exists or No Files are older than $3 days in the directory $2" >> $log_file
  exit 0
fi

for file in $mail_dir/* ;
do
echo "$file"
/\n/g' "$file"
#mail_sub= echo $file | cut -d'/' -f8
mail_sub=`head -1 "$file"`
sed -i -e "1d" "$file"
mail_id=`head -1 "$file"`
sed -i -e "1d" "$file"
chmod 777 "$file"
echo "mail ID is  $mail_id"
echo "mail subject is " $mail_sub
cat $file | mailx -s "$mail_sub" "$mail_id"
#echo $mail_sub
done
exit 0

Welcome rajrishi990,

Firstly, please wrap all code, files, input & output in

```text
 & 
```

tags. I have adjusted your post. It nor preserves your spacing which can make code much easier to read and is critical for fixed width data.

Thanks for the question.

How do you know that this is meant to error? If it displays the message made by Rows for alert $1* doesnot exists then the next thing you do is to exit 0 which is probably signalling success of the script back to the scheduler.

Try changing the exit code and see if it is that simple. Autosys may have a variety of return codes for various states, e.g. success, minor issue, warning, alert, error etc. or is may just have two - zero return code for success and any other number for a failure.

Have a play with that and see how you get on.

I hope that this helps,
Robin

In your script no autosys is involved unless it is hidden in $ITRC/scripts/itrc_startworkflow.ksh . You don't examine this script's exit code - wouldn't that help?

I see you set the shell's -x option - why don't you show us the log of the run?

Something wrong here, a directory is not a file!

In addition: if you run this script via some spooler you probably rely on an environment being there which isn't - similar to Cron Problem Number One. I can't see any part in your script that sets a proper environment. So chances are it isn't there.

I hope this helps.

bakunin