Showing posts with label one-liner. Show all posts
Showing posts with label one-liner. 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, May 20, 2006

one-liner to check disk/file systems usage

as requested by my friend, here is the one-liner to check disk/file systems usage that exceed certain percentage:
$ df -k | sed -e 's/%//g' | awk '{if ($5 > 70) print $1 " " $5 " " $6}'
Filesystem capacity Mounted
/dev/md/dsk/d0 82 /
/dev/md/dsk/d8 78 /home

change 70 to any number that suite your need.

Wednesday, December 21, 2005

unix tip: one-liner find files with different regex

instead of we type find a few times, we can use -o option.
eg:

$ find . -name "*ksh" -o -name "*txt"
./.mozilla/default/nxdv20h2.slt/cookies.txt
./scripts/sham.ksh
./scripts/java.txt
./scripts/ii.ksh
./scripts/aa.ksh
./scripts/input.txt
./scripts/output.txt
./scripts/test.ksh
./scripts/tiktok.ksh
./scripts/file.txt
./download/firefox-installer/license.txt
./sample.txt

Tuesday, November 29, 2005

unix tip: one-liner find & replace string

normally people use sed to find & replace string.
eg:

$ cat test
abc def xyz 123 456 789
$ sed 's/abc/123/g' test
123 def xyz 123 456 789

but the output is sent to stdout (the screen) not to the file unless you redirect it to new file.
you can use perl to do that.
eg:

$ cat test
abc def xyz 123 456 789
$ perl -pi -e 's|abc|123|g' test
$ cat test
123 def xyz 123 456 789

to backup the original file use -pi.bak option & your original file will be saved as .bak