2014年4月11日 星期五

xml config lookup shell scripts

例如可以用下面的scripts來查dfs.replication的設定值為何 [root@master02.dev ~]>cat ~/tttt.sh #!/bin/bash SEARCHPATH="./" if [ -z "$1" ]; then SEARCHPATH="./" else SEARCHPATH="$1" fi for file in `find $SEARCHPATH -name "*xml"` do echo $file cat $file | awk -F "\n" 'BEGIN{a=-1}{if(a < 0) { match($1 , pattern , ar); if( RSTART > 0) a=range; } if( a > 0) { a--; print markhead,$1; } }' range=2 pattern='dfs.replication' markhead='#' done [root@master02.dev process]>cd [root@master02.dev ~]>cd /var/run/cloudera-scm-agent/process [root@master02.dev process]>~/tttt.sh ./12-mapreduce-TASKTRACKER/mapred-site.xml ./12-mapreduce-TASKTRACKER/core-site.xml ./12-mapreduce-TASKTRACKER/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./13-mapreduce-JOBTRACKER/mapred-queue-acls.xml ./13-mapreduce-JOBTRACKER/fair-scheduler.xml ./13-mapreduce-JOBTRACKER/mapred-site.xml ./13-mapreduce-JOBTRACKER/core-site.xml ./13-mapreduce-JOBTRACKER/capacity-scheduler.xml ./13-mapreduce-JOBTRACKER/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./9-hdfs-NAMENODE/core-site.xml ./9-hdfs-NAMENODE/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./19-deploy-client-config/hadoop-conf/core-site.xml ./19-deploy-client-config/hadoop-conf/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./10-hdfs-DATANODE/core-site.xml ./10-hdfs-DATANODE/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./7-hdfs-NAMENODE-format/core-site.xml ./7-hdfs-NAMENODE-format/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./20-deploy-client-config/hadoop-conf/mapred-site.xml ./20-deploy-client-config/hadoop-conf/core-site.xml ./20-deploy-client-config/hadoop-conf/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./11-hdfs-NAMENODE-createtmp/core-site.xml ./11-hdfs-NAMENODE-createtmp/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value> ./8-hdfs-SECONDARYNAMENODE/core-site.xml ./8-hdfs-SECONDARYNAMENODE/hdfs-site.xml # <name>dfs.replication</name> # <value>3</value>

2013年11月20日 星期三

shell scripts for file checking at day-changed(solaris)

> su - user
> vi /home/user/meter.sh
#!/bin/bash
mday=`date +%d`
cday=`date +%Y-%m-%d`
npath="/its/cts/dat/logs/mlog/$mday"
nfile="$npath/xync.log"
#fday=`stat --format="%y" $nfile | cut -f1 -d" "`
#ls -E /etc/hosts | awk '{print $6}'| sed 's#-##g'

if [ -e $nfile ]; then
    fday=`ls -E $nfile | awk '{print $6}'` >/dev/null 2>&1
if [ $fday = $cday ]; then
    date "+%Y/%m/%d %H:%M:%S -- ...   --" >> $nfile
else
    date "+%Y/%m/%d %H:%M:%S -- Start --" > $nfile
fi

else
    date "+%Y/%m/%d %H:%M:%S -- Start --" > $nfile
fi

> chmod 755 /home/user/meter.sh
> crontab -e
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,
29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54
,55,56,57,58,59 * * * * /home/user/meter.sh 2>>/tmp/meter.log 1>>/tmp/mete
r.log

2013年10月29日 星期二

Centos 開機磁區重建

以往可能在一台電腦上安裝多個作業系統(例如CentOS+CentOS , CentOS+Windows)於不同硬碟上, 但開機的設定只能預設在一處, 當開機磁區移走時通常會遇到不能開機,以下Centos解法:
1. 找到安裝光碟
2. 以rescue mode開機, 並把原本Centos硬碟mount在/mnt/sysimage
    chroot /mnt/sysimage
    順便查一下kernel跟initrd的參數(版本)怎麼下, 可以參考原本/boot/grub/grub.conf的設定
    順便簡化它, 例如,如果指定kernel參數中root=指定/磁區, 可以把UUID改成識別符(/dev/sda3)
    如果/boot是獨立磁區, 要注意手動用grub開機的參數(見第4點說明)

3. 確定這顆Centos的硬碟的識別符是什麼(例如/dev/sda),重新安裝grub
    #grub-install /dev/sda
      Installation finished. No error reported.
      This is the contents of the device map /boot/grub/device.map.
      Check if this is correct or not. If any of the lines is incorrect,
      fix it and re-run the script `grub-install'.

      # this device map was generated by anaconda
      (hd0)     /dev/sda
 4. 此時重開機應該仍會找不到對應的開機磁區, 因為原本的grub.conf有問題,
     重開機後,會出現grub>的提示符, 假設原CentOS的磁區分配如下
     /dev/sda1    /boot
     /dev/sda2    swap
     /dev/sda3    /
    手動開機方式如下:
    grub>find //boot/grub/stage1    #尋找開機stage1的位置, 有時會不準, 尤其是/boot是獨立磁區
             (hd0,2)                           #在上面的磁區分配, 其實應該在(hd0,0)
    grub>root (hd0,0)                    #指定/boot分割區的位置
              Filesystem type is ext2fs, partition type 0x83
    grub>setup (hd0)                     #安裝開機程式(注意/boot分割區指定, 不然下次無法自動開機)
接下來如果要手動到把CentOS完全開機,就要載入kernel跟initramfs, 若不要重開機看看reboot
    grub>kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/sda3
    grub>initrd /initramfs-2.6.32-220.el6.x86_64.img
如果到這裡就沒反應,表示initrd的img檔不對, 回頭確認再試一次,(注意, 有些是initrd-2.6...)
    grub>boot
如果此時能開機成功, 回頭看一下/boot/grub/grub.conf的設定跟上面的一不一樣, 有錯的就改過來

文章分類