CHECK SCRIPT SYNTAX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CHECK SCRIPT SYNTAX
# 1  
Old 09-19-2012
CHECK SCRIPT SYNTAX

Hi everyone, i'd like someone chechk this script, i know it's very simple but it doesn't work good, let me tell you this script works over huge directories, maybe that's the problem, if somebody can give me other way to develop, or show me where it's the problem, i'll appreciate it.

Code:
PATH_ROOT="/ot/bean/923/domains/scape"

find $PATH_ROOT/servers/scape-admin/logs/*.log* -mtime +7 -exec rm {} \;
find $PATH_ROOT/servers/scape-services-ru/logs/*.log* -mtime +7 -exec rm {} \;
find $PATH_ROOT/servers/scape-services/logs/*.log* -mtime +7 -exec rm {} \;
find $PATH_ROOT/servers/scape-gui/logs/*.log* -mtime +7 -exec rm {} \;
find $PATH_ROOT/servers/scape-gui-ru/logs/*.log* -mtime +7 -exec rm {} \;

# 2  
Old 09-19-2012
This may be due to the ARG_MAX... every server (OS) has its own kernel limit set to argument length if it goes beyond that (that might be the case your rm command facing)..

read below link..

How long can the command line be?
This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 09-19-2012
i'm working with Red Hat 5 Enterprise, i understand what you mean, but how i can find out what to? My boss ask me for some script which do that, it was very simple, but i just a beginner.
Could you help me?
# 4  
Old 09-19-2012
Do you have to scan directory and all subdirectories within?
If you are only removing old files at ONE level, consider using -prune option of find
This User Gave Thanks to vbe For This Post:
# 5  
Old 09-19-2012
try checking XARGS man page might be usefull
Quote:

xargs can execute the command supplying some initial arguments directly, and reading the remaining arguments from standard input (or piped input).
xargs passes arguments to command in several bundles, this allows command to process more arguments than it could normally handle at once
This User Gave Thanks to vidyadhar85 For This Post:
# 6  
Old 09-19-2012
Putting the too many arguments into find hasn't stopped them from being too many arguments. You need to not give them too many arguments.

Let find handle the pattern matching. That way, you only give it one argument.

You can give find more than one folder, too, and handle it all at once.

Code:
PATH_ROOT="/ot/bean/923/domains/scape"

find    "$PATH_ROOT/servers/scape-admin/logs/"             \
        "$PATH_ROOT/servers/scape-services-ru/logs/"       \
        "$PATH_ROOT/servers/scape-services/logs/"          \
        "$PATH_ROOT/servers/scape-gui/logs/"               \
        "$PATH_ROOT/servers/scape-gui-ru/logs/"            \
        -name '*.log*' -mtime +7 -exec echo rm '{}' '+'

-name can match files like you were doing inside the shell, without having to match inside the shell, avoiding the 'too many arguments' problem. Putting it in single quotes prevents the shell from trying to expand it too soon.

Using '+' instead of ';' will cause it to put as many files as it can into each rm call instead of running rm 10,000 individual times for 10,000 individual files, which will make it more efficient.

Remove the echo once you've tested and are sure it does what you want.
These 2 Users Gave Thanks to Corona688 For This Post:
# 7  
Old 09-19-2012
Power

Hi Corona, as usually, your solution are the best, i got the idea, but your way produce me others doubts, for example the "\" with that spaces at the end of each line, for what are they?
The other question, if i use this code just like you put it on, show, or print me, it works?
Just one line to delete at the end?
And the last one, why should i remove the echo?

Code:
PATH_ROOT="/ot/bean/923/domains/scape"

find    "$PATH_ROOT/servers/scape-admin/logs/"             \
        "$PATH_ROOT/servers/scape-services-ru/logs/"       \
        "$PATH_ROOT/servers/scape-services/logs/"          \
        "$PATH_ROOT/servers/scape-gui/logs/"               \
        "$PATH_ROOT/servers/scape-gui-ru/logs/"            \
        -name '*.log*' -mtime +7 -exec echo rm '{}' '+'   ...just this delete?

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script syntax help

#!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'` CMD=`ps -eaf | grep -c mysql` if ; then ./mysql $ip $user $pass & else sleep 15... (6 Replies)
Discussion started by: galford
6 Replies

2. Shell Programming and Scripting

Help with Check Syntax of Shell Script without Running

Hi Everyone, Is there any way ( generic) to check syntax of Shell Scripts without running it?? (4 Replies)
Discussion started by: roy121
4 Replies

3. Shell Programming and Scripting

Shell script check syntax not working ...

Hello i have question that i want check syntax from my script shell with sh -n filename but it's not show something even i have wrong syntax in my file. why can this happened or any other way to check it? i use on header of file : #!/bin/sh thx before :) (7 Replies)
Discussion started by: Gochengz
7 Replies

4. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

5. Shell Programming and Scripting

script to check if another script is running and if so, then sleep for sometime and check again

Hi, I am a unix newbie. I need to write a script to check wheteher another script is still running. If it is, then sleep for 30m and then check again if the script is running. If the script has stopped running then, I need to come out of the loop. I am using RHEL 5.2 (2 Replies)
Discussion started by: mathews
2 Replies

6. Shell Programming and Scripting

How to Check Shell script syntax w/o executing

Hello All, I looking for a way to verify the correction of shell script syntax. Is there any switch like -c in perl which do this in shell ? Thank You. (1 Reply)
Discussion started by: Alalush
1 Replies

7. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies

8. UNIX for Dummies Questions & Answers

quick check of my awk syntax

I've made an awk command that works successfully. However I'd like to add one character to it. For example instead of /what_i_have_now/ I'd like to change just ONE field to the opposite with an exclamation point. Like this: ! /what_i_have_now/ My question, where am I supposed to place... (1 Reply)
Discussion started by: yongho
1 Replies

9. UNIX for Dummies Questions & Answers

syntax and semantic check

Does the shell perform a syntax and semantic check before commands are sent to the kernel? Ravioli (3 Replies)
Discussion started by: ravioli
3 Replies
Login or Register to Ask a Question