…with an open minded approach

Posts tagged “backup

setup iptable rules for transmission (torrents)

Without further addo, here it is, a working example how to configure iptables to allow transmission torrents to internet (udp 51413) + transmission remote RPC (tcp 9091, localnetwork only) + ssh (tcp 22, localnetwork only).

 

 

Drop a comment if its usefull 🙂

Advertisements

text manipulation: lines to columns and other goodies

Have a look at the power of the “paste” comand – it just solves a bunch of situations with ease, and its litle known… transpose pair a lines into 2 columns, etc…

 

Have a look to these examples to get an idea of “paste” power…

 

http://www.theunixschool.com/2012/07/10-examples-of-paste-command-usage-in.html


unix directory hacks with cd

I’ll just link to the http://www.thegeekstuff.com/2008/10/6-awesome-linux-cd-command-hacks-productivity-tip3-for-geeks/

Read them carefully and your console efficiency may just get a big boost 🙂

 


sudo run as another user – scripting it

To ease your admin scripts….


Bash local variables

All variables in bash default to being *global*.

To define a variable as *local* to a function, we can do:

function my_func {

local MY_LOCAL_VAR=”is local to the scope of its function”

}


Detect ssh login from ~/.bashrc

When you login with ssh, your environment gets 2 variables defined: SSH_CONNECTION and SSH_TTY

A simple way to detect if you are inside a bash session, established from ssh-login, is to check these vars

You can put this check inside ~/.bashrc, so that it executes in all new bash-logins, so that when a ssh-login is detected you can make something happen 🙂

This is a simple hack to detect normal ssh-logins, but dont use this for anything too important 🙂

 

 


incron

There is a great linux kernel functionality called “inotify” – which can emmit events on file changes. Its just great, have a look at its home page, I think its one of those linux pearls not much widely known…

Well, the thing is that using inotify, a tool called incron has been made, which is like a cron for file events (instead of time events), and that is really usefull when we want to detect file changes and react accordingly 🙂 very usefull for server scripts 🙂

And so, without further delay, here it goes, the best resume I found so far detailing how to use incron: http://www.howtoforge.com/triggering-commands-on-file-or-directory-changes-with-incron

NOTES: there be dragons…

Inside you incrontabs, you must leave *only* 1 space between the <path> <mask> <cmd>. If you leave 2 or more spaces, then the 2nd (and more) spaces will be considered part of the <mask> or <cmd> and it will fail… I was leaving 2 spaces between <mask> and <cmd>, and incron did not work and in /var/log/syslog there were these messages

incrond[27693]: cannot exec process: No such file or directory

This was because of having 2 spaces… when I corrected to only 1 space, it began working correctly. Keep it in mind, so you dont suffer as much as I did to find it out 🙂

 

After editing with “incrontab -e”, check that “incrontab -l” shows the rules. If it does not show some rule, then that is because that rule has some error and was not recognized.

 

To debug what is happening behind the curtains, its usefull to have a “tail -f /var/log/syslog” on another terminal…

 

Cheers


Bash initialization files

This bash resume diagram is respectfully copied from http://www.solipsys.co.uk/new/BashInitialisationFiles.html

I’ll post it here before I need it again – its just great


Sed info

Sed – An Introduction and Tutorial by Bruce Barnett – I really should post this up before I forget: it’s a sed resume that goes from-basic-to-deep features, progressively explaining what-does-what with examples… a really good reference for sed usage

 

If you’r into sed, take a look – it will be worth it

 


bash ternary-like comparisons…

Bash does not have a ternary operator ?: to do things like ” condition ? command-if-true : command-if-false ”

Its possible to do the same with “if”s but its not so neat and compact…

One hacky alternative which is possible in bash, is to do ” condition && command-if-true || command-if-false”, like so:

Hope it helps – if so drop a comment