Hi all,
Can anyone assit me?
I wrote this script to clean up log files located in a directory called out. The script creates a directory called TEMP and moves the logs into the directory then tars the directory and compresses it. After all that is done it will remove the temporay directory.
My problem is that when I tested the script without any log files it bombs out at the first foreach that searches for log files.
The complaint that the script gives is as follows:
foreach: No Match
I understand that it is not finding any *.log files but it should continue through the other conditions. The script will not complain if there isn't a TEMP directory.
Here is a copy of my script.
#!/bin/csh
while(1)
echo " starting clean-up in 10 seconds "
sleep 10
envout
foreach log (*.log)
if(-f $log && -d TEMP)then
tar cfv temp.tar TEMP;
compress temp.tar;
rm TEMP/*.*;
mv $log TEMP;
else if(-f $log)then
mkdir TEMP;
mv $log TEMP;
#tar cfv temp.tar TEMP;
#rm -R TEMP;
else if(-d TEMP)then
tar cfv temp.tar TEMP;
rm -R TEMP;
endif
end
foreach file (temp.tar)
if(-f $file && -d TEMP)then
@ $file++
tar cfv $file TEMP;
compress $file;
rm -R TEMP;
else
echo "There are no Log files or a TEMP directory"
endif
end
echo " Finished in 10 seconds"
sleep 10
end #I will not include this so it will only run once.
Can anyone assit me?
I wrote this script to clean up log files located in a directory called out. The script creates a directory called TEMP and moves the logs into the directory then tars the directory and compresses it. After all that is done it will remove the temporay directory.
My problem is that when I tested the script without any log files it bombs out at the first foreach that searches for log files.
The complaint that the script gives is as follows:
foreach: No Match
I understand that it is not finding any *.log files but it should continue through the other conditions. The script will not complain if there isn't a TEMP directory.
Here is a copy of my script.
#!/bin/csh
while(1)
echo " starting clean-up in 10 seconds "
sleep 10
envout
foreach log (*.log)
if(-f $log && -d TEMP)then
tar cfv temp.tar TEMP;
compress temp.tar;
rm TEMP/*.*;
mv $log TEMP;
else if(-f $log)then
mkdir TEMP;
mv $log TEMP;
#tar cfv temp.tar TEMP;
#rm -R TEMP;
else if(-d TEMP)then
tar cfv temp.tar TEMP;
rm -R TEMP;
endif
end
foreach file (temp.tar)
if(-f $file && -d TEMP)then
@ $file++
tar cfv $file TEMP;
compress $file;
rm -R TEMP;
else
echo "There are no Log files or a TEMP directory"
endif
end
echo " Finished in 10 seconds"
sleep 10
end #I will not include this so it will only run once.