5 # kill_known_host: Remove an entry from the ssh hosts file.
6 # Usage: kill_known_host <IP>
7 # kill_known_host <hostname>
10 # 111 if the entry didn't exist.
11 # Notes: Based on Jim's kill-known-host.
14 my $KNOWN_HOSTS = "$ENV{HOME}/.ssh/known_hosts";
15 my $SCRATCH = "$KNOWN_HOSTS.$$";
19 print STDERR "Usage: kill_known_host <IP>\n";
20 print STDERR "Usage: kill_known_host <hostname>\n";
21 print STDERR "Exits: 0 on success.\n";
22 print STDERR " 1 on error.\n";
23 print STDERR " 111 if the entry didn't exist.\n";
30 # Check if it's an IP or a hostname.
31 if ($host =~ /^[1-9]\d{0,2}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
32 $re = "^([^\\s]+,)?$host\\s";
39 open IN, "< $KNOWN_HOSTS" or die "Can't read known_hosts: $!\n";
42 open OUT, "> $SCRATCH" or die "Can't open scratch file: $!\n";
44 my ($in, $out) = (0, 0);
57 rename $SCRATCH, $KNOWN_HOSTS or die "Can't rename $KNOWN_HOSTS: $!\n";
59 exit 111 if $in == $out;