Tagged: howto RSS Toggle Comment Threads | Keyboard Shortcuts

  • diegor 3:25 pm on September 24, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: select a specific python package version using easy_install 

    easy_install” installs the latest version available of a python package. Sometime you need to use a specific version and you can install an earlier version of the package you need. For instance, if you need django 1.1.4, you’ll type:

    #> easy_install "django==1.1.4"

    Pretty simple eh?

    Questions, doubts, comments are appreciated :)

     
  • diegor 8:13 pm on September 19, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: import old logs in AWStats 

    AWStats is a great software to analyse Apache logs for having statistics about your sites. Unfortunately it doesn’t offer a tool to import old logs into AWStats. For that I’ve created a small python script to do this. Here you go:

    import commands
    raw_data = commands.getoutput('ls -rt /var/log/apache2/wespot-access80.log.*.gz')
    logs = raw_data.splitlines()
    for log in logs:
        commands.getoutput('zcat %s > /tmp/tmplog' % log)
        commands.getoutput('/usr/lib/cgi-bin/awstats.pl -update -config=config.site.com -LogFile=/tmp/tmplog')

    If you have problems, comment this post! :)

     
    • Andrea Corbellini 11:09 pm on September 19, 2011 Permalink | Reply

      Hi! AWStats ships with a tool (logresolvemerge.pl) which does exactly the same thing. Also, I think the best way to use the script is not via a temporary file, but specifying something like this in the configuration:

      LogFile=”…/awstats-7.0/tools/logresolvemerge.pl …/access.log* |”

      The pipe symbol tells AWStats to read logs from the output of the command instead of from a file.

      [This is with AWStats 7.0, I don't know about older versions]

      • diegor 10:51 am on September 20, 2011 Permalink | Reply

        Thanks Andrea for your suggestion! When I used AWStats, there wasn’t any tool to do that, so I created my own :)

  • diegor 6:06 pm on July 29, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: rename all files in lowercase 

    Pretty simple.

    1. If you don’t have a *NIX operating system, please skip this post.
    2. Create a script with this content:
      #!/bin/sh
      for f in *; do
      g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
      mv -n "$f" "$g"
      done

      and call it “rename.sh”

    3. Give it execution permissions, typing:
      chmod u+x rename.sh
    4. Execute the script from the directory where you have your files to rename
    If you have two files, “Foo” and “foo“, you’ll be notified and no files will be overwritten. So, don’t worry about that, you won’t lose any information. To be sure, try it with a few files in “/tmp” directory.
    Question? Suggestion? Comment! :)

     

     
    • Luca De Vitis 6:26 pm on July 29, 2011 Permalink | Reply

      ls -1 | while read file ; do mv -nv “${file}” “$(echo “${file}” | tr ‘[A-Z]‘ ‘[a-z]‘)” ; done

      • diegor 6:53 pm on July 30, 2011 Permalink | Reply

        Hi Luca, thanks for the trick.
        I tried but it doen’t work.. I have this:

        “namefile not overwritten”

        It works only if I drop “-n” option from mv command (too risky!!)

  • diegor 3:14 pm on June 18, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: postgresql on Dremhost Private Server 

    If you have a PS with DreamHost and you need to use PostgreSQL as database, you’ll see that’s impossible to login with postgres user and so you won’t able to use PostgreSQL.
    Dreamhost supports officially only MySQL, so they don’t provide any info about PostgreSQL.
    Anyway the problem of using PostgreSQL in DH’s PS is permit the login to postgres user. Follow this two steps:

    1. Become root, typing:
      #>sudo su
    2. Edit /etc/passwd file and find the line containing postgres. Change it from:
      postgres:x:32:32:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/false

      to:

      postgres:x:32:32:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash

    Now you can become postgres user and you can use PostgreSQL.
    Doubts? Comment! :)

    PS: Are you looking for a serious, riable and fast hosting? So Dreamhost is for you! Use Dreamhost promo code “DIEGOR” or click on this link to get 50$ off right now!

     
    • jack1852 5:16 pm on June 18, 2011 Permalink | Reply

      Domanda forse stupida: cos’è che viene cambiato rispetto a prima? (sappi che non ho un hosting su Dreamhost, solo curiosità linuxiana :P )

      • diegor 11:17 pm on June 19, 2011 Permalink | Reply

        La cosa che cambia è il comando da eseguire al login. Ho editato il post. Grazie per la precisazione.

        • jack1852 6:28 pm on June 20, 2011 Permalink | Reply

          In pratica abiliti la possibilità di login dell’utente postgres. Dovrebbe funzionare anche il comando (sempre da root): usermod -s /bin/bash postgres ;)

  • diegor 11:40 am on June 13, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: using telnet to make HTTP request 

    Telnet is an old utility used in local network to offer a bidirectional communication text-oriented using a terminal. Can be used also to make an http call to a remote server with the purpose of testing. Let’s see how:

    1. Open you favorite terminal
    2. Type (instead of diegor.it you can choose whatever server you want)
      #> telnet diegor.it 80

      and you should have as output:

      Trying 75.119.192.123...
      Connected to diegor.it.
      Escape character is '^]'.
    3. Now type:
    4. GET / HTTP/1.1
      host: diegor.it
      <line feed>

      where “/” is the remote path. In this case we want the root. The output looks like this below:

      HTTP/1.1 200 OK
      Date: Mon, 13 Jun 2011 09:06:43 GMT
      Server: Apache
      Cache-Control: no-cache, must-revalidate, max-age=0
      Pragma: no-cache
      Expires: Wed, 11 Jan 1984 05:00:00 GMT
      Last-Modified: Sun, 12 Jun 2011 13:29:48 GMT
      Vary: Accept-Encoding
      Content-Length: 85589
      Content-Type: text/html;charset=UTF-8
      
      ...

    Pretty simple! Any questions or comments are welcome.

     
    • Paolo Bernardi 12:17 pm on June 13, 2011 Permalink | Reply

      Careful there, maybe that MaxOS X telnet is very smart, but usually the command is in the form “telnet hostname port”. So, ‘telnet http://www.diegor.it 80′ is a better way to do this, the protocol is specified by the port number. :-)

      • diegor 12:29 pm on June 13, 2011 Permalink | Reply

        I can’t get what are you saying. Where’s the “error”?

      • diegor 12:32 pm on June 13, 2011 Permalink | Reply

        Ok, now i get it. The problem is that this fucking wordpress put “http://” as prefix in www addresses

  • diegor 3:28 pm on June 12, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: ignore requests without user agent in Apache 

    A public web server could be reached by many http requests with no user agent. Apache can avoid this kind of requests. The configuration is very straightforward:

    <Directory /path/to/a/directory>
        SetEnvIfNoCase User-Agent "^-?$" noUserAgent
        Order Allow,Deny
        Allow from All
        Deny from env=noUserAgent
    </Directory>

    In this example Apache ignores all requests without user agent that are directed to /path/to/a/directory

    Any comments are appreciate.

     
  • diegor 9:45 am on May 20, 2011 Permalink | Reply
    Tags: howto   

    HOWTO: “ip_conntrack: table full, dropping packet” 

    I used to manage a server based on linux and once I had this strange message:

    #> ip_conntrack: table full, dropping packet

    One of the effects of this message is that you aren’t able to make and receive new connections.
    To solve that is enough increase ip_conntrack_max value. As first step check the current value typing:

    #> cat /proc/sys/net/ipv4/ip_conntrack_max
    65536

    Now, increase this value typing:

    #> echo 131072 > /proc/sys/net/ipv4/ip_conntrack_max

    Generally the right value of ip_conntrack_max is set to the total MB of RAM multiplied by 16. If you have 8GB RAM (8192 MB), the value should be 131072.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel

Switch to our mobile site

Powered by Google Talk Widget