Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

2017-06-05

Linux bash history add timestamp

1. vim ~/.bashrc
在最下方加入 HISTTIMEFORMAT='%F %T '
 - %F – expands to full date same, as %Y-%m-%d (year-month-date).
 - %T – expands to time; same as %H:%M:%S (hour:minute:seconds).

2. source ~/.bashrc

2017-04-04

Linux mount disk


Step 1. 查看硬碟資訊,發現有兩顆 /dev/vad 與 /dev/vab

[root@xxxxx tmp]# fdisk -lu

Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003a7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104855551    52426752   83  Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders, total 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Step 2. 新增磁區

[root@xxxxx tmp]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x492efa4a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit

   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4):1
First cylinder (1-1040253, default 1): default 
Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1040253, default 1040253): default 
Command (m for help): w

Step 3. 設定磁區格式 ext4
[root@xxxxx tmp]# mkfs -t ext4 /dev/vdb
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131072000 blocks
6553600 blocks (5.00%) reserved for the super user
.....

Step 4. 建立disk UUID
[root@xxxxx tmp]# tune2fs -U random /dev/vdb
tune2fs 1.41.12 (17-May-2010)

Step 5. 查看UUID
[root@xxxxx tmp]# blkid /dev/vdb

/dev/vdb: UUID="8217a44e-70f1-4f84-850d-c9e8f30ae5bb" TYPE="ext4"

Step 6. 註冊UUID
[root@xxxxx tmp]# vim /etc/fstab
UUID=b7aae0d4-268c-4b60-914a-f3b48e22819c /                       ext4    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

UUID=8217a44e-70f1-4f84-850d-c9e8f30ae5bb /project ext4


Step 6. 掛載磁區到你要的目錄
[root@xxxxx tmp]# mount -t ext4 /dev/vdb /project



完成
[root@ICN-Beta-IXBataAll01 salt]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  1.3G   46G   3% /
tmpfs           3.9G     0  3.9G   0% /dev/shm

/dev/vdb        493G   70M  467G   1% /project

2015-06-05

CentOS ssh 無法執行 java

今天發生透過Jenkins要遠端啟動shellscript, 卻無法執行的情況,
但是直接在本機端執行可以的,已有設定環境變數。

原因ssh時不會執行/etc/profile 內的環境變數

shellscript內容是去呼叫一個jar檔:
#!/bin/bash
nohup java -jar /xxx/abc.jar 2>&1

ssh遠端指令:
ssh xx@10.10.10.10 "sh /xxx/abc.sh"

解決方式:
在/etc/profile.d 底下新增一個shellscript, 名稱都可以jdk1.5.sh,
裡面加入:
export JAVA_HOME=/project/server/jdk1.5
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin


其他方式
1. 使用alternatives 
https://www.cnblogs.com/killkill/archive/2010/08/23/1806468.html

2. 使用 #!/bin/bash --login
https://bbs.csdn.net/topics/392163467

3. java 帶完全路徑
--
/etc/profile 與 /etc/profile.d 差異
.Login shell 啟動時才會運行 /etc/profile 這個腳本
/etc/profile對所有使用者生效
./etc/profile.d 存放一些應用程式所需的啟動腳本
.~/.bash_profile只對當前使用者生效
.~/.bashrc:該檔案包含專用於你的bash shell的bash資訊,當登入時以及每次開啟新的shell時,該檔案被讀取.每個使用者都有一個.bashrc檔案,在使用者目錄下