Batch Resize Multiple Fotos

In order to manipulate multiple images/fotos at once from a command line I recommend installing imagemagick:

apt-get install imagemagick

To resize all “jpg” in current folder by 50% and save new files to re_OLDNAME run :

for i in $( ls *.jpg); do convert -resize 50% $i re_$i; done

For more options check man page for “convert”. You can blur, crop, convert , add effects and many more!

Install Perl CPAN Module

Sometimes some perl dependencies are missing.

If your run into this problem the easiest way to install missing modules is to start PERL Console and fetch missing data. When you run it for the first time, you will be asked to confirm sources. Fell free to confirm the defaults. To start the console run perl -MCPAN -e shell

Shell Script Syntax Error: “(” Unexpected

Shell script syntax error

If running some shell script you encounter following error Syntax error: "(" unexpected check the first line.

Most propably it is #!/bin/sh . If that is the case change it to #!/bin/bash and your script schould run fine.

Debian Packages Primer

Debian package manager tutorial

dpkg -i XYZ.deb - Install the packege XYC

dpkg -R /some/dir - Install all packages in /home/dir

dpkg -p XYZ.deb - Remove package XYZ from system but leave the configuration files

dpkg -P XYZ.deb - Remove package XYZ from system and delete the configuration files

Disable Firewall Rules

How to disable all Iptables rules on linux

If for any reason you need quickly to open firewall (disable it) , use following snippet.

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

This code clears all counters as well.

Be aware, this will expose all your services!

Run this as one script. If you run it line by line and your policy is set to DROP/REJECT you will be cut of after first line.

Firewall Won’t Allow APT to Work

How to allow APT to work thru firewall

Problem: If you set firewall OUTPUT policy to DROP/REJECT APT will not work , it will hang forever on “update” until it times out.

You need to allow outgoing “new” and “established” traffic on OUTPUT chain and make sure you you already have rule accepting “ESTABLISHED” traffic for “INPUT” chain.

Make sure you have following rules apllied.

1
2
-A OUTPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

IMPORTANT: Since you are using DROP policy (if not, you should!) make sure your host is able to contact DNS server to resolve hosts. Following rule will do the trick:

1
-A INPUT -p udp --sport 53 --dport 1024:65535 -j ACCEPT

List All Tablespaces in Postgres

How to show all tablespaces configured in a cluster

1.Log in as postgres user

su postgres

2.Start psql

psql

3.Run query

1
select spcname, pg_tablespace_location(oid) from pg_tablespace;

Setting Up Apache Proxy

Apache Proxy

1.In order to set up simple Apachy proxy make sure your module “proxy_http”is loaded.

a2enmod proxy_http

2.Edit your vhost file , it should look like this :

1
2
3
4
5
6
7
8
<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName www.mydomain.com
  ServerAlias mydomain.com
  ProxyPass / http://localhost:8080/example/
  ProxyPassReverse / http://localhost:8080/example/
</VirtualHost>

3.Reload Apache

service apache2 reload

All requests to mydomain.com will be sent to port 8080 on localhost and back.