20141016
用parted对磁盘进行分区
对大于2T的磁盘无法用fdisk进行管理,需要用parted来进行分区。
对于gpt磁盘,用fdisk -l显示不出磁盘分区信息。
[root@back-hp /]# fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sda: 11999.1 GB, 11999064883200 bytes
255 heads, 63 sectors/track, 1458803 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 1 267350 2147483647+ ee GPT
可以使用parted来查看详细分区信息。
[root@back-hp /]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: DELL PERC H710 (scsi)
Disk /dev/sda: 12.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 211MB 210MB ext4 boot
2 211MB 108GB 107GB ext4
3 108GB 142GB 34.4GB linux-swap(v1)
用parted对大磁盘进行分区,下面我们新建一个5T的磁盘
[root@back-hp /]# parted /dev/sda
(parted) mkpart
Partition name? []? backup <--分区名
File system type? [ext2]? ext4 <--分区格式
Start? 142GB <--起始位置
End? 5262GB <--结束位置
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
(parted) p
Model: DELL PERC H710 (scsi)
Disk /dev/sda: 12.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 211MB 210MB ext4 boot
2 211MB 108GB 107GB ext4
3 108GB 142GB 34.4GB linux-swap(v1)
4 142GB 5262GB 5120GB backup
(parted) q
在分区完后,还需要让系统识别出磁盘分区表的变化。
传统的partprobe命令已经不太好用。会提示磁盘正在使用,无法重新加载分区表
[root@back-hp /]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
在此时,系统是检测不到sda4分区的
[root@back-hp /]# ls /dev/sda*
sda sda1 sda2 sda3
这时可以用partx -a 命令来使系统重新加载分区表
[root@back-hp /]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
再次查看就能看到新增的sda4分区了
[root@back-hp /]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4
分区完成后,还需要对磁盘进行格式化
[root@back-hp /]# mkfs.ext4 /dev/sda4
如果我们需要删除分区,可以用rm number来删除指定分区
[root@back-hp /]# parted
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: DELL PERC H710 (scsi)
Disk /dev/sda: 12.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 211MB 210MB ext4 boot
2 211MB 108GB 107GB ext4
3 108GB 142GB 34.4GB linux-swap(v1)
4 142GB 5142GB 5000GB ext4 primary
(parted) rm 4
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
(parted) p
Model: DELL PERC H710 (scsi)
Disk /dev/sda: 12.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 211MB 210MB ext4 boot
2 211MB 108GB 107GB ext4
3 108GB 142GB 34.4GB linux-swap(v1)
(parted) quit
Information: You may need to update /etc/fstab.
删除后,需要更新分区表来让系统知道已经删除了分区
[root@back-hp /]# partx -d --nr 4 /dev/sda
[root@back-hp /]# ls /dev/sda*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3
20151016
截取某段时间日志
截取2015-10-16 10:50:25 至 2015-10-16 11:00:00之间的日志
要注意,如果日志中没有2015-10-16 10:50:25这个时间点,则会截取失败
sed -n '/2015-10-16 10:50:25/,/2015-10-16 11:00:00/p' catalina.out >1050_1100.log
可用正则来匹配一个范围,如匹配10:5*:**,这样总有一个时间能够匹配到,就不会截取失败了。
sed -n '/2015-10-16 10:5[0-9]:[0-9][0-9]/,/2015-10-16 11:00:[0-9][0-9]/p' catalina.out >1050_1100.log
20160324
rsync利用ssh进行同步
由于scp传文件功能太单一,但如果两边都配置rsync又太麻烦,所以这里让rsync通过ssh来同步文件,即不需要配置rsync,又可以利用rsync客户端的一些好用的功能。
rsync -avz -e 'ssh -p 1234' --exclude=tomcat/logs/* --exclude=mobile/logs/* * root@1.2.3.4:/mnt/run
如果要让变量出现在awk的print里面,则需要用"''"两个引号将变量引起来。
# awk -F"=" '{print "'$appname'"}' iplist
aa
aa
或者用-v这种写法也可以,a传递变量,注意print里面的a不要加$符合。
# awk -F"=" -v a=$appname '{print a}' iplist
aa
aa
# awk -F"=" -v a=$appname '{print $a}' iplist <---错的
mc-hsf=10.139.51.215
aa=2.3.3.3
要让变量出现在awk的//过滤条件中时,只需要将其用''引起来即可,${appname}即为变量。
注意用-v及"''"的方式在这里是无效的
# cat iplist
mc-hsf=10.139.51.215
aa=2.3.3.3
# appname=aa
# awk -F"=" '/'${appname}'/ {print $2}' iplist
2.3.3.3
20160718
#######################
#取生产环境table及column脚本
#######################
file=nirvana_prd.sql
tab=$(cat $file | grep "CREATE TABLE " | awk -F\` '{print $2}')
for ta in $tab
do
sed -n '/^CREATE TABLE `'"$ta"'`\|^call\|^SELECT\|^CALL/{:1;/;/{p;b};N;b1}' $file >tprd.txt
aa=$(cat tprd.txt| grep '^ `' | awk -F\` '{print $2}')
echo $ta
for col in $aa
do
echo " $col"
done
done