UnixTips.net

* use my tips at your own risk !!

* use my tips at your own risk !!

Categories

  • Other (3)
  • Scripting (10)
  • Unix (70)
  • Wordpress (2)

Powered by Genesis

The nc command

To test a connection use nc

# nc -vz myhost 22 -w 15 > /dev/null 2>&1

-w 15 is the timeout

Will return 0 if the host connects on ssh port 22
or 1 if it does not connect.

Updated: 03/29/2016

The new update to the nc command takes this option away.

Instead the following will work

timeout 60s /bin/bash -c 2>/dev/null >/dev/tcp/myhost/22

Test port connection
*from the man pages

On one console, start nc listening on a specific port for a connection.

# nc -l 1234

nc is now listening on port 1234 for a connection. On a second console (or a second machine), connect to the machine and port being listened on:

# nc 127.0.0.1 1234

There should now be a connection between the ports. Anything typed at the second console will be concatenated to the first, and vice-versa. The connection may be terminated using an EOF.

crontab -e hangs

I have only seen this on solaris

# crontab -e
446

simple fix

# export EDITOR=vi 

Host key verification failed ssh scp using cron

I was getting the following error when a script was being executed via cron.

Host key verification failed.
lost connection

But when the script was executed manually from the command line it worked without any issues.

* This worked for me in my particular case. This may not work in every case.

I added the following statements to the script and then ran it from cron.

which scp
which ssh

The output from the two which commands :

/usr/bin/scp
/usr/bin/ssh

What this told me was that the PATH I set in my cron script was forcing the script to use the scp and ssh commands in /usr/bin.

When I ran the same commands from the command line it became clear that it worked without any issues using ssh and scp in /usr/local/bin.

# which ssh;which scp
/usr/local/bin/ssh
/usr/local/bin/scp

My fix was to specify which scp and ssh the script should use.

Before:

scp
ssh

After:

/usr/local/bin/scp
/usr/local/bin/ssh

Hung Solaris Zone : shutting_down state

I had a zone stuck in shutting_down state.

No matter what I did I was not able to shut it down.

But this worked.

# ps -fz myzone
     UID   PID  PPID   C    STIME TTY         TIME CMD
    root  2850     1   0   Jul 22 ?           0:00 zsched
 0040620 18081     1   0        - ?        2529:10 defunct

The problem was that I had a process on the zone that was defunct.

After several kill -9 the defunct process finally died and my zones shutdown and rebooted.

NOTE: YOU SHOULD NOT KILL zsched.

Yum Commands

list packages

yum list

install package

yum install 

Yum Cheat Sheet
http://yum.baseurl.org/wiki/YumCommands

  • 1
  • 2
  • 3
  • …
  • 14
  • Next Page »