Updates from January, 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 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 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..

  • diegor 7:53 pm on January 17, 2011 Permalink | Reply
    Tags:   

    HOWTO: fix offending key in SSH 

    When you perform an ssh connection to a remote machine, the 1st time you will be prompted to say ‘yes’ to authenticate the remote host.
    This feature is controlled by “StrictHostKeyChecking” parameter and it is set to yes by default. From security point of view, this option should be enable because protect you and your system against trojan horse attacks.
    Sometimes you need disabling it temporarily. To disable it you can do via console or via config file.

    Via console:

    #> ssh -o 'StrictHostKeyChecking no' username@remotemachine

    Via config file, adding below line to /etc/ssh_config (OSX) or /etc/ssh/ssh_config (linux):

    StrictHostKeyChecking no

    Once you turned it on, you can solve “offending key” deleting it from “~/.ssh/know_hosts” through this terminal command:

    # sed -i '19d' ~/.ssh/known_hosts

    where 19 is the line containing offending key.

    If you have suggestions, troubles or you feel alone, comment this post! :)

     
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