FAQ Updates: April/03/2012

Posted on in Categories Sys admin last updated April 3, 2012

Our FAQ section has been updated. Here are latest howtos:

Make the most of nixCraft FAQ Section

Get intimated about our new howtos / faqs as soon as it is released via RSS feed OR follow us on twitter OR join our 20k+ facebook fans for more tips and news about Linux.

How To Use vi as Default Editor and Viewer in Midnight Commander

Posted on in Categories File system, Howto, Linux, Shell scripting, Tips, UNIX last updated November 25, 2012

Midnight Commander (mc) is an user-friendly text-based file manager UI for Unix. Using mc, you can browse the filesystem easily and manipulate the files and directories quickly. You will not miss the standard command line prompt, which is also available within the mc itself. If you are new to mc, Midnight Commander (mc) Guide: Powerful Text based File Manager for Unix article will give you a quick jumpstart. In this article, let us review how to solve couple of common annoyance about viewing a file in mc.

Interesting stuff – Aug 8, 2008

Posted on in Categories Links, Linux, News last updated August 8, 2008

=> Cisco 7200 Simulator for Linux. If you decided to study for the Cisco certification, this tool may come handy. Howtoforge has detailed tutorial on setting up a Cisco lab on Linux system. Dynagen is a front-end for use with the Dynamips Cisco router emulator. It uses an INI-like configuration file to provision Dynamips emulator networks. It takes care of specifying the right port adapters, generating and matching up those pesky NIO descriptors, specifying bridges, frame-relay, ATM switches, etc. It also provides a management CLI for listing devices, suspending and reloading instances, determining and managing idle-pc values, performing packet captures, etc.

=> You can capture video of all of the amazing things happening on your desktop with one of Linux’s many screencasting applications. These programs are perfect for creating demonstrations for blogs and tutorials, and for illustrating projects with more than just still images.

=> Postfix Daily Quota reportA shell script hack to create daily quota report for a Posfix mail server including file system usage of each e-mail account.

=> The developers of Firefox have unveiled an experimental project, Snowl, designed to gather all your inbound communications, whether they’re in the form of email, RSS, Twitter, or social network updates.

=> IBM has marked its 10 years of participation in Linux and open source with an open source code contribution focused on supercomputing. The software is available immediately from a software repository run by the University of Illinois’s National Center for Supercomputing Applications (NCSA).

=> Regular nixcraft contributed Ramesh has published simple 6 steps to secure home wireless router / network

=> LinuxLeak is a new daily destination for all your Linux and Open Source news headlines, updated every 15 minutes.

Rotate FTP Backup Using a Shell Script

Posted on in Categories Backup, Howto, Linux, RedHat/Fedora Linux, Shell scripting, Tips, Ubuntu Linux, UNIX last updated January 20, 2008

I’ve already written about rotating sftp / ssh backup shell script to remove directories (old backup files). However, a few of our readers would like to know more about removing old backup directories using ftp. As usual, you need accurate date and time on local system and remote backup directory must be in dd-mm-yyyy or mm-dd-yyyy format. For example daily mysql backup should be stored in /mysql/dd-mm-yyyy format.

Sample Shell Script

Here is a simple and dirty shell script to remove old backups ( download link ):

#!/bin/bash
# call ./script.sh 03-2007 - to remove all March-2007 directories in 01-03-2007, 02-03-2007, 31-03-2007 format
# you must have ncftp ftp client installed on BSD / Linux box
BASE="/mysql" # base dir below that dd-mm-yyyy
[ $# -eq 0 ] && exit 1 || :
DELETE="$1"
echo "Getting old directories..."
ncftpls -u 'ftp-user-name' -p 'ftp-password' -x "-t" ftp://ftp.your-server.com${BASE} > /tmp/ftp.out
LIST="$(grep ${DELETE} /tmp/ftp.out)"
echo -n "Starting removal for ${DELETE}..."
for dir in $LIST
do
 rdir="${BASE}/${dir}"
# echo "Processing ${dir}..."
 ncftp -L -u 'ftp-user-name' -p 'ftp-password' ftp.your-server.com <<EOF
 cd $rdir
 rm *
 rmdir $rdir
 quit
EOF
done

Run the script as follows to remove all backup for Dec-2007, enter:
$ ./script.sh 12-2007

Related: Generate backup ftp script using php based wizard

How to: Check the bash shell script is being run by root or not

Posted on in Categories CentOS, Debian Linux, FreeBSD, Linux, RedHat/Fedora Linux, Shell scripting last updated January 6, 2008

Sometime it is necessary to find out if a shell script is being run as root user or not.

When user account created a user ID is assigned to each user. BASH shell stores the user ID in $UID variable. Your effective user ID is stored in $EUID variable. You can

Old way…

You can easily add a simple check at the start of a script:

Check the script is being run by root user

#!/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# ...

New way: Using EUID

#!/bin/bash
# Init
FILE="/tmp/out.$$"
GREP="/bin/grep"
#....
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# ...

Mount /dev/sdb1 only if you are a root

#!/bin/bash
if [[ $EUID -ne 0 ]]; then
  echo "You must be a root user" 2>&1
  exit 1
else
  mount /dev/sdb1 /mnt/disk2
fi

Updated for accuracy and more examples.