Home > Articles > Open Source > Linux/UNIX/Open Source Operating Systems

This chapter is from the book

System Administration

Traditionally, Linux has been very popular with system administrators. This has been due to not only Linux’s incredible flexibility and power but also to the UNIX philosophy that drives much of the Linux platform. System administrators spend much of their day in the command line crafting strings of commands that hook together to do something interesting. With this powerful underlying command-line platform, so much is possible.

System administration is sometimes fraught with its own fair share of problems, though. This section lines up some of the problems and attempts to resolve them.

How Do I Schedule Things to Happen?

Built right into Ubuntu is a very powerful system for scheduling things to happen at specific times or at regular intervals. This system, called cron, allows you to specify the timing details and the command to run in a special file called a crontab.

The crontab is a simple text file that holds a list of commands to be run at specified times. These commands, and their related run times, are controlled by the cron daemon and are executed in the system’s background. More information can be found by viewing the crontab’s man page, and we will run through a simple crontab example soon to demonstrate how it is used.

The system maintains a crontab for each user on the system. In order to edit or create a crontab, you need to load it into a text editor. This text editor is opened when you use the -e option on the crontab command. To create a crontab, open a terminal and run the following command:

foo@bar:~$ crontab -e

The default nano text editor will open an empty crontab file. When adding crontab instructions, each line represents a separate crontab entry, also known as a cron job.

Crontab Sections

A typical line in a crontab looks like this:

00 01 3 5 6  ps ax

Each of the sections is separated by a space, with the final section having one or more spaces in it. No spaces are allowed within sections 1–5, only between them. Sections 1–5 are used to indicate when and how often you want the task to be executed. This is how a cron job is laid out from left to right:

  • Minute: (00–59)
  • Hour: (00–23; 0 = midnight)
  • Day: (1–31)
  • Month: (1–12)
  • Weekday: (0–6; 0 = Sunday)
  • Command: code

If you read each line in the crontab from the left and use these column descriptions, you can see how the instruction is built up. Here’s an example:

01 04 1 1 1 /usr/bin/somedirectory/somecommand

This example runs /usr/bin/somedirectory/somecommand at 4:01 A.M. on any Monday that falls on January 1. An asterisk (*) indicates that every instance (every hour, every weekday, every month, and so on) of a time period should be used:

01 04 * * * /usr/bin/somedirectory/somecommand

This example will run /usr/bin/somedirectory/somecommand at 4:01 A.M. on every day of every month.

Comma-separated values can be used to run more than one instance of a particular command within a time period. Dash-separated values can be used to run a command continuously:

01,31 04,05 1-15 1,6 * /usr/bin/somedirectory/somecommand

This example will run /usr/bin/somedirectory/somecommand at 1 and 31 minutes past the hours of 4:00 A.M. and 5:00 A.M. on the 1st through the 15th days of every January and June.

The /usr/bin/somedirectory/somecommand text in these examples indicates the task that will be run at the specified times. It is recommended that you use the full path to the desired commands as shown here. The crontab will begin running as soon as it is properly edited and saved.

Crontab Command Options

There are a number of options you can pass to the crontab command to make it do different things. Here are some common options:

  • The -l option causes the current crontab to be displayed on standard output.
  • The -r option causes the current crontab to be removed.
  • The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.

When you edit a crontab file, the modified crontab is checked for accuracy and, if there are no errors, installed automatically.

An Example

Following is an example of how to set up a crontab to run updatedb, which updates the slocate database. Open a terminal application, type crontab -e, and press Enter. Then type the following line into the editor, substituting the full path for the one shown here:

45 04 * * * /usr/bin/updatedb

Save your changes, and exit the editor. The crontab command will let you know if you made any mistakes. The crontab will be installed and begin running if there are no errors. That’s it. You now have a cron job set up to run updatedb, which updates the slocate database every morning at 4:45.

Note that a semicolon (;) or double ampersand (&&) can also be used in the command section to run multiple commands consecutively:

45 04 * * * /usr/sbin/chkrootkit && /usr/bin/updatedb

The semicolon will cause both commands to be executed. The double ampersand will cause the second command to execute only if the first command does not fail. This example will run chkrootkit and updatedb at 4:45 A.M. daily, provided that you have all the listed applications installed.

How Can I Copy a File from One Computer to Another?

The easiest way to copy files between machines is to use the Places > Connect to Server dialog box to make a connection using the graphical file manager. If you would prefer to do this on the command line, use the following command:

foo@bar:~$ scp file.txt jimmy@chin.com:/home/jimmy

The scp command works the same as the normal cp command, but it copies the file (here, file.txt) to another server (chin.com) using a specific user account (jimmy) and into a particular directory on the remote computer (/home/jimmy).

I Know an Application Is Available in Ubuntu, but Synaptic Can’t Find It

If you are browsing through Synaptic and can’t find a package that you know is available for Ubuntu, it is likely that you have not enabled the additional repositories.

To fix this, load Synaptic and select Settings > Repositories. Select the Community Maintained and Software Restricted by Copyright or Legal Issues checkboxes. Click Close to accept the settings and then click the Reload button to refresh the package list. Your package should now be listed.

I Am Running Ubuntu on an Older Computer, and I Would Like a Faster Desktop

Unlike other operating systems, Linux has the flexibility to scale incredibly well across different computers with different levels of horsepower. With the huge range of open source available, you can tweak your system so that it can be optimized in lots of different areas. This is particularly useful for recycling PCs. Some large organizations throw out older hardware that cannot run the latest OS from Microsoft. In many cases, these computers are actually perfectly usable if the software is optimized a little. Some open source groups have been set up to take these old machines, install Linux, and provide them to their local communities.

The first aspect to optimize is the GUI. Make certain you turn off any Desktop Effects. This can be done in the System > Preferences > Appearance tool under the Desktop Effects. After you have done that, you can change the way windows look when dragged. Open the terminal and type the following:

gconftool-2 --type bool --set
/apps/metacity/general/reduced_resources
true

Another option is to use another desktop environment, such as Xfce in Xubuntu (Figure 6-8).

You may also want to explore applications that are more lightweight. As an example, instead of using OpenOffice.org for word processing, try Abiword, a lightweight word processor than includes several features. For other types of applications, try the following alternatives:

  • Web browser: Instead of Firefox, use Galeon.
  • Terminal: Use an xterm instead of the GNOME terminal.
  • Spreadsheet: An alternative to OpenOffice.org for spreadsheets is Gnumeric.

I Reinstalled Windows, and Now Ubuntu Won’t Start!

The first thing your computer does when you turn it on is read a special place on your hard disk called the master boot record (MBR). The information written there tells the computer what to do next. When you installed Ubuntu, it placed a boot menu on the MBR that lets you choose from which system to boot.

Unfortunately, when you reinstall Windows, it will recreate the MBR, not taking into consideration that any other OS may exist and replacing it with an MBR that only boots Windows. This is no good, and you naturally want to be able to replace it with the menu that lets you choose which system to boot.

Grab the CD you used to install Ubuntu on your computer. If you don’t have it anymore, download a CD image from www.ubuntu.com/download, and burn it on a blank CD. If you used the live CD to install, you will need to use the alternative installation CD with the traditional text mode installer.

Insert the CD in the drive, and restart your computer. It will boot on the CD instead of using the hard disk. Now highlight the Rescue a Broken System line, and press Enter. Select your language and keyboard, and let the installer detect the network (for the computer name, you can leave the default Ubuntu) just as you did when you installed Ubuntu for the first time.

You will then be presented with a list of available partitions on your hard disks. Don’t worry about the first line (/dev/discs/disc0/part1). Start looking at the other lines. You need to remember on which disk and on which partition Ubuntu is installed. Most of the time, you probably have just one disk. If you have Windows installed on it, it is probably located on the first partition of this disk, and Ubuntu should be on the second one. Therefore, you probably want to select /dev/discs/disc1/part2 (and then press Enter), unless your situation is more complex.

On the last screen, select the first line, Execute a shell in.... You can now enter commands. Start by mounting the disks on your system:

foo@bar:~# mount -a

Now type:

foo@bar:~# df

Look at the list printed on the screen. Search the last column for the single / character, and on the corresponding line look for the first column. It should say something such as /dev/hda2 (the last few characters may be different for you). Now type the following command, and replace /dev/hda with what you have just read, but without the last digit (e.g., without the 2 from /dev/hda2):

foo@bar:~# grub-install /dev/hda

Wait for the process to finish. It might take a few minutes. About a dozen lines should have appeared on the screen. Check whether you find the text installation finished. If you do, everything went fine. You can now restart your computer by typing this:

foo@bar:~# exit

Eject the CD, and then select Reboot the System. Welcome back to Ubuntu!

How Do I Fix My Disk After a Power Failure?

Although the Ubuntu development team takes every care to ensure every possible situation is catered for, power cuts are one of the most difficult problems to resolve. Computers rely on power, and when it is dramatically removed from the system, the whole Ubuntu world in your computer shuts down immediately. The problem with this is that sudden power failure causes your Ubuntu machine to shut down improperly. When you next start the computer, you may then be prompted with a confusing fsck message. What is this, and how do you fix it?

The fsck program is a little tool to fix hard disks that don’t have consistent filesystems, that is, filesystems typically made inconsistent by power failures. When the disk is inconsistent, Ubuntu automatically runs fsck to fix it. It asks you a bunch of questions that only a filesystem developer really understands, and you feel obliged to say Yes to each of them. As such, you sit there hammering the Y key over and over answering the questions.

There is a quick and simple fix to this problem. Instead of wearing out your Y key, you can simply edit one file and have any errors automatically fixed for you.

If your system is already running the desktop, open a terminal. Enter the following command:

foo@bar:~$ sudo gedit /etc/default/rcS

Now change the FSCKFIX line to the following:

FSCKFIX=yes

Save the file, and the next time you reboot, fsck will fix any detected disk problems without you having to intervene.

If you are using the character-based login, use the following command:

foo@bar:~$ sudo nano /etc/default/rcS

Change the FSCKFIX line as above, and then press Ctrl-O and Ctrl-X to save and exit.

Ubuntu Takes Up Too Much Disk Space on My Old Computer

If you are running Ubuntu on an older computer with a limited amount of disk space, you may want to choose software with more limited space requirements. Luckily, Ubuntu gives you incredibly flexible options when you’re choosing which software you want to install. There is a variant of Ubuntu specifically for older computers, called Xubuntu. Xubuntu is based on Xfce, which is a lighter desktop than KDE or GNOME. To install Xubuntu on an existing Ubuntu system, install the xubuntu-desktop package. You can also download an .iso file of Xubuntu at www.xubuntu.org.

My Computer Is Running Quite Slowly—How Can I Find Out What Is Going On?

If you are having performance problems, there may be a particular process on your computer gobbling up all of the memory. Launch the System Monitor under the System > Administration menu and go the Processes tab. You will see which applications are using more CPU and RAM. You can also use top on the command line:

foo@bar:~$ top

The top command shows the current processes on your computer that are using the most system resources. If you see a particular program taking up an unusual amount of resources, that may be the culprit.

Some processes (such as the Apache Web server) fork and replicate themselves when used. Another useful technique is to see how many of these processes are running:

foo@bar:~$ ps ax | grep theprogram | wc -l

This command takes a listing of the processes running on the system, uses grep to search for a specific process, and then counts the number of lines returned, thus indicating how many processes are running.

How Can I Learn the Different Options for Commands?

Every command in Ubuntu has a small reference card included called a man page. This page displays the range of available options. Access it by typing man, and then enter the command:

foo@bar:~$ man grep

Another method of listing the options is to use the -h or -help options:

foo@bar:~$ grep --help

How Do I Get My Root Account Back?

In a default Ubuntu installation, the root account is disabled. Instead, the user account created during the installation process is used with sudo to access administer facilities. The sudo command is used extensively to temporarily take on root privileges when needed.

If you want to get the root account back, run the following command:

foo@bar:~$ sudo passwd root

Enter your user account’s password, and then enter a new root password. You will be asked to verify the new root password.

To disable the root account at a later date, run the following command:

foo@bar:~$ sudo passwd -l root

This will lock the root account.

I Forgot My System Password—What Can I Do?

Although passwords are indefinably essential and useful, they are also prone to being forgotten. With an increasing number of nasties out there on the Internet wanting to suck away your passwords, you need to think of more complex passwords, which are in turn harder to remember and easier to forget.

If you forget the system password, you need to jump through a few more hoops to reset your password. Restart your computer, and when you see the word GRUB appear on the screen, press Escape to see the boot menu. Select the recovery mode option from the menu. When the computer boots, it will present you with a root shell. At the prompt type:

foo@bar:~# passwd username

Follow the prompts to set a new password. Finally, reboot the computer with the following command:

foo@bar:~# reboot

How Do I Access My Windows Partitions?

If you are running Ubuntu on a computer with a Windows disk, you may want to read and write to the disk. Look on your Desktop for an icon labeled sda1 or hda1. This is your Windows partition.

How Do I Add Users?

To add a new user to your computer, select System > Administration > Users and Groups. When the window loads, click the Add User button, and then just fill in the details. To do this in the command line, use the adduser command:

foo@bar:~$ sudo adduser jimmy

This adds a user called jimmy.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020