Showing posts with label Free software. Show all posts
Showing posts with label Free software. Show all posts

Saturday, March 27, 2021

BASH tricks with strings

I've been trying to leave Bash Scripting for a long time, favoring Python scripting. But when I guess I can't go further with Bash scripting, it just brings me something cool and new!

I must accept ICMP from a few OVH IPs, and among them are 2 IPs from my server network, where the last octet will be 250 and 251. To make it easier to understand, suppose that my server IP is a.b.c.d. So I must ACCEPT ICMPs from a.b.c.250 and a.b.c.251.

So, this is the amazing solution Bash Scripting offers me:

# ==========================================

# Dedicated Server IP external interface

IF_EXT="enp2s0"    # define here your external interface, such as eth0, vmbr0, etc

IP_EXT=$(ip -4 a|grep "${IF_EXT}$"|awk '{print $2}'|cut -d/ -f1)


# OVH monitoring IPs array

#    Here is the thing: the last item of this array!

IP_MONITORING=(37.187.231.251 151.80.231.244 151.80.231.245 151.80.231.246 151.80.231.247 213.186.33.62 92.222.184.0/24 92.222.185.0/24 92.222.186.0/24 167.114.37.0/24 213.186.45.4 213.251.184.9 37.59.0.235 8.33.137.2 213.186.33.13 213.186.50.98 ${IP_EXT%.*}.25{0,1})


# And finally the iptables command

for i in $(seq 0 $[${#IP_MONITORING[@]}-1]) ; do

        iptables -A INPUT -p icmp -s ${IP_MONITORING[$i]} -d ${IP_EXT} -j ACCEPT

done

# ==========================================


Notes:

- Obviously, you must run this script as root!

- I know Python would do it too. What I didn't know is that Bash could carry it out so "gracefully"!!

- I welcome any suggestion that may improve this code!!!


I hope it can help somebody out there. If it does, make me aware of it!

Wednesday, December 30, 2020

bpytop – Awesome Linux, macOS and FreeBSD resource monitor

It is always a good idea to keep a resource monitor open. HTop has been my pet for years. But now, I guess it is time to change. 

BPyTop is an awesome alternative, lightweight, and fully featured. Excellent job, written in Python. After that, I haven't seen my Htop interface for days! Read this concise article, and give BPyTop a try, if you haven't already!

Read more here: https://www.cyberciti.biz/open-source/command-line-hacks/bpytop-awesome-linux-macos-and-freebsd-resource-monitor/

Wednesday, December 21, 2016

Bash Script Check

You like to Bash Script, and would like someone to review your code?

KoalaMan is constantly working on such a project, and it looks to be very good! You just have to paste your Bash Script at the left box and it will be evaluated. Easy like that!

That's my example, a simple BashScript that does nothing. But KoalaMan implemented classic Bash scripting rules to it. Awesome!

This is a "MustHaveInMyList" link: http://www.shellcheck.net/


No automatic alt text available.

Monday, October 15, 2012

Installing Acrobat Reader on Ubuntu

Type the following commands:
sudo add-apt-repository "deb http://archive.canonical.com/ [distro] partner"
Where [distro] is, for example, lucid, natty, oneiric, precise, quantal.

This is for command-line options. This and desktop way cand be found here.

Friday, February 4, 2011

Disk full with Squid3

Besides working in an excellent company, I have some networks I help to administer. And recently, one of these friends called me complaining about the internet dropping. Immediately I got a SSH session to his firewall, and started my investigation job.

In fact, SQUID was not working anymore. Starting it was unuseful. Reading it's log gave me the following details:
$ sudo less /var/log/squid3/cache.log


CPU Usage: 0.044 seconds = 0.016 user + 0.028 sys
Maximum Resident Size: 23936 KB
Page faults with physical i/o: 0
2011/02/03 15:16:42| Starting Squid Cache version 3.0.STABLE19 for i486-pc-linux-gnu...
2011/02/03 15:16:42| Process ID 4628
2011/02/03 15:16:42| With 1024 file descriptors available
2011/02/03 15:16:42| Performing DNS Tests...
2011/02/03 15:16:42| Successful DNS name lookup tests...
2011/02/03 15:16:42| DNS Socket created at 0.0.0.0, port 35799, FD 7
2011/02/03 15:16:42| Adding nameserver 192.168.1.9 from squid.conf
2011/02/03 15:16:42| Unlinkd pipe opened on FD 12
2011/02/03 15:16:42| Local cache digest enabled; rebuild/rewrite every 3600/3600 sec
2011/02/03 15:16:42| Swap maxSize 10240000 + 8192 KB, estimated 788322 objects
2011/02/03 15:16:42| Target number of buckets: 39416
2011/02/03 15:16:42| Using 65536 Store buckets
2011/02/03 15:16:42| Max Mem  size: 8192 KB
2011/02/03 15:16:42| Max Swap size: 10240000 KB
2011/02/03 15:16:42| /var/spool/squid3/swap.state.new: (28) No space left on device
FATAL: storeDirOpenTmpSwapLog: Failed to open swap log.
I figured the problem was solved, but surprisingly, space was not the problem, as I could notice:
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9,2G  2,0G  6,8G  23% /
none                  434M  208K  433M   1% /dev
none                  438M     0  438M   0% /dev/shm
none                  438M   68K  438M   1% /var/run
none                  438M     0  438M   0% /var/lock
none                  438M     0  438M   0% /lib/init/rw
/dev/sda3              63G   42G   18G  70% /var
After some minutes mulling over this problem, I remembered that not only disk space is defined when a partition is formatted, but also the quantity of free inodes. To inspect this, I used df again:
$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1             610800   70254  540546   12% /
none                  110874     692  110182    1% /dev
none                  111925       1  111924    1% /dev/shm
none                  111925      36  111889    1% /var/run
none                  111925       2  111923    1% /var/lock
none                  111925       1  111924    1% /lib/init/rw
/dev/sda3            4153344 4153344       0  100% /var
The line above means I have no spare inodes, although there is a considerable free space. I have to look for which directory is consuming the inodes, or in other words, crowded with small files. Since I know it is in /var, there is where my search starts:
$ sudo du -s /var/* | sort -n
That will show the "heaviest" directory. In my case, it is /var/lib. So let's start again:
$ sudo du -s /var/lib/* | sort -n
The directory that was released was /var/lib/sarg, with the following files:
$ ls -l /var/lib/sarg/
total 52
drwxr-xr-x   7 root root  4096 2010-04-12 13:40 2010Apr12-2010Apr12
drwxr-xr-x  48 root root  4096 2010-04-15 04:00 2010Apr14-2010Apr14
drwxr-xr-x  45 root root  4096 2010-04-16 04:00 2010Apr15-2010Apr15
drwxr-xr-x  45 root root  4096 2010-04-16 16:45 2010Apr16-2010Apr16
drwxr-xr-x  41 root root  4096 2010-04-19 12:55 2010Apr19-2010Apr19
drwxr-xr-x  98 root root  4096 2010-09-06 14:22 2010Sep01-2010Sep06
drwxr-xr-x 168 root root 12288 2010-09-30 20:01 Daily
drwxr-xr-x   2 root root  4096 2010-04-12 13:40 images
-rw-r--r--   1 root root   780 2010-09-30 20:00 index.html
drwxr-xr-x   8 root root  4096 2010-09-01 02:38 Montly
drwxr-xr-x  49 root root  4096 2010-09-27 01:03 Weekly
Precisely, these are files done in a previous (unsuccessful installation of sarg). I may also notice that it happened almost one year ago. It was my fault to forget removing old useless files. After removing this directory, the inodes were restaured:
$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1             610800   70254  540546   12% /
none                  110874     692  110182    1% /dev
none                  111925       1  111924    1% /dev/shm
none                  111925      37  111888    1% /var/run
none                  111925       2  111923    1% /var/lock
none                  111925       1  111924    1% /lib/init/rw
/dev/sda3            4153344 1922631 2230713   47% /var
After that, squid could be started.

Tuesday, January 25, 2011

Installing a brand new Ubuntu box

I am using a Dell Optiplex 780 as my desktop at my job now, and so I do need my environment back, that means, I have to reinstall Ubuntu.

Got a usb memory prepared to install it, asked Windows 7 to release some space in HD (almost 80% of space, in fact), and started the procedure.

Ubuntu 10.10 up and ready, let's start to make it the best I can, and that's the reason why I wrote this post.

Cleaning old lists
First of all, I need to rebuild the apt lists:
sudo rm -v /var/lib/apt/lists/*
sudo apt-get update
This is only needed because for an unknown reason the original lists has some errors. I am really not aware about these mistakes.

Basic tools

Before starting, I need to prepare my surgery tools:
sudo apt-get install vim aptitude htop ssh k3b ssh ipcalc \
vlc gnome-mplayer compizconfig-settings-manager
\
compiz-fusion-plugins-extra
Compiz Configs
There are some adjustments I always do in Compiz interface. Of course, they are optional:
as_active_plugins = core;ccp;move;resize;place;decoration;gnomecompat;workarounds;neg;vpswitch;text;svg;ring;regex;commands;dbus;session;imgjpeg;mousepoll;shift;png;reflex;resizeinfo;animation;wobbly;fade;cube;rotate;3d;cubeaddon;scale;scaleaddon;expo;ezoom;
as_next_key = Tab
as_prev_key = Tab
as_initiate_key = Disabled
These configurations may be inserted through compizconfig-settings-manager, instead of dealing with configuration files.

Installing Java on Maverick Meercat

I don't know why, but Java is not available from Canonical repositories anymore. I just came over that because I needed to have my job's desktop reinstalled.

So, These are easy and single steps to provide Java-6 and Jetty application service in my Ubuntu server:

$ sudo aptitude install python-software-properties
$ add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo aptitude install sun-java6-jdk sun-java6-jre
$ sudo aptitude install libjetty-extra-java libjetty-java jetty

Working fine now!!!

This was edited after reading http://x4nd3m4c.blogspot.com/2011/02/instalando-o-jetty-no-ubuntu-1004.html. Thanks, Alexandre.

Thursday, October 21, 2010

Empathy does not access MSN

Since yesterday my empathy client does not show my contacts from MSN anymore. It is an empathy problem, and I found the solution (workaround) for this. You can find this in this page, but I will show it here quickly:

If you are in text interface, type the following line:

$ sudo vim /usr/share/pyshared/papyon/service/description/SingleSignOn/RequestMultipleSecurityTokens.py

In graphic interface, press ALT+F2 and type:
gksudo gedit /usr/share/pyshared/papyon/service/description/SingleSignOn/RequestMultipleSecurityTokens.py
Look for this line:

CONTACTS = ("contacts.msn.com", "?fs=1&id=24000&kv=7&rn=93S9SWWw&tw=0&ver=2.1.6000.1")

and change it to

CONTACTS = ("contacts.msn.com", "MBI")

Save the file and restart Empathy. It will now work!

Wednesday, November 18, 2009

Shared Folders in VirtualBox with Ubuntu Server

I really enjoy VirtualBox. After knowing it a little, I quit thinking about VMWare, for my Linux courses. Now, there is something really necessary when you work with more than one Virtual Machines: a shared folder.

A shared folder exists in the host system, and accessed by one or more guest systems. Thus, if VM1 needs to copy a file to VM2, just copy it to that folder. Easy like that.

Defining the Shared Folders
First, in Virtualbox console, you set one or more folders to be shared, as shown:

In the right panel above, you can see "Shared Folders". In this example there are already 2 shared folders. Click "Shared Folders", written in blue.

All shared folders are listed here. To add one more, click the folder with a "plus" signal, at the right side.

Write the host's folder full location, at "Folder Path" field. Optionally, this folder can be set as Read Only.

Virtualbox will suggest a name according to the folder's name, as you can see above.

Preparing Virtualbox Software
Now, let's make it available in our virtualized Ubuntu Server. First, we need to install it:

$ sudo aptitude install build-essential dkms

After that, "install Guest Additions" in "Devices" menu. It is an ISO image, and will work as if it is a CD.

Let's access it's contents

$ sudo mount /media/cdrom
$ cd /media/cdrom

In this folder there are several scripts, one for each system. You need to know wich version you have. Type the following:

$ uname -m
x86_64

My VM is a 64 bits. In my case I should type the following:

$ sudo ./VBoxLinuxAdditions-amd64.run

If the answer is "i686", the script must be "VBoxLinuxAdditions-x86.run". Any of them will first verify it's integrity, and after start some compilations. It will take a couple of minutes. Since we are using Ubuntu Server, a message warns that "X Window drivers will not be installed".

Building VirtualBox Kernel Modules
After all that, we are ready to build Virtualbox kernel modules, which is a really simple step. First, you will need to install kernel headers. Verify your kernel version with the command

$ uname -r

My system is kernel "2.6.31-14-server". My kernel is "server" type, so my kernel headers are installed with the following command:

$ sudo aptitude install linux-headers-server

It is a good idea to always update your kernel. When the headers installation ends, type the following command:

$ sudo invoke-rc.d vboxadd setup

After recompiling, Virtualbox recommends you to reboot. As you know, few operations require a system reboot, and most of them are kernel changings.

Mounting Shared Folders
We can now access it normally by mounting, using the module vboxsf (VirtualBox Shared Folders). To mount it manually, we need to know the Shared Folders' name, which is "Example". I choose "/mnt" as mount point.

$ sudo mount -t vboxsf Example /mnt

After that, you can copy files to and from /mnt folder. All these files will be available to the host system (in my case, Windows Vista System). If you want, with Windows Explorer you can access these files.

You can also configure Linux to automatically mount this directory. As "root" user, edit /etc/rc.local and add the following lines by the end of the file:

if [ -z "$(grep '/media/SwitchFiles' /proc/mounts)" ]; then
/bin/mount -t vboxsf SwitchFiles /media/SwitchFiles
fi

/proc/mounts show all mount points. If "/media/SwitchFiles" is not listed there it will be mounted. Of course, you should create this directory, case it does not exist yet.

My application
Since I have many VMs with Ubuntu Server and Ubuntu Desktop working toghether, frequently I have to install some packages, thus downloading them. With shared folders, I can download once, through any VM and use it in all the others VMs. My "/var/cache/apt/archives" is the mount point of a shared folder in Windows, in "/etc/fstab" in all VMs, as follows:

if [ -z "$(grep '/var/cache/apt/archives' /proc/mounts)" ]; then
/bin/mount -t vboxsf AptArchives /var/cache/apt/archives
fi

Of course, in my Virtualbox console, I have created "AptArchives" shared folder in each VM.

Do not forget to comment and to tell if this was useful or not.

Friday, December 12, 2008

Teacher says that there is no free software

I have just known that (in portuguese), and it is astonishing. You can read more about this in Blog of Helios and The Contractor UK, both in English.

The summary
Karen (the teacher) saw students around a laptop, and went to understand it. She found one of them with the laptop showing what Linux could do in his machine (take a look at some of this videos). Not only this, but he was GIVING copies of it to his friends.

Karen kept them all and after talking to the students, she had a name: Ken Starks. She wrote the email with lots of wrong ideas. Both emails, from Karen and Starks' answer are in Blog of Helios.

The worst
Even in US, a great country, even in Texas, a great state, developed, with lots of technologies, lots of people just don't know that there are others possibilities besides MS Windows. A teacher, whose responsability is to prepare youngs , should know this. At least, not to be saying so many wrong things.

I have no doubt: she did what she understood as correct. Where she saw a threat to the kids, she reacted in defense of them. But she is indeed not prepared. Not in technology matters.

She needs to stay in touch with technoloy, as to other subjects. Or else, she may be teaching that the Earth is flat ...