Posted on 20-05-2011
Filed Under (linux, programming, shell script, ubuntu) by admin

Going through different log files can be a pain, but here’s a simple script that parses today’s logs from different files into a single file, in this case we extract today’s logs from messages, auth.log, syslog. Finally, we send them through email. Don’t forget to make the file executable!… Logparser can be downloaded from here

#!/bin/bash
#author jorge
#purpose: extracting daily log entries from multiple log files
 
LOG1=/var/log/messages
LOG2=/var/log/auth.log
LOG3=/var/log/syslog
MYDATE=`date +%b\ %d`
OUTPUTLOG=`date +%F`.dailylog
EMAIL=btuser
 
for LOG in $LOG{1,2,3}
do
        #if file exist and is not empty then process
        if [ -e $LOG ] && [ -s $LOG ]; then
                echo $LOG BEGIN >> $OUTPUTLOG
                #only grabbing todays log out of file
                grep -E "$MYDATE" $LOG >> $OUTPUTLOG 2>/dev/null
                echo $LOG END >> $OUTPUTLOG
                echo >> $OUTPUTLOG
        fi
done
 
#email output
cat $OUTPUTLOG | mail -s "daily logs `date +%F`" $EMAIL 2>/dev/null
 
#END

Comments Off    Read More   
Posted on 31-08-2010
Filed Under (ubuntu) by admin

In past versions of ubuntu, I’ve experienced slow connections specially with internet. And it’s been because of IPv6. Now in Ubuntu 10.04, I didn’t noticed any slow connection; however, I decided to go ahead and disable it anyways… just in case. And here are the steps.

Checking whether IPv6 is enabled or not.

jorge@nixboxen:~$ cat cat /proc/sys/net/ipv6/conf/all/disable_ipv6
cat: cat: No such file or directory
1

if output=0 then is enabled. So use your preferred editor and open /etc/sysctl.conf. Then add the following lines.

#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Comments Off    Read More   
Posted on 10-10-2009
Filed Under (linux, networking, ubuntu) by admin

I decided to make a guide about TCP/IP configuration in Linux, and you may ask: well, what Linux distribution in specific? I know!, there are hundreds of Linux distribution, but for this guide, I’m only going to cover the two most used Linux distribution: Ubuntu and Fedora. Ubuntu is a Debian derivative, so the Ubuntu portion of TCP/IP configuration applies to any distro based on Debian. And the same goes for Fedora, which is based on RedHat Linux.

First, you want to find out what interfaces you have, and what ip address, “if any,” was assigned to your computer. For this use the “ifconfig” command:

ifconfig  #will list all enabled interfaces

if you are looking for a specific interface:

ifconfig eth0 #will only display the configuration for eth0 interface

If you get no interfaces other than the loopback address, it is time to do some troubleshooting and find out whether your network card was detected by Linux or not.

sudo lspci | grep -i ethernet #displaying all your ethernet cards

if you’re troubleshooting a wireless card just change “ethernet” for “wireless.”
other useful command when troubleshooting network card and drivers is “lsmod” Read the rest of this entry »

(2) Comments    Read More   
Posted on 30-09-2009
Filed Under (linux, ubuntu) by admin

To see which processes are currently on a system, most people use the “ps” and “top” commands. The “ps” command gives you a snapshot (in a single list) of processes running at the moment. The “top” command offers a screen oriented, constantly updated listing of running commands, sorted as you choose ( by CPU, memory, UID, etc).

ps #List processes of current user at current shell

root@ubuntu-box:~# ps
  PID TTY          TIME CMD
 2988 pts/0    00:00:00 su
 2996 pts/0    00:00:00 bash
 3047 pts/0    00:00:00 ps

ps -u jorge #Show all jorge’s running processes

root@ubuntu-box:~# ps -u jorge
  PID TTY          TIME CMD
 2662 ?        00:00:00 x-session-manag
 2725 ?        00:00:00 VBoxClient
 2730 ?        00:00:00 VBoxClient
 2737 ?        00:00:00 VBoxClient
 2748 ?        00:00:00 ssh-agent

ps -u jorge u #Show all running processes with CPU/MEM Read the rest of this entry »

Comments Off    Read More   
Posted on 26-09-2009
Filed Under (linux, ubuntu) by admin

Running out of disk space can be annoying on your desktop system and potentially a disaster on your servers. To determine how much disk space is available and how much is currently in use, you can use the “df” command. To check how much space particular files and directories are consuming, use the “du” command.
The “df” command provides the “-h” options which output in a human-readable, usually in MB or GB.
This command display space on file systems in human-readable form

[root@Fedora11-vbox ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_fedora11vbox-lv_root
                      6.7G  3.6G  2.9G  56% /
/dev/sda1             194M   21M  163M  12% /boot
tmpfs                 250M  292K  250M   1% /dev/shm

If you have remote share mounted, these will show up too. So to limit the output to local systems only:

df -hl

To check for disk space usage for particular files or directories in a file system:

[root@Fedora11-vbox ~]# du -h /home/
4.0K	/home/smbuser/.mozilla/plugins
4.0K	/home/smbuser/.mozilla/extensions
12K	/home/smbuser/.mozilla
4.0K	/home/smbuser/.gnome2

If you have root priviliges, you can use the “-s” option to get a summary of disk usage; otherwise, you will get “permission denied” when trying to access directories that you don’t have access to. Read the rest of this entry »

(2) Comments    Read More   
Posted on 26-09-2009
Filed Under (linux, networking, ubuntu) by admin

Understanding subnetwork mask can be confusing if you’re not used to them. You may find “ipcalc” (from ipcalc package) useful to calculate a computer network’s mask.

First start by installing “ipcalc” from the repositories, depending on your distro:

sudo apt-get install ipcalc #for debian distros like ubuntu
yum install ipcalc #for fedora

then find the ip address for which you want to calculate the network for, and enter it along with “ipcalc” command

[root@Fedora11-vbox ~]# ipcalc -bmn 192.168.10.122/22
NETMASK=255.255.252.0
BROADCAST=192.168.11.255
NETWORK=192.168.8.0

So in this scenario, the subnetmask is (255.255.252.0), the broadcast address (192.168.11.255), which means that the last usable ip address for that network is (192.168.11.254), and last the network address (192.168.8.0); therefore, the first ip address for that range will be (192.168.8.1).

Comments Off    Read More   
Posted on 25-09-2009
Filed Under (linux, security, ubuntu) by admin

After you have created users accounts, and let those users loose on your somputer, there are different commands you can use to keep track of how they are using your computer. There are commands for checking such things as who is logged into your system and getting general information about the users with accounts on your system. Here are some of these commands.
last #list the most recent successful logins

root@ubuntu-box:~# last -a
smbuser  pts/2        Fri Sep 25 06:37   still logged in    windows-box
jorge    pts/1        Fri Sep 25 06:35   still logged in    windows-box
jorge    pts/1        Fri Sep 25 06:34 - 06:35  (00:00)     windows-box
 
wtmp begins Fri Sep 25 06:34:52 2009

lastb #List the most recent unsuccessful logins

root@ubuntu-vbox:~# lastb
smbuser  ssh:notty    windows-box      Fri Sep 25 05:36 - 05:36  (00:00)
jorge    :0                            Fri Sep 18 17:28 - 17:28  (00:00)
jorge    :0                            Fri Sep 18 17:28 - 17:28  (00:00)
jorge    :0                            Fri Sep 18 17:27 - 17:27  (00:00)
jorge    :0                            Fri Sep 18 17:27 - 17:27  (00:00)
jorge    :0                            Fri Sep 18 17:27 - 17:27  (00:00)

who -u #List who is currently logged in (long form) Read the rest of this entry »

Comments Off    Read More