awk

Awk dumps. …

Count number of bytes in multiple directories

I have been busy moveing (scp-ing/reorganising) large numer of databases over the network, this little awk script makes me able to count the number of bytes and thus check if my nighlty scp’s didn’t miss a byte. (or two) …

/cygdrive/c/oracle/oradata/DB01/DB01
$ find . -name "*DBF" -exec ls -l {} \;
-rwxrwx--- 1 Administrators SYSTEM 10493952 Oct  9 16:49 ./DB01/DATAFILE/O1_MF_TEST_3HSWQYNH_.DBF
-rwxrwx--- 1 Administrators SYSTEM 104865792 Oct  9 16:49 ./EXAMPLE01.DBF
-rwxrwx--- 1 Administrators SYSTEM 293412864 Oct  9 16:49 ./P1PERG001.DBF
-rwxrwx--- 1 Administrators SYSTEM 104865792 Oct  9 16:49 ./P1PERG002.DBF
-rwxrwx--- 1 Administrators SYSTEM 272637952 Oct 13 08:34 ./SYSAUX01.DBF
-rwxrwx--- 1 Administrators SYSTEM 513810432 Oct  9 16:49 ./SYSTEM01.DBF
-rwxrwx--- 1 Administrators SYSTEM 20979712 Oct 13 08:36 ./TEMP01.DBF
-rwxrwx--- 1 Administrators SYSTEM 47194112 Oct  9 16:49 ./UNDOTBS01.DBF
-rwxrwx--- 1 Administrators SYSTEM 5251072 Oct  9 16:49 ./USERS01.DBF

/cygdrive/c/oracle/oradata/DB01/DB01
$ find . -name "*DBF" -exec ls -l {} \; | awk '
> BEGIN { BYTES = 0 }
> { BYTES = BYTES + $5 }
> END { print "Total number of bytes = " BYTES}'
Total number of bytes = 1373511680

/cygdrive/c/oracle/oradata/DB01/DB01
$

Even shorter. …

find /m*/oradata/ai018001/ -name "*dbf" -exec ls -l {} \; | awk '{B+=$5} END {print B}'

Number format… …

find /m*/oradata/ai018001/ -name "*dbf" -exec ls -l {} \; | awk '{B+=$5} END {printf( "%d", B); print ""}'

Read more →

ls

man: NAME: ls, ls – list directory contents …

Display only directories in current directory
/cygdrive/c/temp $ ls -ld */
drwxr-xr-x+ 2 rz4tlj mkgroup-l-d 0 Sep 18 07:50 _backup_18-SEP-2007/

/cygdrive/c/temp $ 
Read more →

mailx

man: NAME: mailx, mail – interactive message processing system …

send file as attachment

Use uuencode to encode a file and pipe it to mailx to be send as attachment (when you quickly need a file on your desktop it’s faster then ftp…) …

uuencode file to mailx
$ uuencode file.txt file.txt | mailx -s file.txt <your-email-address>
$ 

In my environment the -r flag (return address) is needed since my mailserver is blocking mail without a known email address reply header. …

uuencode file to mailx with -r flag
$ uuencode file.txt file.txt | mailx -s file.txt -r <your-email-address> <your-email-address>
$ 

2012-07-22T08:28:29+00:00 …

Email yourself a list of modified (php) files automatically
One of my WordPress websites I created as a volunteer has been hacked – sunday morning ….. %^&*()
http://codex.wordpress.org/FAQ_My_site_was_hacked …

I want to email myself a list of modified php files in the last ‘N’ days to monitor if hack will comem back so I put this in my crontab.
Command below shows php files modified in the last 7 days – -mtime -7 http://content.hccfl.edu/pollock/unix/findcmd.htm …

$ find . -name "*.php" -mtime -7 -type f -print -exec ls -lart {} \;

Command below shows php files modified in the last 7 days, pipes output to mailx sending it to me …

$ find . -name "*.php" -mtime -7 -type f -print -exec ls -lart {} \; | mailx -s modifief@example.com remivisser@example.com

crontab entry to send myself lis of modifed php files
Make sure to always specify fully qualified paths in crontab. …

# m h  dom mon dow 
Read more →

nohup

man: NAME: nohup – run a command immune to hangups …

nohup and SQL*Plus

Nohup and SQL*Plus can be easily used together: …

$ nohup sqlplus -s remi/remivisser @update.sql &
[4]     14433
$ Sending output to nohup.out

$
$
Prevent password from being displayed in the ps list
$ export password=remivisser
$ nohup sqlplus -s remi/${password} @update.sql &
[8]     16768
$ Sending output to nohup.out
$
$

Read more →

pipe

man: NAME: pipe – create an interprocess channel …

import from compressed export file

Example below demonstrates how to import ‘directly’ from a compressed file. Handy when you have not enough space on your mountpoint to unpack the file. …

mknod pipe_db01 p

zcat exp.dmp.Z > pipe_db01 &

sleep 3

imp / file=pipe_db01 ... 

Same as above but now for the other compression utilities. …

(win)zip
unzip -p exp.dmp.zip > pipe_db01 &
gzip
gunzip < exp.dmp.gz > pipe_db01 &

gzip -cNf < pipe_db01 > exp.dmp.Z &
gunzip -c exp.dmp.Z > pipe_db01 &
cpio
cpio -icvdu < exp.dmp.cpio > pipe_db01 &
The other way around

Export to pipe and compress. …

$ mknod c.pipe p
$ nohup compress < c.pipe > exp_DB01_2007-10-31.dmp.Z & 
$ nohup exp system/$(cat .pwd) file=c.pipe owner=inotime log=exp_DB01_2007-10-31.log & 

Read more →

find

man: NAME: find – find files …

Find/Remove old files

Find files modified more then 365 days ago; …

find . -mtime +365 -exec ls -l {} \;

Use touch to test …

$ touch -t 197801130300 oldfile
$ find . -mtime +365 -exec rm {} \;
$ ls oldfile
ls: oldfile: No such file or directory
Read more →