how to sync time between two linux servers

  1. Option 1
  2. Found a way to synchronize date and time with a server over ssh which can quickly solve the problem:

    # date --set="$(ssh user@server date)"

    Or you can do it the other way around:

    # ssh user@host "date --set \"$(date)\""

  3. Option 2

  4. ‘ntpdate’
    ‘/usr/sbin/sntp -P no -r’
    Of course you need to set up a ntp or sntp server first.

passwordless ssh not working on rhel5

Was doing automation test, trying to set up passwordless ssh between the dirver and couple of test nodes. it just didn't work with one rhel5 box. Finally find the solution:

[root@perlrh5-179 .ssh]# tail -n 10 /var/log/secure
Dec 4 12:39:56 perlrh5-179 sshd[9397]: Authentication refused: bad ownership or modes for directory /root
Dec 4 12:39:59 perlrh5-179 sshd[9398]: Connection closed by

log shows the issue was the permission of the root dir

drwxrwxr-x 20 root root 4096 Nov 25 10:08 root

change it to 700 and the issue was…

find and exec

first we can use find's exec opiton

find . -name CVS -exec ls -dl {} \;

also we can use shell

for i in `find . -name CVS` ; do echo -n $i," "; done

change ls, echo to whatever suits you, like rm -rf

cmd to compare contents of two directories

diff -qr dir1 dir2

How to remove a carriage return (\r\n)

use strict;
use warnings;

my $str = "abcd\r\n";
$str =~ s/\r|\n//g;
print "[$str]";

my $str = "abcd\n";
$str =~ s/\r|\n//g;
print "[$str]";

my $str = "abcd\r";
$str =~ s/\r|\n//g;
print "[$str]";