2016年6月28日 星期二

[Linux][Generate Random Mac Address]

echo -n 00:60:2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 ":%02X"'

Output will be like "00:60:2F:7A:ED:D0".

If you want "00-60-2F-7A-ED-D0", just change the symbol ":" to "-" in the command.

Reference:
http://superuser.com/questions/218340/how-to-generate-a-valid-random-mac-address-with-bash-shell

2014年12月18日 星期四

[Windows][Create simple volume]

In fact, this method is try and error.

I'm now using Windows Server 2012, and, hmm, no need to say too much, just give the method.

1) Have two unused disks.

2) In "Disk Management", use "New Spanned Volume".

3) Use those two disks to create a volume. (Just default, default, next step, next step, finish)

4) Now we have a new volume which composed by two disks.

5) Use "Shrink Volume".

6) Enter a value which is bigger than the size of latter disk, for example, 20 GB + 20 GB, and the value may be 25 GB. Oh, the unit is MB.

7) Now we have a simple volume based on the former disk.

8) It doesn't matter to "Extend Volume" to re-allocate the un-allocated space to the simple volume, it will still be a simple volume. But if you select another disk, it will be spanned volume.

2014年10月21日 星期二

Timezone category.

Because of something, I make a comparison table between "GMT" and the areas in it.
* Not all, but I think it's sufficient.
* This is in Python dict format.
* I discard something like ".5" or ".8" and put those areas in the nearest ".0", such as "Caracas", "St_Johns" and so on.

timezone_list = {
    '-12': [],
    '-11': ['US/Samoa', 'Pacific/Midway', 'Pacific/Niue', 'Pacific/Pago_Pago', 'Pacific/Samoa', ],
    '-10': ['US/Aleutian', 'US/Hawaii', 'HST', 'Pacific/Honolulu', 'Pacific/Johnston', 'Pacific/Rarotonga', 'Pacific/Tahiti', ],
    '-9' : ['US/Alaska', 'America/Adak', 'America/Atka', 'America/Juneau', 'America/Nome', 'America/Yakutat', 'Pacific/Gambier', 'Pacific/Marquesas', ],
    '-8' : ['America/Anchorage', 'America/Dawson', 'America/Los_Angeles', 'America/Tijuana', 'America/Vancouver', 'America/Whitehorse', 'Pacific/Pitcairn', ],
    '-7' : ['US/Arizona', 'US/Mountain', 'US/Pacific', 'America/Dawson_Creek', 'America/Ensenada', 'America/Hermosillo', 'America/Inuvik', 'America/Mazatlan', 'America/Phoenix', 'America/Shiprock', 'America/Yellowknife', 'Canada/Pacific', 'Canada/Yukon', 'PST8PDT', 'Mexico/BajaNorte', ],
    '-6' : ['America/Belize', 'America/Boise', 'America/Cambridge_Bay', 'America/Chihuahua', 'America/Costa_Rica', 'America/Denver', 'America/Edmonton', 'America/El_Salvador', 'America/Guatemala', 'America/Indiana/Knox', 'America/Managua', 'US/Indiana-Starke', 'America/Menominee', 'America/Merida', 'America/Mexico_City',  'America/Monterrey', 'America/Rainy_River', 'America/Rankin_Inlet', 'America/Regina', 'America/Swift_Current', 'America/Tegucigalpa', 'America/Winnipeg', 'Canada/East-Saskatchewan', 'Canada/Mountain', 'Canada/Saskatchewan', 'MST', 'MST7MDT', 'Mexico/BajaSur', 'Pacific/Galapagos', 'US/Navajo', ],
    '-5' : ['US/Central', 'US/Eastern', 'US/Michigan', 'America/Bogota', 'America/Cancun', 'America/Cayman', 'America/Chicago', 'America/Eirunepe', 'America/Grand_Turk', 'America/Guayaquil', 'America/Havana', 'America/Indiana/Indianapolis', 'America/Indiana/Marengo', 'America/Indiana/Vevay', 'America/Iqaluit', 'America/Jamaica', 'America/Kentucky/Louisville', 'America/Kentucky/Monticello', 'America/Knox_IN', 'America/Lima', 'America/Montreal', 'America/Nassau', 'America/New_York', 'America/Nipigon', 'America/Panama', 'America/Pangnirtung', 'America/Port-au-Prince', 'America/Porto_Acre', 'America/Thunder_Bay', 'Brazil/Acre', 'CST6CDT', 'Canada/Central', 'Chile/EasterIsland', 'Mexico/General', 'Pacific/Easter', ],
    '-4' : ['US/East-Indiana', 'America/Anguilla', 'America/Antigua', 'America/Aruba', 'America/Barbados', 'America/Boa_Vista', 'America/Caracas', 'America/Curacao', 'America/Detroit', 'America/Dominica',  'America/Fort_Wayne', 'America/Goose_Bay', 'America/Grenada', 'America/Guadeloupe', 'America/Guyana', 'America/Halifax', 'America/Indianapolis', 'America/La_Paz', 'America/Louisville', 'America/Manaus', 'America/Martinique', 'America/Montserrat', 'America/Port_of_Spain', 'America/Porto_Velho', 'America/Puerto_Rico', 'America/Santiago', 'America/Santo_Domingo', 'America/St_Kitts', 'America/St_Lucia', 'America/St_Thomas', 'America/St_Vincent', 'America/Thule', 'America/Tortola', 'America/Virgin', 'Antarctica/Palmer', 'Brazil/West', 'Canada/Eastern', 'Cuba', 'EST', 'EST5EDT', ],
    '-3' : ['America/Araguaina', 'America/Asuncion', 'America/Belem', 'America/Buenos_Aires', 'America/Catamarca', 'America/Cayenne', 'America/Cordoba', 'America/Cuiaba', 'America/Fortaleza', 'America/Glace_Bay', 'America/Godthab', 'America/Jujuy', 'America/Maceio', 'America/Mendoza', 'America/Miquelon', 'America/Montevideo', 'America/Paramaribo', 'America/Recife', 'America/Rosario', 'America/Sao_Paulo', 'America/St_Johns', 'Atlantic/Bermuda', 'Atlantic/Stanley', 'Canada/Atlantic', 'Chile/Continental', ],
    '-2' : ['America/Noronha', 'Atlantic/South_Georgia', 'Brazil/DeNoronha', 'Brazil/East', 'Canada/Newfoundland', ],
    '-1' : ['America/Scoresbysund', 'Atlantic/Cape_Verde', ],
    '+0' : ['Africa/Abidjan', 'Africa/Accra', 'Africa/Bamako', 'Africa/Bissau', 'Africa/Conakry', 'Africa/Dakar', 'Africa/Freetown', 'Africa/Lome', 'Africa/Nouakchott', 'Africa/Banjul', 'Africa/Monrovia', 'Africa/Ouagadougou', 'Africa/Sao_Tome', 'Africa/Timbuktu', 'Atlantic/Azores', 'Atlantic/Reykjavik', 'Atlantic/St_Helena', 'GMT', 'Greenwich', 'Iceland', 'UCT', 'UTC', 'Universal', 'Zulu',  ],
    '+1' : ['Africa/Algiers', 'Africa/Bangui', 'Africa/Brazzaville', 'Africa/Casablanca', 'Africa/Douala', 'Africa/Kinshasa', 'Africa/Lagos', 'Africa/Libreville', 'Africa/Luanda', 'Africa/Ndjamena', 'Africa/Niamey', 'Africa/Porto-Novo', 'Africa/Tunis', 'Africa/El_Aaiun', 'Africa/Malabo', 'Arctic/Longyearbyen', 'Atlantic/Canary', 'Atlantic/Faeroe', 'Atlantic/Madeira', 'Eire', 'GB', 'GB-Eire', 'Portugal', 'Europe/Belfast', 'Europe/Dublin', 'Europe/Lisbon', 'Europe/London', ],
    '+2' : ['Africa/Bujumbura', 'Africa/Cairo', 'Africa/Harare', 'Africa/Johannesburg', 'Africa/Kigali', 'Africa/Lubumbashi', 'Africa/Lusaka', 'Africa/Maputo', 'Africa/Maseru', 'Africa/Tripoli', 'Africa/Windhoek', 'Africa/Blantyre', 'Africa/Ceuta', 'Africa/Gaborone', 'Africa/Mbabane', 'Asia/Gaza', 'Asia/Nicosia', 'Atlantic/Jan_Mayen', 'CET', 'Egypt', 'Libya', 'MET', 'Poland', 'WET', 'Europe/Amsterdam', 'Europe/Andorra', 'Europe/Belgrade', 'Europe/Berlin', 'Europe/Bratislava', 'Europe/Brussels', 'Europe/Budapest', 'Europe/Copenhagen', 'Europe/Gibraltar', 'Europe/Ljubljana', 'Europe/Luxembourg', 'Europe/Madrid', 'Europe/Malta', 'Europe/Monaco', 'Europe/Oslo', 'Europe/Paris', 'Europe/Prague', 'Europe/Rome', 'Europe/San_Marino', 'Europe/Sarajevo', 'Europe/Skopje', 'Europe/Stockholm', 'Europe/Tirane', 'Europe/Vaduz', 'Europe/Vatican', 'Europe/Vienna', 'Europe/Warsaw', 'Europe/Zagreb', 'Europe/Zurich', ],
    '+3' : ['Africa/Addis_Ababa', 'Africa/Asmera', 'Africa/Dar_es_Salaam', 'Africa/Djibouti', 'Africa/Kampala', 'Africa/Mogadishu', 'Africa/Nairobi', 'Africa/Khartoum', 'Antarctica/Syowa', 'Asia/Aden', 'Asia/Amman', 'Asia/Baghdad', 'Asia/Beirut', 'Asia/Damascus', 'Asia/Jerusalem', 'Asia/Kuwait', 'Asia/Riyadh', 'Asia/Riyadh87', 'Asia/Riyadh88', 'Asia/Riyadh89', 'Asia/Bahrain', 'Asia/Istanbul', 'Asia/Qatar', 'Asia/Tehran', 'Asia/Tel_Aviv', 'EET', 'Iran', 'Israel', 'Turkey', 'Europe/Athens', 'Europe/Bucharest', 'Europe/Chisinau', 'Europe/Helsinki', 'Europe/Istanbul', 'Europe/Kaliningrad', 'Europe/Kiev', 'Europe/Minsk', 'Europe/Nicosia', 'Europe/Riga', 'Europe/Rome', 'Europe/Sofia', 'Europe/Tallinn', 'Europe/Tiraspol', 'Europe/Uzhgorod', 'Europe/Vilnius', 'Europe/Zaporozhye', 'Indian/Antananarivo', 'Indian/Comoro', 'Indian/Mayotte', ],
    '+4' : ['Asia/Baku', 'Asia/Dubai', 'Asia/Kabul', 'Asia/Muscat', 'Asia/Tbilisi', 'Asia/Yerevan', 'W-SU', 'Europe/Moscow', 'Europe/Samara', 'Europe/Simferopol', 'Indian/Mahe', 'Indian/Mauritius', 'Indian/Reunion', ],
    '+5' : ['Antarctica/Mawson', 'Asia/Aqtau', 'Asia/Aqtobe', 'Asia/Ashgabat', 'Asia/Ashkhabad', 'Asia/Calcutta', 'Asia/Colombo', 'Asia/Dushanbe', 'Asia/Karachi', 'Asia/Oral', 'Asia/Samarkand', 'Asia/Tashkent', 'Indian/Kerguelen', 'Indian/Maldives', ],
    '+6' : ['Asia/Almaty', 'Asia/Bishkek', 'Asia/Dacca', 'Asia/Dhaka', 'Asia/Kathmandu', 'Asia/Qyzylorda', 'Asia/Rangoon', 'Asia/Thimbu', 'Asia/Thimphu', 'Asia/Urumqi', 'Asia/Yekaterinburg', 'Indian/Chagos', 'Indian/Cocos', ],
    '+7' : ['Antarctica/Davis', 'Asia/Bangkok', 'Asia/Hovd', 'Asia/Jakarta', 'Asia/Novosibirsk', 'Asia/Omsk', 'Asia/Phnom_Penh', 'Asia/Saigon', 'Asia/Vientiane', 'Indian/Christmas', ],
    '+8' : ['Antarctica/Casey', 'Asia/Brunei', 'Asia/Chungking', 'Asia/Harbin', 'Asia/Hong_Kong', 'Asia/Kashgar', 'Asia/Krasnoyarsk', 'Asia/Kuala_Lumpur', 'Asia/Kuching', 'Asia/Macao', 'Asia/Macau', 'Asia/Makassar', 'Asia/Manila', 'Asia/Shanghai', 'Asia/Singapore', 'Asia/Taipei', 'Asia/Ujung_Pandang', 'Asia/Ulaanbaatar', 'Asia/Ulan_Bator', 'Australia/Perth', 'Australia/West', 'PRC', 'ROC', 'Asia/Beijing', ],
    '+9' : ['Asia/Dili', 'Asia/Irkutsk', 'Asia/Jayapura', 'Asia/Pyongyang', 'Asia/Seoul', 'Asia/Tokyo', 'Australia/Darwin', 'Australia/North', 'Japan', 'ROK', 'Pacific/Palau', ],
    '+10': ['Antarctica/DumontDUrville', 'Asia/Yakutsk', 'Australia/Adelaide', 'Australia/Brisbane', 'Australia/Broken_Hill', 'Australia/Lindeman', 'Australia/Queensland', 'Australia/South', 'Australia/Yancowinna', 'Pacific/Guam', 'Pacific/Port_Moresby', 'Pacific/Saipan', 'Pacific/Truk', 'Pacific/Yap'],
    '+11': ['Asia/Vladivostok', 'Australia/ACT', 'Australia/Canberra', 'Australia/Hobart', 'Australia/LHI', 'Australia/Lord_Howe', 'Australia/Melbourne', 'Australia/NSW', 'Australia/Sydney', 'Australia/Tasmania', 'Australia/Victoria', 'Pacific/Efate', 'Pacific/Guadalcanal', 'Pacific/Kosrae', 'Pacific/Norfolk', 'Pacific/Noumea', 'Pacific/Ponape', ],
    '+12': ['Antarctica/McMurdo', 'Antarctica/South_Pole', 'Asia/Anadyr', 'Asia/Kamchatka', 'Asia/Magadan', 'Pacific/Fiji', 'Pacific/Funafuti', 'Pacific/Kwajalein', 'Pacific/Majuro', 'Pacific/Nauru', 'Pacific/Tarawa', 'Pacific/Wake', 'Pacific/Wallis', ],
    '+13': ['NZ', 'NZ-CHAT', 'Pacific/Auckland', 'Pacific/Chatham', 'Pacific/Enderbury', 'Pacific/Fakaofo', 'Pacific/Tongatapu', ],
    '+14': ['Pacific/Apia', 'Pacific/Kiritimati', ],
}

If there's anything wrong, please inform me, thank you.

Reference:
http://localtimes.info/
http://www.timeanddate.com/worldclock/
http://www.zeitverschiebung.net/en/all-time-zones.html
http://www.travelmath.com/time-zone/
http://www.worldtimeserver.com/

2014年7月22日 星期二

[Linux][Samba][Get Whole Folder with Smbclient]

1. Connect to Samba by using Smbclient.

2. Go to the parent directory of the folder you would like to get.

3. smb: \> tarmode

4. smb: \> recurse

5. smb: \> prompt

6. smb: \> mget <Folder>

Ref: Indradjy's Blog

2014年5月15日 星期四

[Linux][Install PyCharm]

01. Download jdk from Oracle website.
02. tar zxvf jdk-7u55-linux-x64.tar.gz
03. sudo mkdir /usr/lib/jdk
04. cp -r jdk1.7.0_55 /usr/lib/jdk
05. sudo vi /etc/profile
      + export JAVA_HOME=/usr/lib/jdk/jdk1.7.0_55
      + export JRE_HOME=/usr/lib/jdk/jdk1.7.0_55/jre
      + export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
      + export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
06. Change the default value.
      sudo update-alternatives --install /usr/bin/java java /usr/lib/jdk1.7.0_55/bin/java 300
      sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jdk1.7.0_55/bin/javac 300
      sudo update-alternatives --config java
      sudo update-alternatives --config javac
07. Reboot
08. java -version
      java version "1.7.0_55"
      Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
09. Download PyCharm.
10. tar zxvf pycharm-community-3.1.3.tar.gz
11. sh pycharm-community-3.1.3/bin/pycharm.sh

2014年4月10日 星期四

[Script][Bash + AWK + CURL]

[抓副檔名]
FILE_EXT="`echo ${FILE} | awk -F '.' '{if (NF>1) {print $NF}}'`"

[抓名稱]
NAME="abcd"
NAME="`awk -F '=' '/NAME/ {print $2}' ${CFG} | xargs echo -e`"

[找 symlink]
find . -type l

[用 curl 透過 FTP 傳一整個資料夾到 FTP Server]
find <PATH TO DIR> -type f -exec curl -u <USER NAME>:<PASSWORD> --ftp-create-dirs -T {} ftp://<FTP IP>/{} \;

[用 curl 透過 FTP 刪除遠端資料]
curl -u <USER NAME>:<PASSWORD> -Q "DELE <PATH TO FILE FROM FTP ROOT>" ftp://<FTP IP>

[用 curl 透過 FTP 更改遠端資料權限]
curl -u <USER NAME>:<PASSWORD> -Q "SITE CHMOD 777 <PATH TO FILE FROM FTP ROOT>" ftp://<FTP IP>

[用 curl 獲取遠端有的資料並只刪掉 .tar.gz 檔]
Ref: http://help.directadmin.com/item.php?id=487 

[用 source 一次讀進所有設定檔]
<product.cfg 的內容>
NAME="zqpm"
AGE="26"

source product.cfg 會得到 NAME 和 AGE 兩個變數,並且各自有其值。

2013年11月24日 星期日

[Bash][Redirect 多了個 newline]

好久沒寫 Blog 了。(題外話)

這兩天在拿 The C Programming Language 的習題當練習。

碰到一個問題。

一個程式叫 TARGET 可以計算檔案的 blank、tab、newline、character 數。

我用 ./TARGET < test.txt 進行測試。

每次 newline 的個數都會多一。

不知道是不是 "<" 造成的。

=================================================================

後來乾脆直接把讀到的 char 進行判別後印出來。

發現用 "<" 的話會把 test.txt 的資料直接倒過去 TARGET,然後在最末端加上 newline。

所以用 "<" 或 ">" 時它不止幫忙把資料做 redirect,最後還會 "貼心" 的加個 newline。

好,問題解決。