Updates from March, 2011 Toggle Comment Threads | Keyboard Shortcuts

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

    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: 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: 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 3:28 pm on June 12, 2011 Permalink | Reply
    Tags:   

    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: “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.

     
  • diegor 1:00 pm on March 11, 2011 Permalink | Reply
    Tags:   

    HOWTO: make vim show ending line spaces as characters 

    When you edit a file with vim, it’s useful understand where the line ends especially if there are spaces at the end of the line. Instead checking all lines, you can highlight white spaces. How?

    1. Open Vim from Terminal
    2. type
      :set list
    3. You see an output like the one below
    4. If you want see each space as character, type this command
      :set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
    5. The output should look like below

    Very simple and useful tip! :)

    If you have any doubt, advice or something else, comment this post! :)

    Source: Stackoverflow

     
    • proudlygeek 1:43 pm on March 11, 2011 Permalink | Reply

      Vim is my favourite text editor, i use it pretty anywhere :-)

      I’ll share a useful trick for commenting multiple lines of code:

      1) SHIFT-V to select multiple lines;
      2) Type “:s/^/#”

      Where “^” indicates the beginning of a line and “#” the comment symbol of your choice.

      To decomment a block of code:

      1) Shift-V
      2) Type “:s/^#//”

  • diegor 7:58 pm on March 4, 2011 Permalink | Reply
    Tags:   

    HOWTO: run cron job in seconds 

    If you know what cron is, you also know that the minimum time to execute a job is a minute. There is a small tip to execute a cron job every X seconds. For example if you need to run a cron job every 30 seconds (it’s a common case), you can do it adding these lines to crontab:

    * * * * * root sh /path/to/myscript.sh
    * * * * * root sleep 30 && sh /path/to/myscript.sh

    Both lines execute the job every minute, but the second one waits 30 seconds using “sleep” command from bash.

    If you have any question, comment this post. :)

     
    • Andrea 4:01 pm on July 24, 2011 Permalink | Reply

      Very nice guide! It’s very tricky. Anyway do you know some implementation of a scheduler such cron that deals with seconds instead of minutes?

    • diegor 11:17 pm on July 24, 2011 Permalink | Reply

      Mmm, sorry I don’t know any scheduler except cron..

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