Tuesday, April 21, 2009

Oracle SQL: Calculate date and time diff

SELECT FLOOR (a.VALUE)
|| ' days '
|| FLOOR ((a.VALUE - FLOOR (a.VALUE)) * 24)
|| ' hours and '
|| FLOOR ( ( (a.VALUE - FLOOR (a.VALUE)) * 24
- FLOOR ((a.VALUE - FLOOR (a.VALUE)) * 24)
)
* 60
)
|| ' minutes' diff
FROM (SELECT SYSDATE
- TO_DATE ('20-04-2009 13:03:00', 'DD-MM-YYYY HH24:MI:SS')
VALUE
FROM DUAL) a;

Result: 59 days 19 hours and 57 minutes

Friday, February 6, 2009

Bash: Hotkeys

  • ctrl+a : move your cursor to the beginning of the line
  • ctrl+e : move your cursor to the end of the line
  • ctrl+k : delete any characters from your cursor to the end of the line
  • ctrl+u : delete any characters from your cursor to the beginning of the line
  • ctrl+w : delete previous word
  • ctrl+t : transpose two previous characters
  • ctrl+y : yank/recover the last deletion
  • ctrl+d : delete one character at the cursor position
  • ctrl+h : delete one character before the cursor
  • ctrl+f : move forward (or use the right arrow ! :-)
  • ctrl+b : move backward (or use the left arrow ! :-)
  • ctrl+r : find character sequence in history (completion mode)
  • ctrl+g : escape from completion mode

    Tnks Web
  • ctrl-l = clear screen.
  • ctrl-r = does a search in the previously given commands so that you don't have to repeat long command.
  • ctrl-u = clears the typing before the hotkey.
  • ctrl-a = takes you to the begining of the command you are currently typing.
  • ctrl-e = takes you to the end of the command you are currently typing in.
  • esc-b = takes you back by one word while typing a command.
  • ctrl-c = kills the current command or process.
  • ctrl-d = kills the shell.
  • ctrl-h = deletes one letter at a time from the command you are typing in.
  • ctrl-z = puts the currently running process in background, the processcan be brought back to run state by using fg command.
  • esc-p = like ctrl-r lets you search through the previously given commands.
  • esc-. =gives the last command you typed.

    Tnks Web

  • Alt + < - Move to the first line in the history
  • Alt + > - Move to the last line in the history
  • Alt + ? - Show current completion list
  • Alt + * - Insert all possible completions
  • Alt + / - Attempt to complete filename
  • Alt + . - Yank last argument to previous command
  • Alt + b - Move backward a word
  • Alt + c - Capitalize the word
  • Alt + d - Delete word
  • Alt + f - Move forward a word
  • Alt + l - Make word lowercase
  • Alt + n - Search the history forwards non-incremental
  • Alt + p - Search the history backwards non-incremental
  • Alt + r - Recall command
  • Alt + t - Move words around
  • Alt + u - Make word uppercase
  • Alt + back-space - Delete backward from cursor

    Tnks Web

Thursday, February 5, 2009

VMware Server Console 1.0.x cannot connect to VMware Server on openSuSE 11.1 64 bit

VMware Server Console shows:
There was a problem connecting:

Cannot connect to host www.xxx.yyy.zzz: Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd

VMware Server Connection Refused


Check if xinetd is installed:
myserver # rpm -q xinetd
xinetd-2.3.14-129.35


Check current runlevel and check if xinetd is on in chkconfig runlevels
myserver # runlevel; chkconfig --list xinetd
N 5
xinetd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

myserver # rcxinetd start
Starting INET services. (xinetd) done
myserver # chkconfig xinetd on

myserver # chkconfig --list xinetd
xinetd 0:off 1:off 2:off 3:on 4:off 5:on 6:off


From Windows:
telnet www.xxx.yyy.zzz 904

Got response:
220 VMware Authentication Daemon Version 1.10: SSL Required, MKSDisplayProtocol:VNC

So there is a port listening


No Connection Refused anymore!

tnx web: http://communities.vmware.com/thread/115879


VMware Server Console shows a new dialog:
Login (username/password) incorrect

/var/log/messages on my VMware Server host:
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM unable to dlopen(/usr/lib/vmware/lib/libpam.so.0/security/pam_unix2.so)
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM [error: /usr/lib/vmware/lib/libpam.so.0/security/pam_unix2.so: cannot open shared object file: No such file or directory]
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM adding faulty module: /usr/lib/vmware/lib/libpam.so.0/security/pam_unix2.so
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM unable to dlopen(/lib/security/pam_warn.so)
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM [error: /lib/security/pam_warn.so: cannot open shared object file: No such file or directory]
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM adding faulty module: /lib/security/pam_warn.so
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM unable to dlopen(/lib/security/pam_deny.so)
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM [error: /lib/security/pam_deny.so: cannot open shared object file: No such file or directory]
Feb 5 13:20:09 pc2019 vmware-authd[4736]: PAM adding faulty module: /lib/security/pam_deny.so
Feb 5 13:20:09 pc2019 vmware-authd[4736]: pam_unix_auth(vmware-authd:auth): authentication failure; logname= uid=0 euid=0 tty= ruser= rhost= user=root
`


Install pam-32bit package with yast
myserver # yast -i pam-32bit

Modify /etc/pam.d/vmware-authd
vi /etc/pam.d/vmware-authd
#%PAM-1.0
#auth sufficient /usr/lib/vmware/lib/libpam.so.0/security/pam_unix2.so shadow nullok
#auth required /usr/lib/vmware/lib/libpam.so.0/security/pam_unix_auth.so shadow nullok
#account sufficient /usr/lib/vmware/lib/libpam.so.0/security/pam_unix2.so
#account required /usr/lib/vmware/lib/libpam.so.0/security/pam_unix_acct.so
auth sufficient /lib/security/pam_unix.so shadow nullok
auth required /lib/security/pam_unix_auth.so shadow nullok
account sufficient /lib/security/pam_unix.so
account required /lib/security/pam_unix_acct.so


Make softlink for ease-of-use:
ln -s /etc/init.d/vmware /usr/sbin/rcvmware

Restart VMware
myserveretc/pam.d # rcvmware restart
Stopping VMware virtual machines...
Stopping VMware services:
Virtual machine monitor done
Bridged networking on /dev/vmnet0 done
Virtual ethernet done
Starting VMware services:
Virtual machine monitor done
Virtual ethernet done
Bridged networking on /dev/vmnet0 done
Starting VMware virtual machines... done


This worked for me: no problems anymore

My var/log/messages now shows:

Feb 5 14:41:21 pc2019 vmware-authd[6601]: login from 172.16.16.252 as root
Feb 5 14:41:22 pc2019 vmware-authd[6602]: login from 172.16.16.252 as root



tnx web: http://blog.netnerds.net/2007/10/vmware-server-install-vmware-server-10-on-suse-102-x64/

Bash: Debug script

The possibility to find a problem in a bash script is to use the -x variable to bash.

What the -x variable means is quite simple, it tells the script to just echo every single line of code in the script into the standard output of the shell (generally your console). What you do is to change your normal start line of the script from this:

#!/bin/bash

Into the line below:

#!/bin/bash -x

Found on the web, Tnx

Friday, January 16, 2009

Bash: Calculate with file timestamp

Test if file is newer than yesterday 8 pm:
myfile:
myserver:/tmp # ll myfile
-rw-r--r-- 1 root root 0 Jan 16 09:47 myfile

Get timestamp of myfile:
myserver:/tmp # date -r myfile
Fri Jan 16 09:47:08 CET 2009


Get timestamp of myfile in seconds:
myserver:/tmp # date +%s -r myfile
1232095628

Yesterday 8 pm:
myserver:/tmp # date --date="`date +%F` -1 days + 20 hours"
Thu Jan 15 20:00:00 CET 2009

Yesterday 8 pm in seconds:
myserver:/tmp # date +%s --date="`date +%F` -1 days + 20 hours"
1232046000

Use BashCalc (bc) to compare the values:
pc2019:/tmp # echo "1232095628 > 1232046000" | bc
1
<-- return 1: file is newer than yesterday 8 pm

In a shellscript:
#!/bin/bash
TODAY=`date +%F`
YESTERDAY_8_PM_IN_SECONDS=`date +%s --date="$TODAY -1 days + 20 hours"`
echo "YESTERDAY_8_PM_IN_SECONDS:" $YESTERDAY_8_PM_IN_SECONDS

MYFILE="/tmp/myfile"
MYFILE_TIMESTAMP_IN_SECONDS=`date +%s -r $MYFILE`
echo "MYFILE_TIMESTAMP_IN_SECONDS:" $MYFILE_TIMESTAMP_IN_SECONDS

VAR=`echo "$MYFILE_TIMESTAMP_IN_SECONDS > $YESTERDAY_8_PM_IN_SECONDS" | bc`
echo "VAR:" $VAR

if test ${VAR} -eq 1
then
   echo "File $MYFILE is newer then yesterday 8 pm"
else
   echo "File $MYFILE is older then yesterday 8 pm"
fi


Script output:
myserver:/tmp # ./testmyfile.sh
YESTERDAY_8_PM_IN_SECONDS: 1232046000
MYFILE_TIMESTAMP_IN_SECONDS: 1232095628
VAR: 1
File /tmp/myfile is newer then yesterday 8 pm