Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Thursday, February 28, 2008

housekeeping core files

since i've enabled the coreadm for all my solaris servers, i keep getting alerts on file systems full cause of fill up by those core files.



# coreadm
global core file pattern: /var/cores/%f.%n.%p.core
init core file pattern: core
global core dumps: enabled
per-process core dumps: enabled
global setid core dumps: enabled
per-process setid core dumps: enabled
global core dump logging: enabled




so i came out with this 1 liner. put in the crontab. problem solved ;)

# cd /var/cores; find . -type f -name \*core ! -name \*.gz -mtime +1 -exec gzip {} \;

find . - find files in the current directory
-type f - find only file type, not directory or link
-name \*core - find only *core filename
! -name \*.gz - skip the .gz files
-mtime +1 - files before today's date
-exec gzip {} - gzip the files

go here on how to enable the core dump: http://docs.sun.com/app/docs/doc/820-0434/6nc63qo4r?a=view

Saturday, June 03, 2006

script stdout | shell

when writing a shell script, it is important to make sure it does the correct things, especially when it come to execute the specific commands like rm etcetera. it is advisable to print out to stdout what the commands in the scripts do to make sure no typo/error made.
eg: script.sh
#! /bin/ksh
for file in *.log
do
echo rm $file
done

so when you run the script:
$ ./script.sh
rm 1.log
rm 2.log
rm 3.log

it will not execute the rm command since we only use echo. in order to execute it, no need to delete the echo but simpy pipe ( | ) it to the shell:
$ ./script.sh | sh

will delete those 3 log files.

Tuesday, March 21, 2006

script: determine variable type

i found this useful script on how to determine the variable type.
$ cat mad.ksh
#! /bin/ksh

[[ -z "$1" ]] && echo "I cant work without an input" && exit 1

INPUT="$@"

[[ "$INPUT" == ?(+|-)+([0-9]) ]] && echo "$INPUT is numeric" && exit 0

[[ "$INPUT" == +([a-zA-Z]) ]] && echo "$INPUT is character" && exit 0

[[ "$INPUT" == *([0-9]|[a-zA-Z])* ]] && echo "$INPUT is alpha-numeric" && exit 0

$ ./mad.ksh 123
123 is numeric
$ ./mad.ksh abc
abc is character
$ ./mad.ksh abc123
abc123 is alpha-numeric

i hope they don't mind i paste it here.
source: http://www.unix.com/showthread.php?t=21630&p=83968