ksh script throwing arg list too long for mv cp wc - everything

i have a ksh script which internally calls another ksh script.
this inner script has simple commands like shown in the code window.
In the script im trying to do a mv - it fails with arg list too long.
then i try to perform cp and cat - and both are failing with similar error.
:wall:
How is it possible that while trying to move only one file to a different file name - shell is throwing arg list too long error? :confused:
Please note - when i run the same command from command prompt it works just fine.

Please suggest/help if someone has seen such a problem before.
thanks.

 
Script : 
echo "Setting outtempfile name."
export outtempfile="${OUTVALIDLIST}""_tmp"
echo "outtempfile=[${outtempfile}]"
/usr/xpg4/bin/rm -f ${outtempfile}
unalias mv
which mv
echo "move command :"
echo "[[[ mv ${OUTVALIDLIST} ${outtempfile}  ]]]"
/usr/xpg4/bin/mv ${OUTVALIDLIST} ${outtempfile}
if [ $? -ne 0 ]
then
  echo "[WARNING] mv command failed. Source file: [${OUTVALIDLIST}], Destination file: [${outtempfile}]"
  echo "Copying content from ${OUTVALIDLIST} to ${outtempfile}"
/usr/xpg4/bin/cp ${OUTVALIDLIST} ${outtempfile}
  if [ $? -eq 0 ]
  then
    echo "[INFO] Successfully Copied content from ${OUTVALIDLIST} to ${outtempfile}"
    echo "" > ${OUTVALIDLIST}
  else
    echo "[INFO] perform change dir"
cd $ABP_MF_ROOT/log
pwd
filename=`basename ${OUTVALIDLIST}`
tmpfilename="${filename}""_tmp"
echo "moving ${filename} to ${tmpfilename}"
mv ${filename} ${tmpfilename}
if [ $? -ne 0 ] ; then
    echo "[ERROR] Failed to copy content from ${OUTVALIDLIST} to ${outtempfile}"
    return -1
else
echo "[INFO] after perform change dir, mv succeeded"
fi
  fi
else
  echo "[INFO] mv command succeeded. Source file: [${OUTVALIDLIST}], Destination file: [${outtempfile}]"
fi
 

The above script fails with this errors:

Setting outtempfile name.
outtempfile=[/work/users........log/VALIDFILELIST_21798_20121108_073435.log_tmp]
/work/users......../script_Sh[22]: /usr/xpg4/bin/rm: arg list too long
/work/users......../script_Sh[25]: /usr/bin/which: arg list too long
move command :
[[[ mv /work/users........log/VALIDFILELIST_21798_20121108_073435.log /work/users........log/VALIDFILELIST_21798_20121108_073435.log_tmp  ]]]
/work/users......../script_Sh[30]: /usr/xpg4/bin/mv: arg list too long
[WARNING] mv command failed. Source file: [/work/users........log/VALIDFILELIST_21798_20121108_073435.log], Destination file: [/work/users........log/VALIDFILELIST
_21798_20121108_073435.log_tmp]
Copying content from /work/users........log/VALIDFILELIST_21798_20121108_073435.log to /work/users........log/VALIDFILELIST_21798_20121108_073435.log_tmp
/work/users......../script_Sh[37]: /usr/xpg4/bin/cp: arg list too long
[INFO] perform change dir
/work/users........log
/work/users......../script_Sh[47]: /usr/xpg4/bin/basename: arg list too long
moving  to _tmp
/work/users......../script_Sh[50]: /usr/xpg4/bin/mv: arg list too long
[ERROR] Failed to copy content from /work/users........log/VALIDFILELIST_21798_20121108_073435.log to /work/users........log/VALIDFILELIST_21798_20121108_073435.lo
g_tmp
validateScript /work/users......../script_Sh returned failure.

Suggestion: Put all your string arguments for your commands in double quotes and retry
E.g:-

/usr/xpg4/bin/rm -f "${outtempfile}"

Quotes are not helping.
Same situation.

Setting outtempfile name.
outtempfile=[/work/users/......../log/VALIDFILELIST_7309_20121109_055054.log_tmp]
/work/users/......../script_Sh[22]: /usr/xpg4/bin/rm: arg list too long
/work/users/......../script_Sh[25]: /usr/bin/which: arg list too long
move command :
[[[ mv /work/users/......../log/VALIDFILELIST_7309_20121109_055054.log /work/users/......../log/VALIDFILELIST_7309_20121109_055054.log_tmp  ]]]
/work/users/......../script_Sh[30]: /usr/xpg4/bin/mv: arg list too long
[WARNING] mv command failed. Source file: [/work/users/......../log/VALIDFILELIST_7309_20121109_055054.log], Destination file: [/work/users/......../log/VALIDFILELIST_
7309_20121109_055054.log_tmp]
Copying content from /work/users/......../log/VALIDFILELIST_7309_20121109_055054.log to /work/users/......../log/VALIDFILELIST_7309_20121109_055054.log_tmp
/work/users/......../script_Sh[37]: /usr/xpg4/bin/cp: arg list too long
[INFO] perform change dir
/work/users/......../log
/work/users/......../script_Sh[47]: /usr/xpg4/bin/basename: arg list too long
moving  to _tmp
/work/users/......../script_Sh[50]: /usr/xpg4/bin/mv: arg list too long
[ERROR] Failed to copy content from /work/users/......../log/VALIDFILELIST_7309_20121109_055054.log to /work/users/......../log/VALIDFILELIST_7309_20121109_055054.log_tmp

Which operating system and version is this failing on?

Exactly how is the second script called in the first one? What is the first line of the second script?

Regards,
Alister

i have tried with these first line in the script - but nothing helps:
#!/usr/bin/ksh -x
#!/usr/bin/ksh
#!/usr/ksh

How is this script called:
Script is called like this:

validateScript= export validateScript=${scriptpath}/${scriptname}

$\{validateScript\} $\{variable1\} $\{OUTVALIDLIST\} $\{variable3\} $\{variable4\}

OUTVALIDLIST - contains the name of the file which is passed to this script. This file exists before the script is called. (empty file)
Data is populated in the file by the failing script.
When i check on file system - file exists and has proper ascii text data as i expect.
Problem occurs - when i say
wc -l ${OUTVALIDLIST}

and so on as shown in code snippet earlier.

---------- Post updated at 07:34 AM ---------- Previous update was at 05:39 AM ----------

SunOS 5.10