Posts

Showing posts with the label linux

Create a Symlink as a Workaround for Partition Full Error

Sometimes, a mounted partition does not have enough space, and it may take time to expand the LVM volume, if there is not currently enough physical space available, and a separate team handles storage.  Of course making a separate partition is a more proper fix, and LVM is flexible enough to accommodate the changes, but sometimes space is filling up, and something has to be done right away.  Maybe /var/log, or /opt is filling up, and you did not think ahead to make it a separate partition. As a quick workaround, it is fairly common to use a symbolic link, or as sysadmins affectionately call it, a symlimk. Let's say an application wants to install under /opt, and you are out of space in /opt, but have plenty of space in /app.  You can use a symlink to trick the system into thinking that it is using /opt, when in fact it is using /app/opt. I like to perform a directory move and symlink creation at the same time.  Note that both /opt and /app already exist, but w...

Get a List of rpms for a Specific Program or Version

Image
Systems that use rpm as the package manager can often be managed by using yum, but sometimes a simple rpm command can quickly give the required information. The RPM Package Manager has a huge number of options, but most commonly only a few are used on a regular basis. Get a list of rpms for mysql-5.1   Check for mysql version 5.1   $ rpm -qa |grep mysql | grep 5.1 mysql-test-5.1.52-1.el6_0.1.x86_64 mysql-connector-java-5.1.12-2.el6.x86_64 mysql-bench-5.1.52-1.el6_0.1.x86_64 mysql-server-5.1.52-1.el6_0.1.x86_64 mysql-connector-odbc-5.1.5r1144-7.el6.x86_64 mysql-5.1.52-1.el6_0.1.x86_64 mysql-libs-5.1.52-1.el6_0.1.x86_64 mysql-devel-5.1.52-1.el6_0.1.x86_64 Of course we can use egrep, and sort to get a more specific list $ rpm -qa |egrep -i "bash|ntpdate|httpd"|sort bash-4.1.2-8.el6.x86_64 ntpdate-4.2.4p8-2.el6.x86_64 xargs - build and execute command lines from standard input Now suppose we want to remove all the rpms found by the rpm query. Sometimes we can ...

Use awk to Extract a Column from a Text File

Image
Here is an example of how to use awk to extract a column from a text file. The default field separator is a space, so this will work with some text files:    cat somefile.txt | awk '{print $2}' But, if the fields are separated by a delimiter, such as tab, or comma, just specify the field separator by using "-F" before the print statement    cat somefile.txt | awk -F"\t" '{print $2}'   Unix and linux distributions generally come with sed and awk, among other things. The problem. You want to get a list of companies to research before investing in them, and paste only the stock symbols into a Yahoo finance portfolio.   You run a stock screen on a site such as  magicformulainvesting.com , or investors.com but if you try to paste the text into a spreadsheet it may show up as a single row, with no way to extract the column. Here is the process 1.)  Run a Stock Screen Get output similar to this: Company Name (in alphabetical...

Advanced Linux Networking Tools

Image
Some of the more common tools for advanced networking include: tcpdump, netstat, wireshark, and tshark. A previous article covered Basic Linux Networking Tools . Discover Switch Information Now for the advanced stuff. We use tcpdump, and write it to a file pkt.cap. Then we use tshark to read the file. How to check the router to which the linux host is connected. # tcpdump -nvi eth0 -c 1 -s 1500 -w pkt.cap ether proto 0xaa and ether dst 01:00:0c:cc:cc:cc and ether\[20\] \=\= 0x20 and ether\[21\] \=\= 0x00 # tshark -V -r pkt.cap # tcpdump -nvi eth0 -c 1 -s 1500 -w pkt.cap ether proto 0xaa and ether dst 01:00:0c:cc:cc:cc and ether\[20\] \=\= 0x20 and ether\[21\] \=\= 0x00;tshark -V -r pkt.cap tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 1500 bytes 1 packets captured 1 packets received by filter 0 packets dropped by kernel Running as user "root" and group "root". This could be dangerous. Frame 1 (416 bytes on wire, 416 bytes captured) Arrival T...

Basic Linux Networking Tools

Image
Verify Network Connection Most people, who have been around redhat linux for a while, know how to check the IP address, and MAC address using ifconfig. Next, they would typically use route -n (or netstat -r) to find the gateway, and then ping it to verify a connection. Then maybe check duplex and speed using ethtool. Check the IP Address # ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:15:17:C1:54:D4 inet addr:10.10.5.67 Bcast:10.10.5.255 Mask:255.255.255.0 inet6 addr: fe80::215:17ff:fec1:54d4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:342967 errors:0 dropped:0 overruns:0 frame:0 TX packets:353260 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:64963573 (61.9 MiB) TX bytes:262444897 (250.2 MiB) Memory:b8820000-b8840000 Discover the Gateway Address Then, it is common to check the default route with route -n, or netstat -nr. # route -n Kernel...

Yum Repositories for RHEL 5

Image
Sometimes we need a RHEL5 Repository that includes software not released by Redhat. It may be that we need a newer version, or simply something that was not included in our installation, and is not part of the standard redhat repositories. Missing RPM Have you ever tried to install something with yum, only to find that the package is not available? $sudo yum -y install vlc Password: Server | 1.3 kB 00:00 Updates | 951 B 00:00 Workstation | 1.1 kB 00:00 addons | 951 B 00:00 base | 2.1 kB 00:00 extras | 2.1 kB 00:00 update | 1.9 kB 00:00 Excluding Packages in global exclude list Finished...

Data Recovery: 5 Things You Must Know

Image
Hard drive data recovery is one of the most difficult tasks a sysadmin can attempt to perform, so it should be considered a last resort that, after many frustrating hours, may not even work at all. Data Recovery or Disaster Recovery can be thought of in several categories, and it is important to have a plan in place, and know the options before resorting to one of your local hard disk data recovery services. Many people fail to consider the value of their data until it is too late. This article discusses general principles, with some specific examples from experience with Novel, Microsoft, and Linux operating systems. Detailed tool discussions will be reserved for separate posts. Here is a short list of categories, roughly in order of increasing level of difficulty to recover. Backups and off-site storage RAID Documents File Systems Data Recovery from Hard Drives There is software available that can recover from several types of failures, but it does not always work when ther...

nagios-config-build Released

Image
I wrote some shell scripts to generate Nagios configuration files, and I finally decided to publish them on Freshmeat . The initial version is crude, and has some hard-coded information, but it is still better than trying to edit the .cfg files by hand. Here is a brief description nagios-config-build is a group of shell scripts that generate Nagios configuration files from a list of hostnames. It automatically resolves IP addresses from DNS, and provides a quick way to manage a large number of hosts without having to set up a complicated system. Nagios is more than just a server monitoring tool. From the Nagios website: " Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes." Systemnotes.org download: http://www.systemnotes.org/download/shell/nagios-config-build.html Freshmeat project: http://freshmeat.net/projects/nagios-config-build Please feel free to use thi...

Bash Shell, X, & Firefox Shortcuts

Image
As I was writing a script, I noticed that I pressed Shift-PageUp without even thinking about it. Then I realized that there are a lot of shortcuts we take for granted as Sysadmins. I thought it would be helpful to share some of them. This is not a comprehensive list, but a few shortcuts I find myself using all the time. Bash Shell shortcuts Shift-PageUp / PageDown See more of the screen Ctrl-a, Ctrl-e Move to beginning / end of line up & down arrows See bash history !! / !$ Execute the previous command / parameter !n Execute the nth command in history Ctrl-D Logout, or exit Ctrl-u, Ctrl-h, Ctrl-b Delete previous char, or entire line Alt-F1 to Alt-F7 Switch to another console —see also: using-bash-history , ...

Bash Alias

Image
An alias is a built-in way of modifying the way a command works, or it is used as a shortcut for another command. For example, you may find that you often type "ls -l", or "ls -ltr", and think it would be nice if you could type less characters. You can create an alias, so that all you would have to type is "ll", instead of "ls -l." To add an alias to your .bashrc file: $ vi ~/.bashrc Insert these lines: alias ls='ls --color=tty' alias ll='ls -l' In order for the new alias to take effect, you can open a new console, login again, or simply source your .bashrc file. You also have the option of running bash again to open a new shell, or just running the alias command. What do I mean by source the file? You can either run a script, or have the shell read the variables in a script without actually running it. This is called sourcing a file, and is accomplished by typing either "source", or "." followed by th...

Script to Unlock Firefox

Image
I wrote a script to unlock Firefox on a linux machine. The symptom is when firefox is not running, but it won't let you start because it thinks it's still running. If you have already run "pkill -9 –f firefox", then all you have to do is delete the lock files -- .parentlock, and lock. This is user specific, so you'll have to find your own home directory under ~/.mozilla/firefox/. Mine is dz4bq7je.scottm on this host. $ cat ~/bin/unlock_firefox.sh #!/bin/sh rm ~/.mozilla/firefox/dz4bq7je.scottm/.parentlock rm ~/.mozilla/firefox/dz4bq7je.scottm/lock $ ll ~/.mozilla/firefox/ total 12 drwx------ 9 scottm users 4096 Sep 9 11:25 dz4bq7je.scottm -rw------- 1 scottm users 1264 Jun 23 2008 pluginreg.dat -rw-r--r-- 1 scottm users 162 Nov 15 2005 profiles.ini $ The advantage of this simple script is that you don't have to go looking for directories and files, or remember where firefox puts them. Just remember when it's l...

Notes from Ubuntu 7.10 Live CD

Image
Every once in a while, I like to try a few live CD's to see how the distros are progressing. I am happy to report that Ubuntu is getting more usable with each release. I titled this "Notes from..", rather than "Notes about", because I was able to work within a live CD session, and save my files. I admit I wasn't very impressed with the first version of Ubuntu I looked at. That was version 4.1, which I got in live CD format from a local linux user group meeting. After realizing that I couldn't read my NTFS partitions, I played a few games, and quickly lost interest. Also, I had a slower laptop at the time, and having the os frequently read from the CDROM made the experience slightly annoying. Now with a faster CDROM drive, and all the updates, the system is quite pleasant to use. Getting Started Using a boot CD is quite easy, and does not require anything to be installed to the hard drive. The entire operating system can be booted from a CD, and run...

Mail a Text File from the Shell

Image
Would you like an easy way to send files to someone outside of your local network, or quickly test a mail server? Well the old "mail" command is still available, and it comes in handy for sending config files, or using within a shell script. This is all you need: $ mail -s test me@company.com That's the shortcut. If you want more details, you can read the rest of the post... Using the mail command 1) Use Mail Interactively to read mail a) type Mail b) enter the number of the message to read, press enter c) press space to page down, n for next message d) ? for help e) q to quit 2) Use mail Interactively to send mail a) type mail command followed by email address b) Enter subject, press enter c) Enter text of message d) press Ctrl-d on a line by itself when finished e) Enter CC: if desired, or press Ctrl-d again $ mail user@company.com Subject: test Here is my test message <Ctrl-d> Cc: <Ctrl-d>$ For a little less work, add the subject to the command prompt. ...

Ping Multiple Hosts Using Bash Nmap and Fping

Image
I explained how to get a list of hosts using nmap -- using-nmap-to-generate-host-lists.html , but here is another look at the subject. The question is, how do I ping multiple hosts to find out which ones are down? Sure this could be considered a topic of system monitoring, but maybe you just want to reboot a bunch of machines, and make sure they all come back online. This quick check will tell you whether there is a problem or not. Here are three methods for pinging a list of hosts: 1.) for host in `cat all.txt `;do ping -c 1 $host; done 2.) nmap -sP -R -iL all.txt 3.) sudo fping -u < xyz/all.txt First, we assume that you have a text file named all.txt that contains a list of hostnames, one per line. Obviously, the examples here contain fake hostnames, domain names and IPs, as described in another article about vi: vim-tips-search-and-replace.html . --- all.txt --- xyz-1 xyz-2 xyz-3 xyz-4 xyz-5 xyz-6 xyz-7 xyz-8 --- end all.txt --- 1.) Use a for loop in ...

Shell Console Reset

Image
Did you ever cat a file that caused the terminal to display all kinds of strange characters? Pressing Ctrl-C and Enter, or typing clear doesn't get the console back to normal. The characters are there, but they are unreadable. A quick way to fix this is to use "reset" -- type: $ reset That should bring the console back to normal. Of course, if you just want to clear the screen, you can type "clear" ("cls" in DOS, or a Windows command prompt).

Use CheckInstall Instead of Make Install

Did you ever look for a binary, and as a last resort download the source to compile yourself?   Of course you were disappointed that the program would not be part of your package management system. Usually you have to run something like this:   ./configure   make   make install An easy way to create an .rpm or .deb file from source is to run checkinstall instead of "make install" during the standard install from source. http://freshmeat.net/projects/checkinstall -- CheckInstall Freshmeat Page http://checkinstall.izto.org -- CheckInstall Home Page CheckInstall keeps track of all files installed by a "make install" or equivalent, creates a Slackware, RPM, or Debian package with those files, and adds it to the installed packages database, allowing for easy package removal or distribution.

RHCE Study Notes - HTTP

Image
These RCHE study notes were designed to be brief reminders of what you should already be familiar with. This topic covers HTTP server configuration. One thing to be aware of when working with Apache and the 2.6 kernel is SELinux. Overview of SELinux SELinux, is a Mandatory Access Control (MAC) security system for Linux based on the domain-type model. It was written by the NSA ( http://www.nsa.gov/selinux/ ) and is comprised of a kernel module (included in all 2.6 kernels), patches to certain security related applications, and a security policy. More info: http://www.redhat.com/magazine/001nov04/features/selinux/ Study Notes Here are the brief steps from my RHCE study guide to help you remember the steps to configure a virtual host, and configure permissions. * HTTP/HTTPS install httpd, check context with ls -Z   Q: Create a virtual host www1.example.com w/ subdirectory /var/www/html/www1   A:    1) install httpd, modify /etc/httpd/conf/httpd.conf file  ...

Fresh release: Vim 7.1

Image
After one year and five days of waiting: a brand new Vim release! This is a stable version. There are many bug fixes and updated runtime files. No amazing new features. Upgrading from a previous version is highly recommended... Note that Vim works on Linux, Windows, Macintosh, and other systems. This is an excellent free editor with syntax highlighting that is great for programming, text manipulation, and HTML editing. If you plan to be a sysadmin, you have to learn vi. I use it for scripting, text editing, and blog posting, among other things. read more | digg story

How to Hide Files and Directories in Linux

Image
In Linux, directories are not accessible until the device is mounted. This is usually done at startup by the mount command which uses the /etc/fstab file. Files that start with a dot "." are hidden, but not completely (you can do ls -a to see the files). An example is the ~/.bashrc file. You can also hide files in a directory name that starts with a dot, e.g. ~/.ssh Now for the real trick Entire directories can be hidden, simply by mounting another device on top of the directory. The original files will still be in tact, but not visible until the device is remounted. First, find a device that is available to mount (boot is nice, because it is usually small). $ mount /dev/hda1 on /boot type ext3 (rw) ... etc... Then make your stealth directory, copy files to it, and mount a directory over it. $ cd /mnt $ mkdir stealth $ touch /mnt/stealth/somefile.txt $ ls /mnt/stealth/ somefile.txt $ mount -t ext3 /dev/hda1 /mnt/stealth ls /mnt/stealth/ config-2....

How to Copy and Paste in Linux and Windows

Image
This is a very simple topic, but sometimes little tips can save you a lot of time. Windows & Linux First select the text, or item, or location to paste to: Copy = Ctrl-c, or From the "Edit" menu, select "Copy" Cut = Ctrl-x, or From the "Edit" menu, select "Cut" Paste = Ctrl-v, or From the "Edit" menu, select "Paste" You can copy and paste text, graphics, files, etc. In Windows, you can copy and paste files within Windows Explorer, or you can drag and drop them. Linux All of the above, plus: Copy = Select text with the mouse Paste = Click the middle mouse button vi If you want to copy and paste in vi, that's another topic. To copy a line in vi, type yy (yank line), and then p (paste after), or P (paste before). To copy a word, use yw (yank word). To copy five lines -- 5 yy, or five words -- 5 yw, or to paste something five times 5p. Here are some good tips on vi http://www.vim.org/tips/tip.php?tip_id=312 . By t...