Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nulling log files with a script

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi guys,

Currently coding something together to copy and clear down log files on a monthly basis. I thought this would be simple. But I am having problems with the clearing of the original log files. Even when su to root.

Here is a copy of the script I am trying to execute:

while(1)

foreach log (/usr/cs3/master/*.log)

if(-f $log)then
cp -p $log /logs/tetralogs/oct03/;
endif

end
cd /usr/cs3/master
> *.log

When I run the script I get the following error message:

Invalid null command.

I have used the '>' before in a script without issue. Also tried using /dev/null. Anyone have any ideas ?

The files I am attemtping to cleardown are satndard text files.

 
That might work in Korn or Bourne shell, but it looks like you're working in C shell.

Try cp /dev/null thingummy.log instead.

Also, you can't use > *.log in any shell because output can only be directed to one file, so you should do that within your foreach loop for each individual file.

Annihilannic.
 
Thanks Annihilannic. Yes it is a C Shell script. It's the first time I am trying my hand at it. As most of my Scripts have been written for KSH.

I have tried using the > within the foreach loop but got the same error message.

Will try the cp /dev/null approach.

 
Annihilannic. Yes the cp/dev/null works a treat within the loop. Thanks again.
 
Okay I am now using this script:

while(1)

echo " starting clean-up of /usr/cs3/master in 2 seconds "
sleep 2

foreach log (/usr/cs3/master/*.log)

if(-f $log)then
cp -p $log /logs/tetralogs/nov03/;
cp /dev/null $log
endif

end

cp -p /usr/cs3/sysmprc/system.log /logs/tetralogs/nov03/

sleep 1

cp /dev/null /usr/cs3/sysmprc/system.log

sleep 1

echo " starting clean-up of /logs in 2 seconds "
sleep 2

foreach log2 (/logs/*.log)

if(-f $log2)then
cp -p $log2 /logs/oldlogs/;
cp /dev/null $log2
endif


echo " Finished in 2 seconds"
sleep 2

But for the 'foreach log2 (/logs/*.log)' I need to be able to exclude the file servtran.log.

Any ideas.

Thanks again.
 
Hi jpor,

In your original post:
You can't use > *.log outside the loop but you can do it inside:
Code:
while(1)
    foreach log (/usr/cs3/master/*.log)
    if(-f $log)then
        cp -p $log /logs/tetralogs/oct03/;
        > $log
    endif
    end
    cd /usr/cs3/master

uses only redirection instead of loading command.

In your second post, try:
Code:
    :
    if( -f $log2 && $log2 != "/logs/servtran.log" ) then
    :

I'm not very familiar with the C shell but i think it will work

Hope it helps,
Theophilos
 
Thanks theotyflos. Will give that a go.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top