标签:des style http io color ar os 使用 sp
比较项目 | php | shell | perl |
变量 | 弱类型语言,变量可以任意代表任何类型 $age = 13; $name = "pengpeng"; $money = 150.53; $isBoy = true; 这里等号前后空格是为了整齐好看。 例子 <?php $age = 13; print $age; ?> 运行方式 php t.php |
弱类型语言 age=13 name="pengpeng" money=150.53 isBoy=true 注意:这里等号前后不能空格,shell的语法规则导致。 再次调用变量的时候需要加$ 符号。 例子 #!/bin/bash
age=13
echo $age
运行方式
sh t.sh
shell的逻辑变量样例
#!/bin/bash
test1=true
if $test1 ; then
echo "ok";
fi
test2=false;
if $test2 ; then
echo "false";
fi
|
弱类型语言 my $age = 13; my $name = "pengpeng"; my $money = 150.53; my $isBoy = true; 例子 #! /usr/bin/perl my $age = 13;
print $age;
运行方式
perl t.pl
|
字符串及连接 | $str1 = "str1"; $str2 = "str2"; $str3 = $str1.$str2; $str4 = $str1."test".$str2; print $str3."\n"; print $str4."\n"; |
#!/bin/bash str1="str1"; str2="str2"; str3=$str1$str2; #直接放到一起即可连接 str4=$str1"test"$str2; #直接放到一起即可连接 echo $str3; echo $str4; |
#! /usr/bin/perl my $str1 = "str1"; my $str2 = "str2";
my $str3 = $str1.$str2;
my $str4 = $str1."test".$str2;
print $str3."\n";
print $str4."\n";
|
数组遍历 | <?php
$colorArr = array(‘red‘,‘blue‘,‘green‘,‘yellow‘);
foreach ($colorArr as $color){
print $color."\n";
}
?>
|
#!/bin/bash colorArr=(‘red‘ ‘blue‘ ‘green‘ ‘yellow‘) for i in "${colorArr[@]}" ; do
echo $i
done
|
#! /usr/bin/perl my @colorArr = (‘red‘,‘blue‘,‘green‘,‘yellow‘); foreach $color(@colorArr)
{
print $color."\n";
}
|
哈希数组及遍历 | <?php
$ageArr = array(‘zhang‘=>13,‘li‘=>14,‘wang‘=>15,‘qian‘=>12);
foreach ($ageArr as $name => $age){
print "$name = $age\n";
}
?>
|
不知道 | #! /usr/bin/perl my %ageArr = (‘zhang‘=>13,‘li‘=>14,‘wang‘=>15,‘qian‘=>12); foreach my $name(keys %ageArr)
{
print "$name = ".$ageArr{$name}."\n";
}
|
条件判断 | <?php
$user=`whoami`;
if($user != "work" || ! isset($argv[1]) )
{
echo "必须是work账户,同时为./release.sh sss 或者 ./release.sh hhhh";
exit ;
}
?>
|
1.逻辑变量判断 2.逻辑表达式判断 user=`whoami`; if [ $user != "work" ] || [ ! $1 ];then
echo "必须是work账户,同时为./release.sh sss 或者 ./release.sh hhhh";
exit 0;
fi
|
#! /usr/bin/perl my $user=`whoami`; if($user != "work" || ! defined($ARGV[0]) )
{
print "必须是work账户,同时为./release.sh sss 或者 ./release.sh hhhh";
exit ;
}
|
循环 | <?php
for($i=0;$i<10;$i++)
{
print $i."\n";
}
?>
|
for((i=1;i<10;i++))
do
echo $i
done
|
for($i=0;$i<10;$i++)
{
print $i."\n";
}
|
函数定义 | <?php
function send_content_mail($maillist, $subject, $content)
{
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= ‘From:
stat@mmm.com‘ . "\r\n";
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
mail($maillist, $subject, $content, $headers);
}
send_content_mail("wenjiezeng@mmm.com", "test", "testMail");
?>
|
#!/bin/sh
function send_content_mail()
{
echo $3."有问题请咨询wenjiezeng@mmm.com" |mail -s "$2" $1
}
send_content_mail "wenjiezeng@mmm.com" "testMail" "test";
|
#!\usr\bin\perl -w
use Net::SMTP;
sub send_content_mail($$$)
{
my $to_mail = shift;
my $subject = shift;
my $content = shift;
$smtp = Net::SMTP->new(‘127.0.0.1‘); #邮件服务器地址
$smtp->to($to_mail);
$smtp->data();
$smtp->datasend("To: ".$to_mail."\n" );
$smtp->datasend("Subject: ".$subject."\n"); #主题
$smtp->datasend($content."\n");
$smtp->dataend();
$smtp->quit;
}
send_content_mail("wenjiezeng\@mmm.com","testpl","testplcontent");
|
命令行参数 | $argv <?php print_r($argv);
?>
php t.php 1 2 3
Array
(
[0] => t.php
[1] => 1
[2] => 2
[3] => 3
)
|
$1 $2 $3 #!/bin/sh echo $1;
echo $2;
echo $3;
|
@ARGV #!\usr\bin\perl -w use Data::Dumper;
print Dumper(@ARGV);
|
时间处理 |
date_default_timezone_set(‘PRC‘);
$today = date("Y-m-d",time());
$yesterday = date("Y-m-d",time()-86400);
$yesterday = date("Ymd",strtotime("-1 day"));
|
today=`date +%Y%m%d`;
yesterday=`date +"%Y%m%d" -d "-1 days"`;
echo $today;
echo $yesterday;
|
#!/usr/bin/perl -w
use POSIX qw(strftime);
my $today = strftime("%Y%m%d", localtime(time ));
my $yesterday = strftime("%Y%m%d", localtime(time - 24*3600));#获取昨天的日期
print $today."\n";
print $yesterday."\n";
|
小文件 按行处理 |
$cc = file_get_contents($file); $tmpArr = preg_split(‘/\r|\n/‘,$cc,-1,PREG_SPLIT_NO_EMPTY); foreach($tmpArr as $line) { //do with $line } |
for i in `cat list`
do
### $i is line
done
|
open(FILE,"<","list")||die"cannot open the file: $!\n";
@linelist=<FILE>;
foreach $eachline(@linelist){
print $eachline;
}
close FILE;
|
大文件逐行 | <?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>
|
shell尽量不要处理大文件,会很慢很耗费资源 | my $logFile = "list";
if(open(FH, ‘<‘, $logFile))
{
while(<FH>)
{
chomp;
print $_."\n";
}
close FH;
}
|
数组函数 | arsort() asort() count() krsort() ksort() | 这个我不知道 | shift() push() pop() sort() |
调试函数 | var_dump() print_r() |
这个我不知道 | #!\usr\bin\perl -w
use Data::Dumper;
print Dumper(@ARGV);
|
字符替换 | $file = preg_replace(‘/\.less$/‘,‘.css‘,$file); | file=`echo "$file"|sed s/\.less/.css/` | $file =~ s/\.less$/css/ |
输入192.168.5.12/26 返回所有ip function iprange($ip,$mask=24,$return_array=FALSE) { $corr=(pow(2,32)-1)-(pow(2,32-$mask)-1);
$first=ip2long($ip) & ($corr);
$length=pow(2,32-$mask)-1;
if (!$return_array) {
return array(
‘first‘=>$first,
‘size‘=>$length+1,
‘last‘=>$first+$length,
‘first_ip‘=>long2ip($first),
‘last_ip‘=>long2ip($first+$length)
);
}
$ips=array();
for ($i=0;$i<=$length;$i++) {
$ips[]=long2ip($first+$i);
}
return $ips;
}
$test1=iprange(‘192.168.5.12‘,26,TRUE);
//$test2=iprange(‘221.1.1.0‘,24,TRUE);
print "192.168.5.12/26<br>";
print_r($test1 ) ;
?>
|
在当前路径输出日志
function addLog($msg)
{
$now_date_day = date("Ymd", time());
$logtime = date("Ymd H:i:s", time());
$fileLog = dirname(__FILE__)."/log/myLogRS".$now_date_day.".txt";
file_put_contents($fileLog,"[".$logtime."]".$msg."\n",FILE_APPEND);
}
|
html2txt
function html2txt($document){
$search = array(‘@<script[^>]*?>.*?</script>@si‘, // Strip out javascript
‘@<style[^>]*?>.*?</style>@siU‘, // Strip style tags properly
‘@<[\/\!]*?[^<>]*?>@si‘, // Strip out HTML tags
‘@<![\s\S]*?--[ \t\n\r]*>@‘, // Strip multi-line comments including CDATA
‘@ @‘
);
$text = preg_replace($search, ‘‘, $document);
return $text;
}
|
判断是否内网ip
function is_i_ip($hostsearch) {
if (preg_match("/^127\./", $hostsearch)) {
return true;
}
if (preg_match("/^10\./", $hostsearch)) {
return true;
}
$regexp = "/^172\.((1[6-9])|(2[0-9])|(3[01]))\./";
if (preg_match($regexp, $hostsearch)) {
return true;
}
if (preg_match("/^192\.168\./", $hostsearch)) {
return true;
}
return false;
}
|
mysql命令 | 含义 |
mysql -uroot -p 输入密码 | 输入密码登陆数据库 |
show databases | 显示所有的数据库 |
use 数据库名 | 进入我们要操作的库 |
show tables; | 查看有哪些数据表 |
desc tblXXX; | 查看表的结构 |
select * from tblXXX limit 10; | 查看此表10行 |
select * from sms201406 where phone=‘15010796740‘ order by id desc limit 10\G; | |
set names utf8; | 设定数据库字符集utf8,以便显示正常 |
select | |
select DATE_FORMAT(sendtime,‘%Y-%m-%d‘), count(DATE_FORMAT(sendtime,‘%Y-%m_%d‘)) as cc from sms201406 group by DATE_FORMAT(sendtime,‘%Y-%m-%d‘) order by cc ; | 查询数据 |
show full process list; | 显示正在查询的sql的状态 |
order by | 排序 |
group by | 分组 |
max | 峰值 |
min | 最小值 |
sum | 汇总 |
avg | 均值 |
id | int(11) | 自增字段 |
insertTime | datetime | 数据插入时间 |
bw | float(9,2) | 当前带宽 Mbit/s |
insertTime | bw |
2014-06-17 10:00 | 20.77 |
2014-06-17 10:05 | 22.33 |
2014-06-17 10:10 | 21.09 |
... | ... |
每日峰值 | select DATE_FORMAT(insertTime,‘%Y-%m-%d‘) as day,max(bw) from bandWidth group by day; |
每日总流量 | select DATE_FORMAT(insertTime,‘%Y-%m-%d‘) as day,sum(bw) from bandWidth group by day; |
每日均值 | select DATE_FORMAT(insertTime,‘%Y-%m-%d‘) as day,avg(bw) from bandWidth group by day; |
Mysql中
下划线表示匹配任意字符
例
mysql> select * from student where name like‘_____‘;
假如我们要查找的名字包括5个字母,我们就可以使用特殊的字母"_"(下划线)。将列好在表student中包括5个字母学生的名字
例
path
0_1
0_1_2
0_1_2_3
0_1_4
0_1_6
导出 | 导入 |
mysqldump -uroot -pXXX mc roles> mc.r.sql | ./source /root/mc.r.sql |
SELECT * from tblXXX INTO OUTFILE ‘/tmp/logXXX‘ | LOAD DATA INFILE ‘/tmp/logXXX‘ INTO TABLE ‘/tmp/logXXX‘; |
标签:des style http io color ar os 使用 sp
原文地址:http://blog.csdn.net/zzz_781111/article/details/41247315