Sponsored Content
Full Discussion: Script to clear filesystem
Operating Systems HP-UX Script to clear filesystem Post 302997182 by anaigini45 on Tuesday 9th of May 2017 06:51:10 AM
Old 05-09-2017
Script to clear filesystem

Hi,

I have created a script to clear up the /var filesystem once it reaches > 90%.
This is part of the script :

Code:
#!/bin/bash

DIR = ./adm
DIR2=./adm/sw
DIR3 = ./spool/mqueue
DIR4 = ./adm/syslog
DIR5 = ./adm/sulog
DIR6 = ./tmp
F1 = ./tmp/dead.letter
F2 = ./adm/wtmps
file1 = dead.letter
file2 = wtmps

dir=`du -x | sort -rn | head -20`
cd /var
for i in $dir;
do
	if [ -d "$DIR1" ]; then
		cd "$DIR1"
			if [ -f "$file2" ]; then
			 cat /dev/null > "$file2"
	elif [ -d "$DIR2" ]; then
		tar -cvf /temp/admsw.arch "$DIR2";
		rm -rf "$DIR2"
	elif [ -d "$DIR3" ]; then
		find "$DIR3" -mtime +100 -exec rm {} \;			
	elif [ -d "$DIR4" ]; then

	elif [ -d "$DIR5" ]; then	
		
	elif [ -d "$DIR6" ]; then
		cd "$DIR6"
			if [ -f "$file1" ]; then
				rm -f "$file1"
 			fi
	elif [ -f "$F1" ]; then
		rm -f "$F1"
	elif [ -f "$F2" ]; then
		cat /dev/null > "$F2"
	fi
done

To test if this script works, I execute the command in the terminal (only to clear one of the filesystems above). However it seemed to run for an extremely long time. Therefore I sensed that something could be wrong with the statements I used - perhaps the for loop?

These are the steps I executed :

Code:
# cd /var
# dir=`du -x | sort -rn | head -20`
# DIR2=./adm/sw
#for i in $dir;
>do
>if [ -d "$DIR2" ]; then
>tar -cvf /temp/admsw.tar "$DIR2";
>fi
>done

Are the above steps correct? Why does the command run for a long time?

Last edited by anaigini45; 05-09-2017 at 07:58 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Clear Case, Awk and script

Hello. I should have asked this awhile ago but here is my situation. My task is to generate LOC for different directories. I have a text file that has dates in this format (01-Aug-2006). My task is to read each line and compare it to a branch date. Depending on the date, it should generate a... (0 Replies)
Discussion started by: mastachef
0 Replies

2. Linux

SED/AWK Script to clear log file using timestamp?

I have a log file on our system which fills up with lines that have been timestamped, as follows.... 03/03/2008 10:56:06:815] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:06:820] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:07:003]... (2 Replies)
Discussion started by: davesimm
2 Replies

3. Shell Programming and Scripting

How to clear $1 when dot-running a script.

Here's my problem: the $1 parameter is getting permanently set when you dot-run a script - and I cannot unset it. Here's how to duplicate the problem: 1) Create a script called testme and put this simple command in the script: echo 1=$1 Save the script 2) Make the testme script... (12 Replies)
Discussion started by: HobieCoop
12 Replies

4. AIX

Help with a filesystem monitoring script.

I'd like to create a cron script that checks filesystems. For example if it reaches 95% USED, I'd like it to send me an email. Can this be possible for up to say 4 filesystems using the df -k command? Any samples to get me started would be much appreciated. (7 Replies)
Discussion started by: NycUnxer
7 Replies

5. Shell Programming and Scripting

Monitoring Script - filesystem

Hi all, I got an error when running this script (from BigAdmin community) the error is test: argument expected my server version is SunOS XXX 5.8 Generic_117350-46 sun4u sparc SUNW,Sun-Fire-V890 any idea on it? #! /usr/bin/ksh ### ### This script can be run from cron to... (9 Replies)
Discussion started by: SmartAntz
9 Replies

6. Shell Programming and Scripting

Filesystem Usage Script

Hey guys I am learning Linux and I am working on script for a college class project to check usage of file system. I pulled this from a different site but have to tweak it a little to work but I still get errors. Here is what I got so far. ALERT=5 function main_prog() { while read output;... (1 Reply)
Discussion started by: jcsx6245
1 Replies

7. UNIX for Dummies Questions & Answers

hwo to find shared filesystem and local filesystem in AIX

Hi, I wanted to find out that in my database server which filesystems are shared storage and which filesystems are local. Like when I use df -k, it shows "filesystem" and "mounted on" but I want to know which one is shared and which one is local. Please tell me the commands which I can run... (2 Replies)
Discussion started by: kamranjalal
2 Replies

8. AIX

Mount Filesystem in AIX Unable to read /etc/filesystem

Dear all, We are facing prolem when we are going to mount AIX filesystem, the system returned the following error 0506-307The AFopen call failed : A file or directory in the path name does not exist. But when we ls filesystems in the /etc/ directory it show -rw-r--r-- 0 root ... (2 Replies)
Discussion started by: m_raheelahmed
2 Replies

9. AIX

Help with clear printer queue script in AIX 5.3

Good day UNIX forum, could you help me with my clear printer queue script, i have problems with the consistency of this function, sometimes it works sometimes it doesn't. Thanks in advance } preRemovePrintQ(){ clear; echo; echo... (1 Reply)
Discussion started by: beware187
1 Replies

10. Shell Programming and Scripting

Need to exclude .NFSxxx files in clear old files batch script

I am new to Shell Scripting and need some help. The following batch job has been failing for me due to the .nfsxxx files in use. I need to know how to modify the following script to exclude the .nfsxxx files so this batch job will not fail on me. I have done lots of googling and keep coming back... (2 Replies)
Discussion started by: kimberlyg2007
2 Replies
DIFF(1) 						      General Commands Manual							   DIFF(1)

NAME
diff - print differences between two files SYNOPSIS
diff [-c | -e | -C n] [-br]file1 file2 OPTIONS
-C n Produce output that contains n lines of context -b Ignore white space when comparing -c Produce output that contains three lines of context -e Produce an ed-script to convert file1 into file2 -r Apply diff recursively to files and directories of EXAMPLES
diff file1 file2 # Print differences between 2 files diff -C 0 file1 file2 # Same as above diff -C 3 file1 file2 # Output three lines of context with every diff -c file1 file2 # Same diff /etc /dev # Compares recursively the directories /etc and /dev diff passwd /etc # Compares ./passwd to /etc/passwd DESCRIPTION
the same name, when file1 and file2 are both directories" difference encountered" Diff compares two files and generates a list of lines telling how the two files differ. Lines may not be longer than 128 characters. If the two arguments on the command line are both directories, diff recursively steps through all subdirectories comparing files of the same name. If a file name is found only in one directory, a diagnostic message is written to stdout. A file that is of either block special, character special or FIFO special type, cannot be compared to any other file. On the other hand, if there is one directory and one file given on the command line, diff tries to compare the file with the same name as file in the directory directory. SEE ALSO
cdiff(1), cmp(1), comm(1), patch(1). DIFF(1)
All times are GMT -4. The time now is 12:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy