Linux System Administration

Today I have tried to install RHEL6 i386 as a virtual machine using virtualbox. Right after startup I got a error message saying:

This kernel requires the following features not present: pae
Unable to boot - please use a kernel appropriate for your CPU

If you get this error enable PAE/NX on your virtual machine by navigating to:

Settings->System->Processor->Extended Features and tick: PAE/NX

This is a simple skeleton of a bash countdown script. The script takes two arguments . Here are some examples of its usage:

  • countdown time to 90 minutes from now:
./bash-countdown.sh -m 90
  • countdown time to 23.3.2036 from now:
./bash-countdown.sh -d "Mar 23 2036"
  • countdown time to 21:06 from now:
./bash-countdown.sh -d 21:06
  • countdown time to 21:06:45 from now:
./bash-countdown.sh -d 21:06:45

Feel free to modify this script according to your needs. Git repository: Countdown

countdown.sh :

#!/bin/bash 
 
if [ "$#" -lt "2" ] ; then 
	echo "Incorrect usage ! Example:" 
	echo './countdown.sh -d  "Jun 10 2011 16:06"' 
	echo 'or' 
	echo './countdown.sh -m  90' 
	exit 1 
fi 
 
now=`date +%s` 
 
if [ "$1" = "-d" ] ; then 
	until=`date -d "$2" +%s` 
	sec_rem=`expr $until - $now` 
	echo "-d" 
	if [ $sec_rem -lt 1 ]; then 
		echo "$2 is already history !" 
	fi 
fi 
 
if [ "$1" = "-m" ] ; then 
	until=`expr 60 \* $2` 
	until=`expr $until + $now` 
	sec_rem=`expr $until - $now` 
	echo "-m" 
	if [ $sec_rem -lt 1 ]; then 
		echo "$2 is already history !" 
	fi 
fi 
 
_R=0
_C=7
tmp=0
percent=0
total_time=0
col=`tput cols`
col=$[ $col -5 ]

while [ $sec_rem -gt 0 ]; do 
	clear 
	date 
	let sec_rem=$sec_rem-1 
	interval=$sec_rem 
	seconds=`expr $interval % 60` 
	interval=`expr $interval - $seconds` 
	minutes=`expr $interval % 3600 / 60` 
	interval=`expr $interval - $minutes` 
	hours=`expr $interval % 86400 / 3600` 
	interval=`expr $interval - $hours` 
	days=`expr $interval % 604800 / 86400` 
	interval=`expr $interval - $hours` 
	weeks=`expr $interval / 604800` 
	echo "----------------------------" 
	echo "Seconds: " $seconds 
	echo "Minutes: " $minutes 
	echo "Hours:   " $hours 
	echo "Days:    " $days 
	echo "Weeks:   " $weeks 

	echo -n "["

	progress=$[$progress + 1]
	if [ $total_time -lt 1 ] ; then
		total_time=$[$hours * 3600 + $minutes * 60 + $seconds]
	fi
	
	printf -v f "%$(echo $_R)s>" ; printf "%s\n" "${f// /=}"
	_C=7
	tput cup 7 $col

	tmp=$percent
	percent=$[$progress * 100 / $total_time]
	printf "]%d%%" $percent
	change=$[$percent - $tmp]

	_R=$[ $col * $percent / 100 ]

	sleep 1
done
printf "\n"

Do not forget to make bash-countdown.sh script executable before execution:

$ chmod +x countdown.sh

Exectute:

$ ./countdown.sh -d 08:50

Output:

Fri Apr 10 08:47:46 AEST 2015
----------------------------
Seconds:  13
Minutes:  2
Hours:    0
Days:     0
Weeks:    0
[========>                                                                 ]12%

Not everyone has unlimited Internet download. Sometimes Internet provides provide peak and off-peak hours and hardly is someone going to stay up at night to trigger their downloads.

There are many tools in Linux which allows user to set a timer to automatically start download without user intervention. Here is a simplest form of automatic off-peak download involving at, wget and shutdown command. First create a file which will contain wget and shutdown commands:

mydownloads.txt:

wget ftp://ftp.redhat.com/pub/redhat/rhel/beta/6/i386/iso/RHEL6.0-20100414.0-AP-i386-DVD1.iso
wget http://ftp.monash.edu.au/pub/linux/CentOS/5.5/isos/i386/CentOS-5.5-i386-bin-DVD.iso
shutdown -h now

Now use at command to execute all command within mydownloads.txt file:

at -m 02:00 < mydownloads.txt

At command will automatically start download at 2AM and when downloads are finished it will shutdown your PC.

NOTE: For shutdown you need sudo or run command as root

Page 63 of 72



Free Linux eBooks

Go to top