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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh script throwing arg list too long for mv cp wc - everything
# 1  
Old 11-08-2012
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.
Smilie
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? Smilie
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.

Code:
 
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:
HTML Code:
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.
# 2  
Old 11-08-2012
Suggestion: Put all your string arguments for your commands in double quotes and retry
E.g:-
Code:
/usr/xpg4/bin/rm -f "${outtempfile}"

# 3  
Old 11-09-2012
Quote:
Originally Posted by bipinajith
Suggestion: Put all your string arguments for your commands in double quotes and retry
E.g:-
Code:
/usr/xpg4/bin/rm -f "${outtempfile}"


Quotes are not helping.
Same situation.

HTML Code:
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
# 4  
Old 11-09-2012
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
# 5  
Old 11-09-2012
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 ----------

Quote:
Originally Posted by alister
Which operating system and version is this failing on?
SunOS 5.10
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Arg list too long

Hello All, I am trying to find a file name with .sh exention from a list of .dat files inside a directory. find /app/folder1/* -name '*.dat'| xargs grep '.sh' ksh: /usr/local/bin/find: arg list too long Please help me finding the command. Thanks (3 Replies)
Discussion started by: tkhan9
3 Replies

2. Shell Programming and Scripting

arg list too long

Hi, Help. I have a file that contains a list of users in a file. I want to cat the content of the file and feed it into sed to a preformated report. The error I got is "ksh: /usr/bin/sed: arg list too long" My method below. A=`cat FILE1.txt` B=`echo $A` sed "s#USERLIST#$B#" FILE2 >... (2 Replies)
Discussion started by: Zenwork
2 Replies

3. UNIX for Dummies Questions & Answers

Arg List too Long in SCP

Hey guys. I have a program written in which i am trying to get the files from one remote machine and transferring the files to another remote machine using SCP. It works fine for 50 or 60 files but when the files grows to 250 then i get an error message stating "Arg list too long". #scp -p... (5 Replies)
Discussion started by: chris1234
5 Replies

4. UNIX for Dummies Questions & Answers

ksh: /usr/bin/ls: arg list too long

I am using IBM AIX unix version 4.3.3.0. In a directory there are many files with different patterns. When I am trying to execute the command, ls -l with the file pattern, which have fewer files it gives the desired result. However when I am trying to execute the same command for file pattern,... (2 Replies)
Discussion started by: jitindrabappa
2 Replies

5. Shell Programming and Scripting

ksh: /bin/grep: arg list too long

when i run the command below in a directory which contains too many files i got the error: ksh: /bin/grep: arg list too long ls|grep AA*B* how can i handle this problem? (5 Replies)
Discussion started by: gfhgfnhhn
5 Replies

6. UNIX for Dummies Questions & Answers

ls -t arg list too long

echo dirname/filename* | xargs ls -t As a substitute doesn't give the results desired when I exceed the buffer size. I still want the files listed in chronological order, unfortunately xargs releases the names piecemeal...does anyone have any ideas? :( (4 Replies)
Discussion started by: CSU_Ram
4 Replies

7. UNIX for Advanced & Expert Users

arg list too long

Does anyone have a solution for arg list too long error. I have got this from the web but I fail to make any sense out of it Thanks enc (8 Replies)
Discussion started by: encrypted
8 Replies

8. UNIX for Dummies Questions & Answers

zcat --> Arg list too long

Hi all I have more than 1000 files in a folder and when ever i use a "compress" or "zcat" command it give error /bin/zcat: Arg list too long. . any solution for this :o (3 Replies)
Discussion started by: muneebr
3 Replies

9. UNIX for Dummies Questions & Answers

egrep and Arg list too long

hi everyone, We have a heck of a lot of files in a particular directory and I need to search through all of them to find a list of all files containing particular text strings...one being a date and the other being the name of the report that is printed on the files..... I've tried the... (6 Replies)
Discussion started by: kingo
6 Replies

10. UNIX for Dummies Questions & Answers

arg list too long

I do ls -l ABC*, I get arg list too long message. This will not happen if ABC* has small no of files I believe 4000 files is limit. Any way of avoiding this. I even tried like this for i in `ls -l ABC*` do echo $i done Same problem. Any solution would be great. I am on HP-UX... (5 Replies)
Discussion started by: vingupta
5 Replies
Login or Register to Ask a Question