Показ дописів із міткою shell programming. Показати всі дописи
Показ дописів із міткою shell programming. Показати всі дописи

понеділок, 11 березня 2013 р.

Using wget/curl to connect to specific server/vhost

One of DNS advantages is it's round-robin capability. But often you need to connect to specific server to specific vhost.

wget is capable of performing this task, just use --header switch:

wget http://2.2.2.2/the_url_to_test/ --header 'Host: www.example.com'
curl also can ;-)
curl --verbose --header 'Host: www.example.com''http://2.2.2.2/the_url_to_test'
Very handy features for shell programming!

References:
http://lists.gnu.org/archive/html/bug-wget/2011-03/msg00040.html
http://drewish.com/content/2010/03/using_curl_and_the_host_header_to_bypass_a_load_balancer

четвер, 7 березня 2013 р.

MySQL in scripting - using timeouts

If you are using any cron jobs with which connect to MySQL and do some work it will be wise decision to think about what will happen when MySQL daemon stops. I'll tell you! Your scripts will not be able to connect to database. And they will run until database returns.  They may run forever!
Just look into man of mysqld.

      ·   connect_timeout
           The number of seconds before connection timeout. (Default value is
           0.)
See that?! Default value is 0 - it means infinity!
No need to have such risk.
Hence quickly add the following parameter to your scripts (example below use 5 seconds timeout):
--connect_timeout=5

понеділок, 10 грудня 2012 р.

Handly shell programming using MySQL

A very handy options to use MySQL queries results in your shell scripts:

       ·   --batch, -B
           Print results using tab as the column separator, with each row on a
           new line. With this option, mysql does not use the history file.

           Batch mode results in nontabular output format and escaping of
           special characters. Escaping may be disabled by using raw mode; see
           the description for the --raw option.

       ·   --skip-column-names, -N
           Do not write column names in results.

Feel the difference!
> mysql -h localhost -e 'show status like "uptime"'
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Uptime        | 2612  |
+---------------+-------+

> mysql -h localhost  -B -N -e 'show status like "uptime"'
Uptime 2619

Refrerences: