(Identifying data is obscured to protect the clueless.)
From an email message after someone traced data flow:
"There is a PL/SQL package in $DATABASE that this CGI script calls indirectly (CGI script executes ssh, which in turn executes sqlplus on $DATABASE_HOST, which in turn executes $SQLSCRIPT.sql script which in turn calls $STORED_PROCEDURE_NAME procedure)."
I just spent far too long diving through far too many perl scripts that use functions from a "Pushpull.pm" module. One of which is called pull. So to avoid colliding with the built-in pull, you have to call it by &pull(...). Now I understand why all that code looked like it was from the Perl 4 era....
Kill. Me. Now.
% ls -l /etc/logcheck/ignore.d.server/exim lrwxrwxrwx 1 root logcheck 23 Jan 28 06:04 /etc/logcheck/ignore.d.server/exim -> ../ignore.d.server/exim
This stupidity is not our company; our email servers can't send email to them for some reason:
% host example.com example.com is an alias for example.com. example.com is an alias for example.com. example.com is an alias for example.com.
(No, the domain in question was not actually example.com.)
I found a script today that has a lock file, which is only referenced when creating it and removing it. They even have special code to remove it when it gets a SIGINT. But nothing actually tests for its existence.
$lock_file = "/path/to/lockfile";
$SIG{'INT'} = 'INT_handler';
...snip...
#-- Create lock file before processing `touch $lock_file`;...snip...
#--Remove Lock file after processing
unlink $lock_file;
exit(0);
sub INT_handler {
print STDERR "Program Interrupted\n";
if( -f $lock_file) {
unlink $lock_file;
}
exit(-2);
}
Found in a shell script, repeated a bunch of times:
echo "Error: code $? when transfering $FILE, skip" |tee|logger -t $tag -p $priority
tee without any arguments simply copies its standard input to its standard output: it's basically cat here, which is useless.
Found in a perl script:
my $end_time = `perl -e '{print time(), "\n"}'`;
This isn't really an "unclear on the concept" — it's just very funny.
-----Original Message----- From: Cron Daemon [mailto:root@HOST] Sent: Thursday, March 18, 2010 16:31 To: root@HOST Subject: Cron <root@HOST> [ -x /usr/local/sbin/SCRIPT ] && /usr/local/sbin/SCRIPT 2>&1 /var/log/faillog: No such file or directory
This is from old monitoring code. Server is a socket. $timeout = 5. I found this when trying to figure out why this always paused for an extra 5 seconds. I include my fix as a hint as to why this is dumb.
- while (select($socketvecout=$socketvec, undef, undef, $timeout) ) {
+ if (select($socketvecout=$socketvec, undef, undef, $timeout)) {
recv(Server, $server_reply, 1500, 0)
or die "udp recv failed testing $port: $!\n";
}
+ else {
+ return "timed out waiting for response from $daemon on port $port";
+ }
Today I ran across a script with two fun examples.
First example:
DATE=`perl -e '@arr = localtime(time - 86400); printf "%04d:%02d:%02d", $arr[5]+1900, $arr[4]+1, $arr[3];'` YEAR=`echo $DATE | cut -d: -f1` MONTH=`echo $DATE | cut -d: -f2` DAY=`echo $DATE | cut -d: -f3`
This one is not totally insane, just ugly and inefficient. There are a number of ways to fix it, including a single 'eval' line:
eval `perl -e '@arr = localtime(time - 86400); printf "YEAR=%04d; MONTH=%02d ; DAY=%02d", $arr[5]+1900, $arr[4]+1, $arr[3];'`
What's interesting is that they only need $YEAR, $MONTH, and $DAY separate because of the other example from this script:
if [ ! -d $ARCHIVE_DIR/$YEAR ]
then
mkdir -p $ARCHIVE_DIR/$YEAR
fi
if [ ! -d $ARCHIVE_DIR/$YEAR/$MONTH ]
then
mkdir -p $ARCHIVE_DIR/$YEAR/$MONTH
fi
if [ ! -d $ARCHIVE_DIR/$YEAR/$MONTH/$DAY ]
then
mkdir -p $ARCHIVE_DIR/$YEAR/$MONTH/$DAY
fi
'mkdir -p' already makes any missing parent directories, and doesn't make (nor throw an error for) any directory that already exists), so this can be collapsed to
mkdir -p $ARCHIVE_DIR/$YEAR/$MONTH/$DAY
And thus both examples could be collapsed to two lines:
YMD=`perl -e '@arr = localtime(time - 86400); printf "%04d/%02d/%02d", $arr[5]+1900, $arr[4]+1, $arr[3];'` mkdir -p $ARCHIVE_DIR/$YMD
and then from then on, $YMD could be used (because the script refers only to $YEAR/$MONTH/$DAY [combined] from then on).
What, you mean Perl's print doesn't convert strftime() conversion specifiers for you automatically?
print $sendmail_fh "Date: %a, %d %b %Y %T %Z\n";
(This is printing to a pipe connected to the standard input of /usr/lib/sendmail -t. This is also my own error. Sigh.)
% ps -ef | grep "[t]ail" clueless 25624 924 0 Jul 17 ? 0:00 tcsh -c tail -f /path/to/logfile | tail -3 clueless 25660 25624 0 Jul 17 ? 5:07 tail -f /path/to/logfile clueless 25661 25624 0 Jul 17 ? 0:03 tail -3
I came across a perl script today that was entirely made up of
system("shell-command1 ARGS1");
system("shell-command2 ARGS2");
system("shell-command3 ARGS3");
and so on. Sigh.
sub getHashCount($){
my $count = 0;
for my $k (keys %{$_[0]}){
$count++;
}
return $count;
}
(As opposed to simply using
scalar(keys %hash).)
% head -6 /path/to/logroll/script # daemon's agelogs script # #!/bin/sh # $Source: /path/to/cvs/repository/for/logroll/script,v $ # $Id: script,v 1.4 2008/03/11 17:38:35 clueless Exp $ %
It's a darn good thing that /bin/sh is the default shell.
$Id: unclear-on-the-concept.html,v 1.27 2011-11-09 18:56:01 jdpaul Exp $ $Source: /home/jdpaul/repository/websrc/unclear-on-the-concept.html,v $