Linux: Number of days before password expired

While creating a script to send an email alert when a linux accounts password is about to expire, we needed to determine the number of days remaining before expiry. A quick search of Google surprisingly returned only methods that access /etc/shadow, which is not possible for standard users. However, we did manage to come up with a solution.

The following can be used to echo the number of days remaining to stdout:

EXPIRE_DATE=$(chage -l $USER | awk -F ':' '/^Password expires/ { print $NF }')
[[ $(echo $EXPIRES | grep -c 'never') -gt 0 ]] && echo "never" ||  echo "( $(date -d "$EXPIRE_DATE" "+%s") - $(date +%s) ) / 86400" | bc

It’s worth mentioning the “-d” option of the date command that allows a human readable date to be passed in – and which is automatically parsed without needing to specify a format specification. Very useful!

This article was first published on http://www.dba-resources.com.

Linux: Number of days before password expires

While creating a script to send an email alert when a linux accounts password is about to expire, we needed to determine the number of days remaining before expiry. A quick search of Google surprisingly returned only methods that access /etc/shadow, which is not possible for standard users. However, we did manage to come up with a solution.

The following can be used to echo the number of days remaining to stdout:

EXPIRE_DATE=$(chage -l $USER | awk -F ':' '/^Password expires/ { print $NF }')
[[ $(echo $EXPIRES | grep -c 'never') -gt 0 ]] && echo "never" ||  echo "( $(date -d "$EXPIRE_DATE" "+%s") - $(date +%s) ) / 86400" | bc

It’s worth mentioning the “-d” option of the date command that allows a human readable date to be passed in – which is automatically parsed without needing to specify a format specification.

Very useful!

This article was first published on http://www.dba-resources.com.

Making Reflection behave like PuTTY

Around 14 years ago, I switched from using Reflection to PuTTY because it was free and my employer at the time wouldn’t pay for such extravagance software purchases such as a simple terminal emulator! Since then I’ve become rather accustomed to the way PuTTY behaves, and find Reflections particularly annoying to use on the occasion that I visit a client who insists on using it.

However, it is possible to solve most of the biggest annoyances…

Fixed font size – that doesn’t change when you resize the window:

  1. Menu > Setup > Display… > Fonts
  2. Untick the “Auto font sizing” option
  3. Change your font settings to include a size, and change the font if you want to:

 

Resizing the window changes the number of rows/columns to fit the window:

  1. Menu > Setup > View Settings…
  2. Find the “Dynamic Terminal Size” and change it to “Yes”.
  3. Find the “End of Line Wrap” option and change it to “Yes
  4. Click OK

 

Double clicking select words and paths including any underscores:

  1. Menu > Setup > View Settings…
  2. Find the “Word Boundary Exclusive” and remove the underscore from the current list of characters.
  3. Click OK

 

Right click copies and pastes the selected text:

  1. Menu > Setup > Mouse Map…
  2. Click on the picture of the right mouse button.
  3. Change the “command field” to “EditCopy EditPaste
  4. Click “Map”

 

Miscellaneous:

  • Increase the Display memory to a large number of blocks in Menu > Setup > Display > Screen…
  • Make the cursor blink by ticking “Blinks” in Menu > Setup > Display > Screen…
  • Reduce the delay between pasting characters in Menu > Setup > Display > Screen…

 

This article was first published on http://www.dba-resources.com.

Continue SCP’ing file(s) after log out

The unix command scp is very useful for transferring files between two hosts over a secure connection, but sometimes you need to kick off an scp command that will take several hours to complete and you want to disconnect and go home.

Using “screen”

One approach is to use the screen command (available only on linux AFAIK) to start the initial transfer, then detach by pressing CTRL-A followed by d.

The command will continue to run even after you have logged out, and screen has the bonus advantage that you can subsequently log back in to the machine and re-connect to the command being run at any time to see how things are progressing.

Exmpale:

oralinux001> screen
 
$ scp linuxamd64_12c_database_1of2.zip oralinux002:/oracle01/staging
<CTRL-A>
d
[detached]
 
oralinux001 > screen -ls

There is a screen on:
14623.pts-0.oralinux001 (Detached)
1 Socket in /var/run/screen/S-oracle.

To reconnect to the session, just use the -r flag (remember to detach from the screen session again as above if you want to disonnect and log out)

screen -r 14623.pts-0.oralinux001

Using “nohup”

If the screen command is not available due to the version of linux/unix being used you may be able to use the nohup command to run the scp in the background. However it does require user equivalence to be configured (negating the need to enter a password) as well as creating a temporary script and a somewhat cryptic form of nohup.
  • Ensure that you have set up user equivalence between the two hosts. This is to remove the need to specify the password for the remote host on the terminal.
  • Now put your scp command in a script (in this case called copy.ksh) and be sure to specify the flags  -q (to disable the progress meter) and -B (to run in”batch!” mode).

#!/bin/ksh
scp -q -B linuxamd64_12c_database_1of2.zip oralinux002:/oracle01/staging

  • Finally, run the script using the follwoing nohup call:
chmod 700 copy.ksh
( nohup ./copy.ksh & ) &
To test that the connection survives a log out, you should immediately log out from the system where the command was issued, and log on to the destination system. Do an ls -l a few times to ensure that the size of the files being transferred are increasing. If the size is not increasing then the command was unsuccessful (and will be in a “zombie” state on the source server).

This article was first published on http://www.dba-resources.com.

Installing FUSE on linux (for DBFS)

Filesystem in Userspace (FUSE) is a loadable kernel module for Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a “bridge” to the actual kernel interfaces. It is a pre-requisite for using Oracle DBFS.

Manual Installation

Firstly, check whether FUSE has already been installed with the following command:

lsmod | grep fuse

If it has been installed then you don’t need to continue reading!

Pre-Requisites

Ensure that the kernel development package is installed with the following command (the exact version will be displayed if it is installed):

rpm -q kernel-devel

If it is not installed, then ask your linux administrator to install  it for you.

Installing FUSE

1. Download the FUSE 2.7.3 package from http://fuse.sourceforge.net/ and transfer it onto the server.

2. Install the FUSE package as the “root” user using the following commands:

tar -xzvf fuse-2.7.3.tar.gz
cd fuse-2.7.3
./configure --prefix=/usr --with-kernel=/usr/src/kernels/`uname -r`-`uname -p`
make
make install
/sbin/depmod
/sbin/modprobe fuse
chmod 666 /dev/fuse
echo "/sbin/modprobe fuse" >> /etc/rc.modules
chmod 700 /etc/rc.modules

3. Reboot the server.

4. Check that Fuse is now available:

lsmod | grep fuse

5. Add a new library path

# Change ORACLE_HOME as appropriate for your installation 
ORACLE_HOME=/oracle/product/1120/rdbms/a
echo "/usr/local/lib" >> /etc/ld.so.conf.d/usr_local_lib.conf
ln -s $ORACLE_HOME/lib/libclntsh.so.11.1 /usr/local/lib/libclntsh.so.11.1
ln -s $ORACLE_HOME/lib/libnnz11.so /usr/local/lib/libnnz11.so
ln -s $ORACLE_HOME/bin/dbfs_client /sbin/mount.dbfs
ln -s /usr/lib/libfuse.so /usr/local/lib/libfuse.so

Reload the dynamic loadable library cache:

ldconfig

Installation is now complete.

This article was first published on http://www.dba-resources.com.

Determining network adapter speeds on linux

If you need to determine the configured speeds of the network adapters on your linux server,  the ethtool command provides the answer. You can find the speed of all your ethernet adapters with a simple unix script:

for eth in `ifconfig | grep '^eth[0-9] ' | cut -f1 -d' '` ; do 
  echo $eth: `ethtool $eth | grep Speed` 
done

This will produce output such as:

eth0: Speed: 1000Mb/s
eth1: Speed: 1000Mb/s
eth2: Speed: 1000Mb/s
eth3: Speed: 1000Mb/s
eth4: Speed: 4000Mb/s
eth5: Speed: 4000Mb/s
eth6: Speed: 4000Mb/s
eth7: Speed: 4000Mb/s

 

 

This article was first published on http://www.dba-resources.com.