Sponsored Content
Full Discussion: Script to clear filesystem
Operating Systems HP-UX Script to clear filesystem Post 302997273 by MadeInGermany on Wednesday 10th of May 2017 02:14:51 PM
Old 05-10-2017
Your script does not work for several reasons.
The du -x ... is run in the current directory.
root's home directory is / so it takes very long to traverse all the files. Then, the du output consists of numbers and directories. The for loop cycles through all of them. The code in the loop is run over and over again.
Now you know why it takes so long.
--
Once upon a time I created a script that rotates HP-UX system log files.
Useful on systems that are not regularly rebooted.
It is run by the crontab entry:
Code:
10 3 1 * * /usr/lib/newsyslog

And the executable /usr/lib/newsyslog looks like this
Code:
#!/bin/sh
# idea from Sun's newsyslog script
# HP-UX version
#
MIN_BLOCKS=2048 # rotate if >1MB
MAX_HIST=3 # .0 through .3
#
# access rotated files with
# last -f /var/adm/wtmp.0
# last -Xf /var/adm/wtmps.0
# lastb -f /var/adm/btmp.0
# lastb -Xf /var/adm/btmps.0
#
pgrepx(){
UNIX95=1 ps -C "$1" -o pid=
}
#
testlog(){
 for _i do
  [ -s "$_i" ] &&
   [ -n "`find "$_i" -prune -type f -size +"$MIN_BLOCKS"`" ] &&
   return
 done
}
#
rotatelog(){
 log=$1
 method=${2:-mv}
 i=$MAX_HIST
 while [ $i -gt 0 ]
 do
  j=`expr $i - 1`
  test -f $log.$j && mv $log.$j $log.$i
  i=$j
 done
 $method $log $log.0
 > $log
}
#
umask 22
LOGS="
/var/adm/syslog/syslog.log
/var/adm/syslog/mail.log
"
action=""
for log in $LOGS
do
 if testlog $log
 then
  rotatelog $log "mv"
  action=1
 fi
done
[ -n "$action" ] &&
 chmod 644 /etc/syslog.pid &&
 kill -HUP `cat /etc/syslog.pid`
#
LOGS="
/var/opt/omni/log/inet.log
/var/opt/omni/log/debug.log
"
action=""
for log in $LOGS
do
 if testlog $log
 then
  rotatelog $log "mv"
  action=1
 fi
done
#
umask 2
LOGS="
/var/adm/wtmps
/var/adm/wtmp
/var/adm/btmps
/var/adm/btmp
/var/adm/sulog
/var/adm/lp/lpd.log
"
# rotate all non-zero files or none
action=""
if testlog $LOGS
then
 for log in $LOGS
 do
  if [ -s $log ]
  then
   rotatelog $log "cp -p"
   action=1
  fi
 done
fi
#
# finally rotate the cron logs
umask 22
LOGS="
/var/adm/cron/log
"
action=""
cronstart=/sbin/init.d/cron
[ -f $cronstart ] && {
for log in $LOGS
do
 if testlog $log
 then
  rotatelog $log "mv"
  action=1
 fi
done
# restart cron a bit time-shifted
[ -n "$action" ] &&
 sleep 1 &&
 sh $cronstart stop &&
 sleep 1 &&
 sh $cronstart start
}
#

If you have understood it, you can add more things to the LOGS= strings.

Last edited by MadeInGermany; 05-10-2017 at 04:57 PM..
 

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
log(8)							      System Manager's Manual							    log(8)

NAME
log - Records input and output from a program SYNOPSIS
/usr/sbin/log <logfile> <command> OPERANDS
The file in which to record the interaction being logged. The command to execute. DESCRIPTION
The log program runs <command> and logs the input to and output from <command> to the <logfile> file. Input and output are logged until <command> exits, the log program exits, and the exit status of <command> is returned. The log program is used by the system installation procedure and the it(8) command to create the /var/adm/smlogs/install.log and /var/adm/smlogs/it.log installation log files. RESTRICTIONS
Because the log program is used in the installation standalone environment, program size was the greatest concern in its implementation. The log program does not search for the PATH variable to locate <command> and error messages are terse. The log program causes <command> to take standard input from and write standard output and standard error to UNIX pipes. Some commands will not be able to operate in this environment; therefore, it is suggested that you use the script(1) command instead. UNIX shells will not issue prompts when run from log unless the shell is started with an explicit interactive switch (-i for most shells). For example, log foo.tmp /sbin/sh -i In the previous example, foo.tmp is the name of <logfile>. The log program intercepts end-of-file (usually Ctrl/d). Therefore programs which normally receive end-of-file as an exit command must exit by some other means. ERRORS
Log open error Explanation: The log program was unable to open <logfile>. Verify that the directory exists and that ownerships and permissions are set correctly. Exec Error Explanation: The log program was unable to execute <command>. Verify that you specified a full pathname for <command> and that <command> is an exe- cutable file. Fork Error Explanation: The log program was unable to create one of the processes it requires to log data. SEE ALSO
Commands: it(8), script(1) log(8)
All times are GMT -4. The time now is 09:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy