Operating System - HP-UX
1820540 Members
3100 Online
109626 Solutions
New Discussion юеВ

Parameter list is too long.

 
SOLVED
Go to solution
Rafael Mendon├зa Braga
Regular Advisor

Parameter list is too long.

Hello There...
I have a Script that removes logs with "x" days in a directory of my HPUX 11i server.
The logs are generated following a standard:
Dxx_LOG_NAME.log, where xx is the number of days we have to retain the log.
The scripts is this:

DAY=$(ls -1 /interface/web/D* |cut -f2 -dD |cut -f1 -d_)

NEW=00
for EACHONE in $DAY
do
if [ "${NEW}" -ne "${EACHONE}" ]; then
NEW=$EACHONE
EACHONE=`expr $EACHONE \* 1`
EACHONE=`expr $EACHONE - 1`
find /interface/web/ -name D$NEW*.* -mtime +$EACHONE -print -exec rm {} \;
fi
done

----------------------------------------------------------

Sometimes I'm receiving this message:

sh: /usr/bin/ls: The parameter list is too long.

Do you Know How can I avoid it?

Thanks,

Rafael
7 REPLIES 7
RAC_1
Honored Contributor

Re: Parameter list is too long.

You are hitting MAX_ARGS limit. Pipe the output and then do args on it to do what you want.
There is no substitute to HARDWORK
Steven E. Protter
Exalted Contributor

Re: Parameter list is too long.

ls -1 > file

while read -r filename
do
rm -f $filename
# or any other operation you want to accomplish.
done < file


SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Parameter list is too long.

Hi:

You are causing the shell to collect create a list that is too long. Change the way you drive your script to leverage the 'find' of the directory, like:

...
cd /interface/web
find . -type f |
while read FILE
do
...
done

Regards!

...JRF...
Roy Colica
Advisor
Solution

Re: Parameter list is too long.

Rafael,
use find instead of ls to solve the issue.
Re
Roy
Doug O'Leary
Honored Contributor

Re: Parameter list is too long.

Hey;

Although the other posts would work, RAC mentioned the correct answer:

DAY=$(ls -1 /interface/web/D* |cut -f2 -dD |cut -f1 -d_)

NEW=00
for EACHONE in $DAY
do
if [ "${NEW}" -ne "${EACHONE}" ]; then
NEW=$EACHONE
EACHONE=`expr $EACHONE \* 1`
EACHONE=`expr $EACHONE - 1`
find /interface/web/ -name D$NEW*.* -mtime +$EACHONE -print | xargs -i rm {}
fi
done

The trick is the xargs pipe from the find command. Minor tweak.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Doug O'Leary
Honored Contributor

Re: Parameter list is too long.

Oops; my mistake. Misread where the error was coming from...

I'd still keep the xargs command in your loop; however, you can avoid the potential buffer overflow by:


NEW=00
for EACHONE in $(find /interface/web -name D\* -exec ls -dl {} \; | cut -f2 -dD | cut -f1 -d_)
do
if [ "${NEW}" -ne "${EACHONE}" ]; then
NEW=$EACHONE
EACHONE=`expr $EACHONE \* 1`
EACHONE=`expr $EACHONE - 1`
find /interface/web/ -name D$NEW*.* -mtime +$EACHONE -print | xargs -i rm {}
fi
done

Sorry for the confusion...

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Rafael Mendon├зa Braga
Regular Advisor

Re: Parameter list is too long.

Thanks Guys!!!

It's Working!