nav-left cat-right
cat-right

Bash script to generate cPanel user files...

Don’t have your domains listed in WHM/cPanel. The cPanel takes information from cPanel user files under /var/cpanel/users/. The accounts won’t be listed in WHM if corresponding files are missing. This script will help you to generate cPanel user files. This script may fail if you have cPanel user files existing under /var/cpanel/users/. So I would request you to backup users directory and then remove all user...

Bash puzzle: Unset last element of an array...

Here is a puzzle for bash lovers. This is taken from shell scripting community at Orkut. Question: How to reset last element of an array even if it’s a discontinuous array. Answer: $ array=([0]=a [9]=d [2]=i [6]=k); echo "${array[@]}" a i k d $ : ${!array[@]} $ unset array[_] $ echo "${array[@]}" a i k If you are not familiar with bash, you might...

Awk FS (Input Field Separator), OFS (Output Field ...

I would like to explain a simple behavior by awk that I noticed while writing a script. #!/bin/awk -f BEGIN { FS=":"; OFS="-"; } { $2=""; print } Give this script the password file, it will delete the password field, but leave everything else the same after changing output field separating to hyphen(-). This works fine, but OFS won’t be effective if you remove the...

Linux Time Fields: Access (atime), Modify (mtime),...

Linux saves 3 different time fields per file in inode. They are access, modify and change time and you can use stat command to get them. As far I know, Linux never stores file creation time (for good or bad, I doubt ). Some guys are not sure about the difference between modify and change time. As I study mostly from man pages, I’m pasting relevant sections from the man page for stat system call. man -s 2 stat time_t...

Start AWK programming...

Awk is a pattern scanning and processing language. It’s essentially a stream editor, like sed. You can pipe text to it, and it can manipulate on a line-by-line basis. Awk can also read from a file and then process on a line-by-line basis. Unlike sed, it has the ability to remember context, do comparisons, and most things another full programming language can do. The simplest form of awk is a one-liner: awk '{ do-something-here...

Bash Script: backup your data directories and mysq...

You can use this script to backup your data directories and mysql databases. Please note that this script is designed to retain only a single backup copy at the remote server. You can download the script from here. #! /bin/bash ######################################################################################### #                              ...

How to create a chkconfig service?...

How to create a chkconfig service? Did you ever wonder how to add your custom script/service to chkconfig so that it can start automatically when the server boots up? Read below for more details. chkconfig – updates and queries runlevel information for system services chkconfig provides a simple command-line tool for maintaining the /etc/rc[0-6].d directory hierarchy by relieving system administrators of the task...

sed: match words...

The escaped angle brackets are your solution if you wanna match exact words, not their parts. The angle brackets must be escaped, since otherwise they have only their literal character meaning. \<word\> -- mark word boundaries Example: $ echo "for forward" |sed 's/for/XXX/g' XXX XXXward $ echo "for forward"|sed 's/\<for\>/XXX/g' XXX forward ~mohammed

SED: change/insert/append lines after matching a p...

Do you want to change/insert/append lines after matching a pattern from a file? If yes, you can use sed to do that. I’m pasting the relevant parts from sed manpage followed by some examples. a \ text - Append text, which has each embedded newline preceded by a backslash. i \ text - Insert text, which has each embedded newline preceded by a backslash. c \ text - Replace the selected lines with text, which has each...

Linux commands: cut and paste...

cut and paste can be handy sometimes, especially when you have to manipulate files based on rows and columns. simple usages of cut and paste: file1 ****** first second first second first second file2 ****** 3 4 3 4 3 4 Let me say, I want to cut first column of file2 and paste them as last column of file1. Here you go # cut -d" " -f1 file2 |paste -d" " file1 - first second 3 first second 3 first second...

« Previous Entries