Operating System - HP-UX
1752571 Members
4599 Online
108788 Solutions
New Discussion юеВ

Re: script to clean files

 
SOLVED
Go to solution
Felix  Tabares
Contributor

script to clean files

Good afternoon.

I wanted to please help me create a script that allows me to empty the files located in the following path: / var/opt/hpsmc/avc/VM00726000-1-1/log clean them manually with the command cp / dev / null
clean up files in the directory are: sgsyncd.log, monitorsvcd.bak, monitorsvcd.log

Thanks for your help
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: script to clean files

Hi:

Consider something like:

#!/usr/bin/sh
cd var/opt/hpsmc/avc/VM00726000-1-1/log || exit
for FILE in sgsyncd.log, monitorsvcd.bak, monitorsvcd.log
do
cat /dev/null > ${FILE}
done

Regards!

...JRF...
Wilfred Chau_1
Respected Contributor

Re: script to clean files

#! /usr/bin/sh

cd /var/opt/hpsmc/avc/VM00726000-1-1/log
ls sgsyncd.log monitorsvcd.bak monitorsvcd.log | while read file
do
ls -l $file >> purge.log
> $file
done
James R. Ferguson
Acclaimed Contributor

Re: script to clean files

Hi (again):

Doing a 'cd' and assuming that it places you where you want is asking for trouble!

If the change-directory fails, you are left where you began. If you began from '/' and Wilfred's script would ever so helpfully truncate every file in the root directory. Of course, no directory descent would occur, but...

Regards!

...JRF...
Wilfred Chau_1
Respected Contributor
Solution

Re: script to clean files

Good point James! I added a condition to end of the cd command.

#! /usr/bin/sh

cd /var/opt/hpsmc/avc/VM00726000-1-1/log || exit
ls sgsyncd.log monitorsvcd.bak monitorsvcd.log | while read file
do
ls -l $file >> purge.log
> $file
done