SSH
Try something like this:
ssh user@rhost 'vi /etc/passwd'
And you'll get warnings like this:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
To avoid such warnings and cleanly edit your remote
files type the following:
ssh -t user@rhost 'vi /etc/passwd'
The -t option will... (from OpenSSH man pages)
Force pseudo-tty allocation. This can be used
to execute arbitrary screen-based programs on a
remote machine, which can be very useful, e.g.,
when implementing menu services.
Multiple -t options force tty allocation, even
if ssh has no local tty.
perl
perl subroutine to send email..
$mailprogram should be your mailprogram, ie
$mailprogram = "/usr/sbin/sendmail";
&Email($title,$message);
sub Email {
my ($title, $message) = @_;
open (MAIL,"¦$mailprogram -t");
print MAIL "To: name@example.comn";
print MAIL "From: script@example.comn";
print MAIL "Subject: $titlenn";
print MAIL "$message n";
close(MAIL);
}
Want to count the number of times $word appears in $text?
my $numtimes = 0;
$numtimes++ while ($text =~ /b $word b/gx));
Need a fast way of getting rid of the second half of an array?
$#array /= 2;
GMT time Example
$now = time();
print "The local time is ", scalar(localtime($now)), "n";
print "Greenwich mean time is ", scalar(gmtime($now)), "n";
How do I print something out in color?
In general, you don't, because you don't know whether the recipient has a color-aware display
device. If you know that they have an ANSI terminal that understands color, you can use the
Term::ANSIColor module from CPAN:
use Term::ANSIColor;
print color("red"), "Stop!n", color("reset");
print color("green"), "Go!n", color("reset");
Or like this:
use Term::ANSIColor qw(:constants);
print RED, "Stop!n", RESET;
print GREEN, "Go!n", RESET;
Linux Tips
VSIZE (Virtual memory SIZE) - The amount of memory the process is
currently using. This includes the amount in RAM and the amount in
swap.
RSS (Resident Set Size) - The portion of a process that exists in
physical memory (RAM). The rest of the program exists in swap. If
the computer has not used swap, this number will be equal to
VSIZE.
What Network Services are Running?
$ netstat -atup
$ netstat -ap|grep LISTEN|less
This can be helpful to determine the services running.
Need stats on dropped UDP packets?
$ netstat -s -u
TCP
$ netstat -s -t
summary of everything
$ netstat -s
looking for error rates on the interface?
$ netstat -i
Listening interfaces?
$ netstat -l
Databases
SQL Indexes
Table scan –
Indexes usually faster than table scan
•
Clustered index
–One per table
–Primary key is usually clustered index
–Data is physically ordered by index
–Not good for data updated frequently (table must be reordered)
•
Non-clustered index
–All other indexes on table
–Unique or non-unique
–Data not physically ordered