Browsing the archives for the Tutorial tag.

How to do a quick backup at console

Linux, Tutorial

So, you are coding your project and you realize that you haven’t done any backups! What is the easiest and fastest way to do backup (I don’t know about speed and difficult of this method, but it works and I like this.)

Dump your databases! (if you have any)

Mysqldump --databases dbname > dump.SQL

Then move to parent directory

cd ..

And do a tar archive

tar cvvf project.tar project/

And voilà! Local backup is ready, let’s move it to safe place in your ftp server…

ftp ftp.example.com

Use ls and cd to find right folder on your server, then move local file with:

put project.tar

Whee! Now you have backups safely on your server! It is possible to write a cron script that backups and uploads your project every hour.

No Comments

Create simple twitter bot using python

Internet, Tutorial

In this tutorial you will learn how to do very simple twitter bot. Requirements is Linux/Mac system, but it should be possible to get this on windows.

Install python-twitter

First, you need to install python-twitter package. Installion is simple. Just download package from python-twitter’s website and follow instructions.

Lets get started

In this code we import libraries needed to get this working. First library is the twitter-python package and another is time-library for creating simple timer. We need timer for doing a loop. Commands library is needed to get output from external command. (In this case, uptime)

#!/usr/bin/python
import twitter
import time
import commands

Intializing api


api = twitter.Api(username='username', password='password')

This will intialize twitter api and create new class, api. Change username and password to your accounts details.

Tweeting something


while 1 == 1:
api.PostUpdate(getoutput('uptime'))
print(getoutput('uptime'))
time.sleep(3600)

This will generate infinite loop that will send twitter update every hour. Tweet contains output of uptime command. This also prints output to console so its easier to see what is tweeted.

I run this command inside screen, so it will run 24/7 tweeting uptime of my vps.

If you want to learn more about python-twitter I recommend to read docs on python-twitters website.

Download source code of this tutorial: twitter_bot.py

No Comments

Ultimate Irssi guide for beginners

Applications, Tutorial

What is irssi?

Irssi is modern command-line irc client. It is very customizable, stable and fast irc client. Best thing about irssi is that you can run it on shell account inside screen, so you will be online 24/7 even if you shut down your computer. You can connect to your irc from any machine you have. You can use your client from any machine.

Irssi may be little difficult at first, but after learning it, it becomes extremely powerful irc-client.

Basics settings

Installing irssi is easy, just use your distros package-manager. I also recommend to install” screen”. You can find it also from standart repos.

Start irssi with “irssi” in terminal. You should found very basic screen with first time message.

Lets set up some basic settings and connect to irc network. Type “/set timestamp_format %H:%M:%S” That gives seconds to timestamps. (normally it is just %H:%M) Then lets set nick and other name stuff, “/set nick asdasdasd” will change your default nick before connecting. After connection , use “/nick asdasd” instead.

Then type “/set name” name is not a option to set, but irssi will show you all settings that have a “name” on it. Very easy to search for settings. Also all settings supports tab completion, so you can type “/set user_n<tab>”. You can also use <tab> on nicks and commands.

Connecting to servers

Connecting to server is easy. Just “/connect irc.freenode.net” Then, when you have connected just type “/join #channelname” to join channel. Then just start chatting :) . You can leave channel with “/leave” or “/part” command.

Connecting to multiple servers is also easy. Just type another “/connect irc.servername.org”. Using “/server” you can list servers. In default status window (alt+1) you can change server where commands are going by <ctrl>+x. Example if you want to join another channel, press <ctrl>+x to get right server and then just give join command.

Window managing

Window managing may feel weird at first. After you have connected and joined to couple channels, you can change window with <alt>+windownumber or using <ctrl>+n/p. First window (1) is the status window where all server stuff and irssi’s system messages goes. Other windows are mostly for channels and querys

You can change position of windows using “/window move left” (or right) command. There is also way to split windows and make them sticky. Use “/help window” to read more.

Tip: If you have over 10 windows open, you can open windows 11,12,13… with <alt>+q,w,e…

Alias

Aliases are easy and powerful way to create simple commands and make long commands shorter. Syntax for aliases is simply. “/alias longline say This is a freaking long line that you must type many times on day” After that you can use “/longline” to say that line to channel.

you can also create aliases for irssi commands, like “/alias wml window move left”. Then you can move window to left with “/wml”

You can list aliases with “/alias”. Removing aliases is done vie “/unalias”

It is also possible to create aliases with parameters. “/alias slap me slaps % around with a large trout.” Then just “/slap <nick>”!

A uptime alias is also very fun. It shows uptime of Irssi, not system.  Some versions/packages of irssi has this alias already, but if you don’t have “/uptime” command, create it with: “/alias uptime eval exec – expr `date +%s` – $F | awk ‘{print “Irssi uptime: “int(\$1/3600/24)”d “int(\$1/3600%24)”h “int(\$1/60%60)”m “int(\$1%60)”s” }’”

My best uptimes for irssi is about 60-70 days.

Screen

Screen, way to keep your irssi alive. Screen is program that allows dedacthing cli-programs and then continuing them using them later. Start irssi with “screen irssi”, then when stopping chatting just type <ctrl>+a <ctrl>+d and irssi is detached! To retacth irssi use screen -r command.

This is useful when you run your irssi on machine that is running 24/7, a shell. For free shells try #bshellz@freenode. They offer best free shells.

To get bell working, first set screen to support audible bell. (<ctrl>+a <ctrl>+g) Then set irssi “/set beep_msg_level hilight” or what ever level you want. (/help levels)

Scripts and themes

Scripts are powerful way to add new features to irssi. You can find scripts from http://irssi.scripts.org.

Installing scripts is pretty simple. Just “cd” to “.irssi”  and create script directory if it doesn’t exist. “mkdir scripts” and then wget script.Eexample “wget http://url.to.script.file”.

After download, run script using “/run scriptname” or “/script load scriptname”. Unloading scripts is done via “/script unload scriptname”. (/run is alias for loading scripts). Listing running scripts is easy. Just type “/script”.

Themes are also easy to install, just put the .theme file to .irssi folder, then “/set theme <themename”.

Scripts I recommend to try:

  • awl.pl – Listing windows on statusbar, excellent script and very customizable
  • lastfm.pl – Now playing script using last.fm
  • autoaway.pl – Automatically set you away
  • keepnick.pl – Keeps your nick and tries to get it back if someone stoles it
  • trackbar.pl – Adds xchat like trackbar to channels so you can easily see what messages are new
  • trigger.pl – Create triggers and other cool tricks
Telnetting to batmud using irssi

Telnetting to batmud using irssi

Irssi with weed theme and awl script

Irssi with weed theme and awl script

8 Comments