Using the hwclock Command

Use the hwclock command to display or set your Linux system time, display or set your PC's hardware clock, or to synchronize the system and hardware times. To see your hardware date and time, use hwclock with its --show option like so:

# hwclock --show

Fri 27 Jan 2006 02:17:53 PM GMT -0.193809 seconds

Use hwclock with its --set and --date options to manually set the hardware clock like so:

# hwclock --set --date '01/27/06 08:00:00'

# hwclock --show

Tue 27 Jan 2006 08:00:08 AM GMT -0.151718 seconds

In these examples, the hardware clock has been set with hwclock, which is then used again to verify the new hardware date and time. You can also hwclock to set the Linux system date and time date, using your hardware clock's values with the Linux system date and time.

For example, to set the system time from your PC's hardware clock, use the --hctosys option as follows:

# hwclock --hctosys

Capturing Screen Images

Although you're working at the command line rather than a swish GUI, you can still grab images from your graphical desktop through the import command, and that's exactly what we did to capture the images for this book.

First, we ran xhost + on the remote computer to allow another computer access to the X server on the remote machine; the command to take the screenshot is run on our local machine like this:

$ import -window root -display 192.168.2.4:0 12fig07.jpg

This utility made a difficult task easy because the publisher required the screenshots be done from an 800?600 screen (too small to comfortably work in) to accommodate its printing and production equipment.

We could also have used the classic UNIX tool xwd to take screenshots. The command would have looked similar to that of import:

$ xwd -root -display 192.168.2.4:0 -out 12fig07.jpg

Reference

http://www.gnu.org/ — The website of the GNU project, it contains manuals and downloads for lots of command-line software.

http://www.linuxdevcenter.com/linux/cmd/ — A wide selection of Linux commands and explanations of what they do.

http://www.tuxfiles.org/linuxhelp/cli.html — Several short command-line tutorials, courtesy of tuXfiles.

http://www.linuxcommand.org/ — Describes itself as 'your one-stop command line shop!' It contains a wealth of useful information about the console.

http://www.tripwire.org/ — Information and download links for the open source version of Tripwire.

Books

Understanding the way UNIX works at the nuts-and-bolts level can be both challenging and rewarding, and there are several good books that will help guide you on your way. Perhaps the best is The Art of UNIX Programming, by Eric Raymond (Addison-Wesley, ISBN: 0-13-142901-9), which focuses on the philosophy behind UNIX and manages to mix in much about the command line.

O'Reilly's UNIX CD Bookshelf (ISBN: 0-596-00392-7) contains seven highly respected books in one, although it retails for more than $120 as a result! That said, it is incomparable in its depth and breadth of coverage.

CHAPTER 33

Writing and Executing a Shell Script

Why should you write and use shell scripts? Shell scripts can save you time and typing, especially if you routinely use the same command lines multiple times every day. Although you could also use the history function (press the Up or Down keys while using bash or use the history command), a shell script can add flexibility with command-line argument substitution and built-in help.

Although a shell script doesn't execute faster than a program written in a computer language such as C, a shell program can be smaller in size than a compiled program. The shell program does not require any additional library support other than the shell or, if used, existing commands installed on your system. The process of creating and testing shell scripts is also generally simpler and faster than the development process for equivalent C language commands.

NOTE

Hundreds of commands included with Fedora are actually shell scripts, and many other good shell script examples are available over the Internet — a quick search yields numerous links to online tutorials and scripting guides from fellow Linux users and developers. For example, the startx command, used to start an X Window session from the text console, is a shell script used every day by most users. To learn more about shell scripting with bash, see the Advanced Bash-Scripting Guide, listed in the 'Reference' section at the end of this chapter. You will also find Sams Teach Yourself Shell Programming in 24 Hours a helpful guide to learning more about using the shell to build your own commands.

When you are learning to write and execute your first shell scripts, start with scripts for simple but useful tasks. Begin with short examples, and then expand the scripts as you build on your experience and knowledge. Make liberal use of comments (lines preceded with a pound # sign) to document each section of your script. Include an author statement and overview of the script as additional help, along with a creation date or version number. Use a text editor such as vi to write shell scripts because it does not automatically wrap lines of text. Line wrapping can break script syntax and cause problems. If you use the nano

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату