[vox-tech] Bash scripting newbie - need syntax help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vox-tech] Bash scripting newbie - need syntax help
Hi all -
The short version of my problem is I need help with a recursive bash script, and I have never written a bash script before. If you want to skip this lengthy intro, you may be able to tell what I am trying to do from looking at my script attempt (labeled below).
* * * * * * Lengthy intro
I had noticed that logrotate was running what seemed to be an excessive amount of time for (many) weeks. I didn't have time to look at why, so I would kill it and return to other work. Recently, I just let it run and top showed logrotate was still running after 467 minutes (using over 99% CPU). After some looking around, I found that I had 100MB in empty error messages in /var/log/mailman.
total 0 [actually, over 100MB]
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 23 21:54 error.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1
-rw-rw-r-- 1 mailman mailman 0 Apr 19 04:45 error.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1
As I tried to delete them I got the following errors:
[root@localhost mailman]# rm -f error.*
bash: /bin/rm: Argument list too long
[root@localhost mailman]# rm -f error.1*
bash: /bin/rm: Argument list too long
[root@localhost mailman]# rm -f error.1.1*
bash: /bin/rm: Argument list too long
[root@localhost mailman]# rm -f error.1.1.1.1*
bash: /bin/rm: Argument list too long
[root@localhost mailman]# rm -f error.1.1.1.1.1*
bash: /bin/rm: Argument list too long
[root@localhost mailman]# rm -f error.1.1.1.1.1.1*
bash: /bin/rm: Argument list too long
I finally found some that I could delete.
[root@localhost mailman]# rm -f error.4.4.3*
[root@localhost mailman]# rm -f error.4.4.2*
[root@localhost mailman]# rm -f error.4.4*
After an hour of this I decided there must be a way to write a bash script to go through adding a digit each time rm failed.
* * * * * * Bash script attempt
I have no prior experience with bash scripting, so I am hoping there are simple syntax errors someone can point out. The script is "bigerase" and the first arg is "error".
[root@localhost mailman]# bigerase error
The idea is that if it can't erase all files "error.1*" because there are too many, it calls itself again and tries "error.1.1*", and so forth.
declare -i $i;
echo $i $1
for (($i=1; $i<5; $i++));
Do
until rm -f $1.$i* || exec -a bigerase $1.$i;
done;
echo -n =
done;
I read through the bash man page 3 times, but couldn't get enough out of it to understand the error message: unexpected Do on line 4. The man page said the syntax of the for loop was "for ((exp; exp; exp)); do exp; done", which is what I thought I had.
Any help would be appreciated. Thanks.
- Larry
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech
|