result=$(echo "37 * 0.5" |bc)
对结果取整的话:
result_int=${result%.*}
也可以通过sed截去小数点后的值:
echo $result|sed 's/\..*//g'
作者: PuGuangH 原文链接: http://blog.sina.com.cn/s/blog_4d
PID=$1
JIFFIES=`cat /proc/$PID/stat | cut -d" " -f22`
UPTIME=`grep btime /proc/stat | cut -d" " -f2`
START_SEC=$(( $UPTIME + $JIFFIES / 100 ))
START_TIME=`date -d "
echo $START_TIME
其中PID中要传入对应的进程ID。
其中/proc/stat中的btime指的是系统的启动时间,也就是boot time,
对于一个具体的进程
/proc/$pid/stat中对应的第22项指的是该进程相对于系统启动以来的执行时间。
当我从别的目录跳转到/root/private/perl下时:[root@supersun.biz tmp]#echo $CDPATH
.:/root:/root/private/
2、自己定义变量[root@supersun.biz tmp]#pwd
/root/tmp
[root@supersun.biz tmp]#cd perl
/root/private/perl
[root@supersun.biz perl]#
同样,在使用jboss时,经常跳到/home/jboss/server/default/deploy下,次数多了就会烦人的,因此设定变量DEPLOY为/home/jboss/server/default/deployexport NAGIOS=/usr/local/nagios
[root@supersun.biz root]# cd $NAGIOS
[root@supersun.biz nagios]# pwd
/usr/local/nagios
此脚本用于可保文件内容的md5校验和及以文件stat信息以及与生成的校验数据进行对比,找好更动过的文件。脚本如下:
#!/usr/bin/perl
#
#用法:
#genmd5.pl --basedir=/etc --chksumfile=etc-chksum.dat
#genmd5.pl --basedir /private/etc --compare
use strict;
use Digest::MD5;
use IO::File;
use File::Find ();
use Getopt::Long;
#设置默认值
my $chksumfile = 'chksums.dat';
my $compare = 0;
my $basedir = '/etc';
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
GetOptions("chksumfile=s" => \$chksumfile,
"compare" => \$compare,
"basedir=s" => \$basedir);
my $chksumdata = {};
if ($compare)
{
loadchksumdata($chksumfile);
}
my $outfile = '';
if (!$compare)
{
$outfile = IO::File->new($chksumfile,"w");
}
File::Find::find({wanted => \&wanted}, $basedir);
if ($compare)
{
foreach my $file (keys %{$chksumdata})
{
print STDERR "Couldn't find $file, but have the info on record\n";
}
}
sub loadchksumdata
{
my ($file) = @_;
open(DATA,$file) or die "Cannot open check sum file $file: $!\n";
while(<DATA>)
{
chomp;
my ($filename,$rest) = split(/:/,$_,2);
$chksumdata->{$filename} = $_;
}
close(DATA);
}
sub wanted {
next unless (-f $name);
my $fileinfo = genchksuminfo($name);
if ($compare)
{
if (exists($chksumdata->{$name}))
{
if ($chksumdata->{$name} ne $fileinfo)
{
print STDERR "Warning: $name differs from that on record\n";
gendiffreport($chksumdata->{$name}, $fileinfo);
}
delete($chksumdata->{$name});
}
else
{
print STDERR "Warning: Couldn't find $name in existing records\n";
}
}
else
{
printf $outfile ("%s\n",$fileinfo);
}
}
sub gendiffreport
{
my ($orig,$curr) = @_;
my @fields = qw/filename chksum device inode mode nlink uid gid size mtime ctime/;
my @origfields = split(/:/,$orig);
my @currfields = split(/:/,$curr);
for(my $i=0;$i<scalar @origfields;$i++)
{
if ($origfields[$i] ne $currfields[$i])
{
print STDERR "\t$fields[$i] differ; was $origfields[$i],
now $currfields[$i]\n";
}
}
}
sub genchksuminfo
{
my ($file) = @_;
my $chk = Digest::MD5->new();
my (@statinfo) = stat($file);
$chk->add(@statinfo[0,1,2,3,4,5,7,9,10]);
$chk->addfile(IO::File->new($file));
return sprintf("%s:%s:%s",
$file,$chk->hexdigest,
join(':',@statinfo[0,1,2,3,4,5,9,10]));
}
用以下命令生成校验数据:
[root@supersun securety]# ./getsum.pl --basedir=/etc/ --chksumfile=etc-chksum.dat
etc-chksum.dat格式如下:
/etc/bluetooth/hcid.conf:c3fb848b5e2f57e3cd65ecd8dd766724:769:1627930:33188:1:0:0:1153336356:1163469800
/etc/bluetooth/pin:81bdf50f2025f988490024cfbd36ffb8:769:1627931:33152:1:0:0:1153336356:1163469800
校验文件:
[root@supersun securety]# ./getsum.pl --basedir=/etc --compare --chksumfile=etc-chksum.dat
Warning: /etc/fstab differs from that on record
chksum differ; was 253f53fef12b9e6fa7bc2cb3556427de,
now a8506e1f2ff5e5dcb08d93b64b1be235
inode differ; was 1629160,
now 1627820
size differ; was 1187075582,
now 1190012212
mtime differ; was 1187075582,
now 1190012212
原文请参见:http://www.ibm.com/developerworks/aix/library/au-satsystemvalidity/index.html
就是因为懒!我不想每次上传公钥到新系统上时重复那几条命令,当然也是为了高效,呵呵!在使用脚本前请更改变量$locate_key的值,将其设定为你公钥所在文件。
#!/usr/bin/perl -w为了更高效点的了解内网中mac与ip的变更情况,我写了以下脚本,在此我们可以学到如果生成彩色的输出及如果使用数组和关联数组的混合以建立复杂的数据结构。
数据文件样式:
192.168.4.99 0 00:12:3f:d2:ef:e6 WORKGROUP\6B76C16DD9D3453
我们可以使用以下命令生成原始的数据文件:
[root@supersun private]# nbtscan -m 192.168.4.0/24 |awk '{print $1"\t0\t"$3"\t"$2}' >data.mac
然后我们运行脚本,终端输出新增的IP地址及变更的数据并以红色字体打印,根据实际需要我们选择是否保存到数据文件中。