Showing posts with label корисне. Show all posts
Showing posts with label корисне. Show all posts

Friday, October 14, 2011

redirect wget output to stdout



The following command runs wget and sends the output to STDOUT instead of save to a file. Sometimes it useful for testing a URL's output.
wget -q -O - http://www.example.com/file.html

-q  - Turn off Wget's output. (don't print  http-headers ans wget information)
-O - Output file .  If - is used as file, documents will be printed to  standard output, disabling link conversion

Thursday, October 13, 2011

Http request with telnet

How to do http request with telnet command: for testing www server or other reasons.
it's very simple, fo example


# telnet www.server.com 80GET / HTTP/1.0
 

don't forget twice  press enter (new line) after type "GET / HTTP/1.0"


or you can use HTTP 1.1 protocol,
# telnet www.server.com 80GET / HTTP/1.1
Host: www.server.com
 


or if you want to see only http-headers in response type HEAD instend of GET

# telnet www.server.com 80HEAD / HTTP/1.1
Host: www.server.com
 

also you can define other argument with HTTP 1.1 protocol, for example Referer, User-Agetn etc

Monday, October 3, 2011

tar: Removing leading `/' from member names

"tar: Removing leading `/' from member names "-  you can see this message when creating an archive when specify full path to file names (or direcrory), for example:

tar -cxf /home/user/backup/site.tar.gz    /var/www/
tar: Removing leading `/' from member names




it means:  tar archives don't contain absolute paths, only relative ones (in your case, relative to the root directory). so it remove leading "/' for file names.
It gives you more flexibility about where to restore files. You may want to restore files into a temporary location. The relative path makes this possible. If the file paths in the tar archive were absolute then you would have to chroot into a temporary directory in order to restore the files anywhere but their original location.


To avoid this message you can use "-P" option, wich indicate tar store full absolute path in archive. But use this option  cautiously when extracting with absolute pathnames or relative symbolic links that contain "..", because it can override original files.



Correct solution is:

  1.  go to the directory with necessary files, and then create acrive 
    cd /var/
    tar -cxf /home/user/backup/site.tar.gz www
  2. or tar can do it himself, with option "-C"
    tar -cxf /home/user/backup/site.tar.gz -C /var/ www


Tuesday, September 13, 2011

fatal: not enough arguments to satisfy format string

Деколи про роботі з awk, а саме printf виникає помилка atal: not enough arguments to satisfy format string

наприклад:
tail -5000   /var/log/nginx/access.log |awk '{ if ( $1 = IP)  printf $_ }'
....  "awk: (FILENAME=- FNR=36) fatal: not enough arguments to satisfy format string


Усунути її можна 2 способами:

  1. використовувати printf  "%s", $_   (чи printf  "%s", $1 - відповідно що саме потрібно вивести) , наприклад:
     tail -5000   /var/log/nginx/access.log |awk '{ if ($1 = IP)  printf "%s", $_ }'
  2. або можна виокристати просто print,  наприклад:
     tail -5000   /var/log/nginx/access.log |awk '{ if ($1 = IP)  print $_ }'

Monday, October 12, 2009

find exclude ( виключення в find )

Якщо з самого початку - то виникла в мене потреба стирати всі фалйи в певному каталозі, що старші ніж 2 дні,  здавалося б все дуже просто
find  /dir -type f  -exec rm {} \;

але потім настала потреба виключити з пошуку певний підкаталог , написав таке
find  /dir -type f | greo -v "/dir/notrm/  | xargs  rm

проте згодом зявилися файли з символами " та ' в іменах.. і мою послідовність команд дала збій..
прийшлося  шукати як все ж таки в find зробити виключення..
після довгих пошук вдалося знайти :

find /dir -path '/dir/notrm' -prune -o -type f -mtime +2 -exec rm {} \; 

переконаний, що і попередній варіант команди можна було б підправити і все ю запрацювало , але так мені більше подобається 

Friday, May 29, 2009

як перевірити скачаний файл ..

час від часув мене виникає потреба скачати із зовнішнього свого серверу якийсь файл (архів чи ще шось) івідповідно хочесться перевірити достовірність завантаженого файлу. Це можна зробити за допомогою команди md5sum

md5sum — програма, що дозволяє обчислювати значення хеш‐сумм (контрольних сум) файлів по алгоритму Md5. У звичайному випадку обчислені хеши виводяться (можна зберегти у файлі, для подальшого використання). У інших випадках, програма звіряє обчислені значення із значеннями збереженими у файлі (це зручно для масової перевірки цілісності файлів).

Найчастіше програма використовується для перевірки правильного завантаження файлів по мережі. Програма має безліч версій (функціональність версій може істотно розрізнятися) для різних ОС — наприклад, Gnu/linux, UNIX (напр. BSD), Microsoft Windows, MacOS.

Ключі запуску програми
md5sum [ключі] [файл]...

Якщо файл не вказаний, або як його ім'я вказаний символ -, то дані читаються з standard input.

Ключі:
-t --text — читати дані файлів в текстовому режимі (за умовчанням). Перед ім'ям файлу виводиться пропуск.
-b --binary — читати дані файлів в двійковому режимі. Перед ім'ям файлу виводиться символ *.
-c --check — звіряти обчислені значення Md5 із значеннями з файлу
--status — (лише при перевірці хешей) — виводити лише код перевірки ()
-w --warn — (лише при перевірці хешей) — запобігати про рядки (checksum lines) з неправільним форматом
--help — вивести лише довідку по ключах
--version — вивести лише інформацію про версію

і тепер виконавши на двох серверах: 

# md5sum all_mysql.gz

857eb1d6c5bc7d2c33c33e5389db999c   all_mysql.gz

я переконався що я маю точну копію архіву..