One of the things that excited me while learning Unix/Linux was how quickly one can perform tasks via the command line. Bash is a fully functional scripting language that incorporates Variables, Loops and If/Then statements; the bash shell allows a user to use these functions while performing adhoc tasks via the command line. This is also true for the other common shells such as bourne, korn shell, and csh.
Below I will show 5 example for loops that are run on the command line without being placed into a shell script.
Recently I coveredhow to increase and decrease the CPU priority of processes using nice and renice. Today I am going to cover how to change the default niceness value for a user or group.
Why change the default CPU priority value? Before explaining how to change the default niceness value, let's cover why this could be useful.
Scenario #1 You have a system that has thousands of users that log in via SSH and could potentially run CPU intensive tasks.
Nice is a command in Unix and Linux operating systems that allows for the adjustment of the “Niceness” value of processes. Adjusting the “niceness” value of processes allows for setting an advised CPU priority that the kernel's scheduler will use to determine which processes get more or less CPU time. In Linux this niceness value can be ignored by the scheduler, however other Unix implementations can treat this differently.
Being able to adjust the niceness value comes in handy in two scenarios usually.
When supporting systems you have inherited or in environments that have many different OS versions and distributions of Linux. There are times when you simply don't know off hand what OS version or distribution the server you are logged into is.
Luckily there is a simple way to figure that out.
Ubuntu/Debian $ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=13.04 DISTRIB_CODENAME=raring DISTRIB_DESCRIPTION="Ubuntu 13.04" RedHat/CentOS/Oracle Linux # cat /etc/redhat-release Red Hat Enterprise Linux Server release 5 (Tikanga) Catchall If you are looking for a quick way and don't care what the output looks like, you can simply do this as well.
Today's article is going to cover a command that falls into the “I don't use this often, but when I do it's awesome” category.
The tac command is very similar to the cat command in that it is used to concatenate and print files. However there is one very large difference, the tac command does this in reverse, starting with the last line of the file and working its way up to the first line.
The grep command is a command that most Linux users learn early on, and many times they learn to use it via pipes (stdin). Because of this some Linux users just assume that grep can only be used with stdin; it's ok, I was one of those too!
Before I continue with some grep tricks I want to clarify the basic grep usage.
Stop Doing This:
$ cat file.log | grep "something" something Do This More:
In the office I use Red Hat quite often and one of the quicker ways to provision a Red Hat server is via kickstart. There are many ways to reach a kickstart file during initial install (NFS, HTTP, FTP) but one of the ways I commonly use is to put the file on the installation DVD itself.
The below steps are what I use to add a custom directory to the installation iso file.
One of the most basic tasks for any Sysadmin is packing and unpacking files for various reasons. While there are many ways to perform this task GNU Tar is probably one of the most recognized and commonly used tools by Linux/Unix users.
A little history on tar The tar command is a command that appeared in the early days of Unix and has had several changes made over time. Originally the command was used to take files, combine them into one file and write them to a tape archive (tar).
Backups are important, whether you are backing up your databases or your wedding pictures. The loss of data can ruin your day. While there is a huge list of backup software to choose from; some good, some not so good. One of the tools that I have used for years is rdiff-backup.
rdiff-backup is a rsync delta based backup tool that both stores a full mirror and incremental changes. It determines changes based on the rsync method of creating small delta files, which allows for rdiff-backup to restore files to any point in time (within the specified retention period).
Normally on this blog I tend to write about more complicated tasks or fancy Linux tricks and completely overlook some of the most basic tasks that a SysAdmin needs to know. Today I have decided that I will make my blog a little more comprehensive and add some posts with some of the basics.
Along with this I will be starting a new category, called Sysadmin Basics and I will try to post an additional article each week that covers some of the more basic concepts and commands used by Linux and Unix Sysadmins.