• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Tuesday, April 20, 2010

Posted by venu k
9 comments | 6:05 AM

Using tput command:


#!/bin/bash
# SCRIPT: digclock.sh
# USAGE: ./digiclock &
# PURPOSE: Displays time and date in the top right corner of the
# screen using tput command.
# To stop this digclock use command "kill pid"
################################################################

####################### VARIABLE DECLARATION ###################

# To place the clock on the appropriate column, subtract the
# length of $Time and $Date, which is 22, from the total number
# of columns

Columns=$(tput cols)
Startpoint=$(($Columns-22))

# If you're in an X Window System terminal,you can resize the
# window, and the clock will adjust its position because it is
# displayed at the last column minus 22 characters.

Color1=`tput setab 2` # Green background color for time
Color2=`tput setab 6` # Cyan background color for date
Normal=`tput sgr0` # back to normal screen colors

####################### MAIN PROGRAM ###########################

# The script is executed inside a while without conditions

while :
do
Time=`date +%r`
Date=`date +"%d-%m-%Y"`
tput sc #Save the cursor position&attributes
tput cup 0 $Startpoint

# You can also use bellow one liner
# tput cup 0 $((`tput cols`-22))
# But it is not efficient to calculate cursor position for each
# iteration. That's why I placed variable assignment before
# beginning of the loop.

# print time and date in the top right corner of the screen.

echo -n $Color1$Time $Color2$Date$Normal

# restore the cursor to whatever was its previous position

tput rc

# Delay for 1 second

sleep 1

done


Using ANSI escape sequences:


The ANSI escape sequences don't work in all terminal emulators, but
they do fine in xterm. Here's the script:

#!/bin/bash
# SCRIPT: digclock.sh
# USAGE: ./digiclock &
# PURPOSE: Displays time and date in the top right corner of the
# screen using ANSI escape sequences.
# To stop this digclock use command kill pid.
################################################################

#################### VARIABLE DECLARATION ######################

# To place the clock on the appropriate column, subtract the
# length of $Time and $Date, which is 22, from the total number
# of columns

Columns=$(tput cols)
Startpoint=$(($Columns-22))

# If you're in an X Window System terminal,you can resize the
# window, and the clock will adjust its position because it is
# displayed at the last column minus 22 characters.

########################### MAIN PROGRAM #######################

# The script is executed inside a while without conditions.

while :
do
Time=`date +%r`
Date=`date +"%d-%m-%Y"`
echo -en "\033[s" #save current screen position & attributes

tput cup 0 $Startpoint

# You can also use bellow one liner.
# tput cup 0 $((`tput cols`-22))
# But it is not efficient to calculate cursor position for each
# iteration. That's why I placed variable assignment before
# beginning of the loop

# print time and date in the top right corner of the screen

echo -en "\033[42m$Time \033[46m$Date\033[0m"

#restore current screen position & attributes

echo -e -n "\033[u"

#Delay for 1 second

sleep 1
done

Save the script as digclock.sh,change permissions to 755 using chmod,
and run it with ./digclock.sh & or . digclock.sh & or sh digclock &.
The time and date should now appear at the top right of your screen.

Output:



When you run digclock.sh, the terminal will return the job number and
process identifier (PID) of the digclock.sh process. From above output
you can find job number is "1" and PID is "15800".

You can end the execution of the script by two ways:

1. Using the kill command and specifying the job number or process ID.
If you don't remember job number or PID, you can get job number by
running jobs command and PID by ps command.

$ jobs
[1]+ Running ./digclock.sh &
$ shell]# ps | grep digclock
15800 pts/1 00:00:00 digclock.sh

To kill this job/process, either kill %1 or kill 15800 works.

$ kill %1
$
[1]+ Terminated ./digclock.sh
or
$ kill 15800
$
[1]+ Terminated ./digclock.sh

2. Using the fg command. The fg command switches a job running in the
background into the foreground, Then press Ctrl+c to terminate the
job. If no job number is specified, then fg command acts upon the
currently running job.

$ fg 1
./digclock.sh

Ctrl+c
$

With this script, you can display not only a clock, but other useful
information as well. For example,monitoring free space with df command
or CPU's load average with uptime command. Samba, Apache, and many
other servers have status commands where you can extract pieces of
information to show this way.

9 comments:

  1. hey thanks it was a great help.............zoya

    ReplyDelete
  2. Wonder full post and this article tell us how reset your time and date thanks for share it personal statement editor .

    ReplyDelete
  3. Financial research outsourcing
    TopAssociate is a specialist provider of outsourcing and offshoring solutions for the global financial and investment community. We provide a very comprehensive range of high quality analytics - TopAssociate,Investment research outsourcing,hedge fund research outsourcing,M&A research outsourcing,Private equity research outsourcing,Equity research outsourcing,Financial analyst outsourcing,Customised financial research,Fixed income research outsourcing,Financial research outsourcing

    ReplyDelete
  4. Thanks for your informative guide on SQL technology. As we all know, SQL is most used database tool and your article offer clear insight about the technology. Your blog is recommended for freshers and experienced ones looking for ideal blog to learn SQL technology. Java Training in Chennai

    ReplyDelete
  5. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai JavaEE Training in Chennai JavaEE Training in Chennai

    ReplyDelete