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 →

Download and Install of Java (JRE) on Centos

Here’s how I installed JDK on Centos (thanks to http://www.trading-shim.org/faq/?java) …

Download

Go to http://java.sun.com/javase/downloads/index.jsp and download the desired file. …

Extract the .bin file
[root@localhost tmp]# chmod 755 j2re-1_4_2_15-linux-i586-rpm.bin
[root@localhost tmp]# ./j2re-1_4_2_15-linux-i586-rpm.bin
Install the .rpm file
[root@localhost tmp]# rpm -Uvh j2re-1_4_2_15-linux-i586.rpm
Preparing...                ########################################### [100%]
   1:j2re                   ########################################### [100%]


Adjust environment

Finally add the path to the java executable in the /etc/profile file. …

Test
$ java -version
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
View symbolic links

In my environment a symbolic link is created in /usr/bin/java which points to /usr/java/default/bin/java. …

$ which java
/usr/bin/java
$ ls -la /usr/bin/java
lrwxrwxrwx 1 root root 26 Jul 31 14:38 /usr/bin/java -> /usr/java/[strong]default[/strong]/bin/java
$ ls -la /usr/java/
total 40
drwxr-xr-x  4 root root 4096 Jul 31 14:38 .
drwxr-xr-x 14 root root 4096 Jun 14 21:03 ..
lrwxrwxrwx  1 root root   16 Jul 31 14:38 [strong]default[/strong] -> /usr/java/[strong]latest[/strong]
drwxr-xr-x  7 root root 4096 Jul 31 14:16 j2re1.4.2_15
drwxr-xr-x  9 root root 4096 Jul 31 14:38 jdk1.6.0_02
lrwxrwxrwx  1 root root   21 Jul 31 14:38 [strong]latest[/strong] -> /usr/java/jdk1.6.0_02
$

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 →

yum

‘Everythin’ about yum – Yellowdog Updater Modified. Yum is an interactive, automated update program which can be used for maintaining systems using rpm. …

Enable YUM behind a Proxy Server

To enable yum behind a proxy server add the http_proxy environment variable to you shell: …

$ export http_proxy='http://<username>:<password>@<proxyserver>:<port>'

yum update

Below is the logging of a ‘yum update’ session. …

[root@localhost ~]# yum update
Loading "installonlyn" plugin
Setting up Update Process
Setting up repositories
base                      100% |=========================| 1.1 kB    00:00
updates                   100% |=========================|  951 B    00:00
addons                    100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
Reading repository metadata in from local files
primary.xml.gz            100% |=========================| 249 kB    00:01
updates   : ################################################## 552/552
Added 25 new packages, deleted 0 old in 0.76 seconds
primary.xml.gz            100% |=========================|  62 kB    00:00
extras    : ################################################## 233/233
Added 5 new packages, deleted 0 old
Read more →

Centos 5.0 install fails, kernel panic

Centos welcome screen

The following configuration is at place, VMWare Server (1.0.3) on Windows XP (host operating system). Installation of Centos 5.0 fails with kernel panic. …

I can not get Centos 5.0 installed, I choose, Red Hat Enterprise Linux 4 as the ‘Guest Operating System’ the boot starts fine, but after a while the kernel panic errors appear and the install freezes. …

Solution (workaround)

As I did not have the time to sort this one out, I downloaded a preconfigured VM Machine CentOS 5.0 server install from thoughtpolice.co.uk, http://www.thoughtpolice.co.uk/vmware/#centos5.0 (ziparchive is 399M, extracted it is 8G). This one is running stable now, thank you thought police! Saved my day. …

Screen Captures 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 →

Configure telnet

Install and configure telnet on fresh Debian install …

Install (download) telnet

Install telnet with the apt-get utility as shown below: …

$ apt-get install telnetd
Configure telnet

Upon install the telnet server is enabled …

$ cat /etc/inetd.conf

To start telnet server issue command below. …

$ /usr/sbin/in.telnetd
$
$ netstat -a | grep telnet
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 →