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...

C Programming: sizeof variable types...

As you know C programming language has different variable types and each of them use different byte size. Do you wonder how to find size of each variable type in C? Look at the program below. Program: int main() {   printf("sizeof(char) == %d\n", sizeof(char));   printf("sizeof(short) == %d\n", sizeof(short));   printf("sizeof(int)...

Linux: fork() system call with an example...

fork() creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited. Under Linux, fork() is implemented using copy-on-write pages, so the only penalty that it incurs is the time and memory required to duplicate the parent’s page tables, and to create a unique task structure for the child. RETURN...

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

« Previous Entries