Tag Archives: Linux

Mounting Windows Shares in Linux

I’ve needed to mount CIFS shares (Windows network shares) from Linux before, and it’s usually not a problem. It’s as easy as the mount command with a few options – for example:

mount -t cifs //windowsbox/sharename /mnt/point

That command will use the caller’s username – since root is typically the only one allowed to mount file systems, it will try to authenticate with the Windows machine with the username “root.” You’ll be prompted for a password as well.

To specify a username to use for Windows authentication, use the ‘-o’ flag with a string of arguments, without spaces:

mount -t cifs -o username=ben //windowsbox/sharename /mnt/point

You can also throw the password in there, separating it from the username with a comma:

mount -t cifs -o username=ben,password=myP@ss\&ord //windowsbox/sharename /mnt/point

Note that you will need to escape any reserved characters from this command, such as the ampersand ‘&’ I have escaped in the example above.

However, if you wanted to mount this automatically, you’d have to add a new line to /etc/fstab to include the filesystem you want to mount. The line in /etc/fstab to mount the filesystem mentioned above would be something like

//windowsbox/sharename  /mnt/point  cifs  username=ben,password=myP@ss&ord  0  0

This will work all day long. However, there’s a problem: your password is in plain text in /etc/fstab, which is a file any user on the system can read. The best way to solve this is to put your credentials in a text file readable only by root, and then having /etc/fstab refer to this credentials file rather than including the username and password in the fstab line. According to the man page, the credentials file can have three lines in it:

username=value
password=value
domain=value

Another note: you don’t need to escape reserved characters in fstab or in the credentials file. You might want to store the file somewhere in root’s home directory or somewhere else that isn’t globally readable. Ownership should be root:root and permissions would be best at 600. If I stored the file at /root/creds.crd, the fstab line would then be

//windowsbox/sharename  /mnt/point  cifs  credentials=/root/creds.crd  0  0

Standard users would be able to see where the credentials were stored, but they would not be able to see those credentials.

Of course, if I missed anything you’ll let me know, right?

xargs Reminder

I remember using xargs at a previous workplace for pasting a multi-line text list (say, from a text file on my desktop) to generate a space-delimited line of text containing the items in the pasted list. For the life of me this morning I couldn’t remember how to do it, and most examples don’t use xargs in this way. Here’s my reminder that I hope might help others.

Say I had this list of students in a text file that looked like:

mary
bob
susan
jim
jennifer
xavier

and I needed to generate a quick Bash one-liner to process something for them on the command line.  If I wanted to use a for loop on the command line, I’d supply the for loop with a list of things separated by a space.  For example:

for x in bob sue larry
> do
> echo "Hi $x"
> done

and the output will be:

Hi bob
Hi sue
Hi larry

On to xargs: say those names are in a text file on my desktop, with one name per line:

mary
bob
susan
jim
jennifer
xavier

If I copy the text from the file and paste it into the Linux command window, each name will be on a separate line and be interpreted as a command:

$ mary
-bash: mary: command not found
$ bob
-bash: bob: command not found
$ susan
-bash: susan: command not found
$ jim
-bash: jim: command not found
$ jennifer
-bash: jennifer: command not found
$ xavier
-bash: xavier: command not found

Using xargs, I can paste the list into the window and get all the names on one line, each separated by a space.  I will type xargs <<EOF and press enter, then paste my text.  The ‘EOF’ part of the command specifies the end-of-file string, which is needed to tell xargs when I’m finished with the input.  After I paste the list, I enter EOF to finish the command:

$ xargs <<EOF
> mary
> bob
> susan
> jim
> jennifer
> xavier
> EOF

And the output:

mary bob susan jim jennifer xavier

I can then copy this single line and paste it in the for loop.  Sure, it’s not really efficient with three items, but it sure makes things easier when you’re working with 100 server names.

Clearing out a MySQL Database with One Long Bash Command

IMG_2196The need arose yesterday to drop all tables from a database so I could re-create a WordPress installation.  Sure, I could have dropped the database and re-created the entire thing, but that wouldn’t have been much of a challenge and I wanted to easily keep the same credentials and permissions on the database.

However, the number of tables exceeded my laziness.  There was a Drupal installation in addition to an old, unrelated WordPress site – perhaps around forty tables total.  I found a script that would do this, but it was also too involved.  I ended up with a fairly simple bash loop that did the trick. 

I’m using CentOS Linux and connecting to another CentOS Linux server running MySQL 5.1.69 for this article. Here’s how it worked in a not-so-brief explanation:

Overall, I simply needed to connect to the database and drop every table.  There isn’t any DROP-ALL-TABLES sort of command that I know of, so they must be dropped one-by-one.  Let’s get a list of tables to drop, shall we?

$ mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;'
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+

There – that did it, but we don’t need all those pipe symbols in the output.  Pipe it through awk:

$ mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;' | awk '{ print $1}'
Tables_in_wordpress
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_term_relationships
wp_term_taxonomy
wp_terms
wp_usermeta
wp_users

And voila!  A simple list of all table names in this database.  You could easily filter this output to capture only a subset of table names with different prefixes (‘wp_’, ‘blog_’, etc..) if you didn’t need to list all of the tables.  The top of this list still includes the output column header, so we can just grep -v it right on out of there…

$ mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;' | awk '{ print $1}' \
| grep -v "^Tables_"
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_term_relationships
wp_term_taxonomy
wp_terms
wp_usermeta
wp_users

…and the list is clean.  Now we just have to drop each of those tables.  If we surround that entire command with tick marks (`) bash will run the command and capture the output.  We can use that output as an iterable list.  The For loop knows how to use this list – we just need to tell it what to do with each item.  So here we go:

$ for x in `mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;' \
| awk '{ print $1}' | grep -v "^Tables_"`
> do
> echo $x
> done
wp_commentmeta
wp_comments
wp_links
wp_options
wp_postmeta
wp_posts
wp_term_relationships
wp_term_taxonomy
wp_terms
wp_usermeta
wp_users

The previous example just prints each item in the list – this is useful to us in that we know exactly what’s in the list.  With this knowledge we can put each item (each table name, that is) in an SQL statement to drop the tables.  Let’s make sure we can do that by printing some SQL statements:

$ for x in `mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;' \
| awk '{ print $1}' | grep -v "^Tables_"`
> do
> echo 'DROP TABLE $x;'
> done
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;
DROP TABLE $x;

Uh-oh!  See what happened there?  The literal string ‘$x’ was printed instead of the variable’s value.  That’s an important difference between using single-quoted (‘) and double-quoted (“) strings.  Single-quoted strings will literally print what you put in them, and double-quoted strings will allow you to substitute variables.  Let’s change the single-quotes to double-quotes:

$ for x in `mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;' \
| awk '{ print $1}' | grep -v "^Tables_"`
> do
> echo "DROP TABLE $x;"
> done
DROP TABLE wp_commentmeta;
DROP TABLE wp_comments;
DROP TABLE wp_links;
DROP TABLE wp_options;
DROP TABLE wp_postmeta;
DROP TABLE wp_posts;
DROP TABLE wp_term_relationships;
DROP TABLE wp_term_taxonomy;
DROP TABLE wp_terms;
DROP TABLE wp_usermeta;
DROP TABLE wp_users;

Success!  We now have everything we need to drop the tables.  Just change the echo statement in the loop to a mysql statement with the proper credentials and bash will run those commands:

$ for x in `mysql -h db01 -u user -pP@ssword wordpress -e 'SHOW TABLES;' \
| awk '{ print $1}' | grep -v "^Tables_"`
> do
> mysql -h db01 -u user -pP@ssword wordpress -e "DROP TABLE $x;"
> done

There won’t be any output unless there is an error. For each of the table names, an SQL DROP statement will be issued to the database.

If you would like to read more on the commands I used, feel free to visit some of the documentation for them:

It goes without saying that you should be careful with these operations and most database maintenance should be handled by a knowledgeable database administrator – especially in a production environment. My purpose here was only to experiment with bash and do something I hadn’t done before, and the database I was working with wasn’t currently in production.  I highly recommend against trying these things on a database your organization depends on.

Linux and NTFS

I’ve been through this before and had to look it up again today.  This post is simply a reminder for the inevitable next time I can’t remember it.

I typically install CentOS on a box or in a VM with minimal packages so I can bring in only what I need.  I did just such a thing yesterday to have a machine I can use to rsync data here and there, and do some remote administration.

One primary purpose was to take my backup drives from my house and sync to a share on a storage array at work.  This serves as my off-site backup consolidation.

Instead of tying up a Windows machine and using their experimental SyncToy (which has been performing worse and worse lately), I chose to use a Linux-powered data management machine.  It will eventually synchronize the local backups at home to the storage array at work, but there’s only so much time…

Anyway, my little 1TB external drives are formatted in NTFS, and we all know that’s not a native Linux filesystem.  We’ll have to install a library.  We had to do the same thing to mount a Windows network share (CIFS), a library which was readily available in the default YUM repository – no problem.

The utility needed for NTFS is not, however.  It’s found in the Extra Packages for Enterprise Linux (EPEL) repository, available from the Fedora project.  This is a very long way of saying that you need to enable the EPEL repo by installing the proper RPM (currently available here for EL6 x86_64), and then install the ntfs-3g NTFS userspace library package with YUM.

Keep in mind that there are a lot of other cool things in EPEL, but at present you just need to remember this one.

Install GNOME Desktop through YUM

When you install something like CentOS with 512MB RAM, the graphical installer doesn’t launch due to the memory restriction and you are relegated to a text-based install.  It’s a colorful CUI (chewy; command-line user interface) and the installer doesn’t let you choose packages (at least in CentOS 6).  You get a very small “minimal” install by default, and when you’re up and running you can install your needed/favorite packages with yum.  The minimal install doesn’t give you a desktop environment, and I keep having to look up which packages to install to get GNOME on a Red Hat-based system that was installed without a GUI.  I have to do this about twice a year and I can never remember which packages are needed.  Jeffrey B. Murphy has a post that explains it simply, and I’ll repeat the simple yum command here:

yum groupinstall basic-desktop desktop-platform x11 fonts

There. Perhaps someone will find this or Jeffrey’s post helpful. I’ll update this if needed later.

A lot of forum posts you’ll find mention a “GNOME Desktop Environment” group, but that doesn’t seem to work at present.

Linux+, LPIC-1, and Novell CLA Achieved

I passed CompTIA’s LX0-101 and LX0-102 a few weeks ago. I am now CompTIA Linux+ and LPIC-1 certified. I can turn that in and be granted Novell’s Certified Linux Administrator as well. It was harder than I thought, and when I submitted the exam today I fully expected to have failed it. I used Roderick Smith’s Linux+ Complete book to study with, but either I didn’t read every page closely or there were some things left out. I’m pretty sure that IPv4 subnetting wasn’t covered in the book, but I was asked to tell how many addresses there were in a /26 subnet and couldn’t do it. Maybe that was one of those “unscored” questions they talk about in the introduction.

Oh, well. Passing is passing. I’m not a daily network guy so I don’t fault myself for not being able to calculate that number.  Now it’s on to CE|H and Microsoft products since I’m teaching Windows Server 2008 Network Infrastructure and Directory Services courses next semester.

On second thought, I may as well continue with LPI and go for the LPIC-2 certification, for which there is no definitive study guide.  The objectives are there at LPI’s site, and aside from the book written by Roderick Smith, there isn’t really a study guide.  Through LPI I did find some free sources, but they’re a bit dated.  Still useful, I’m sure.  Compiling a kernel and changing options can’t have changed that much since they were written.

I’m not going to commit to anything here, but as I continue my study over these objectives, I would like to say that I’ll write about what I find so I can help you study too.  First, though, let’s look at the objectives for exam 201, the first of two exams required for LPIC-2:

LPI Exam 201 covers the following main topics:

  • Linux Kernel
  • System Startup
  • Filesystem and Devices
  • Advanced Storage Device Administration
  • Networking Configuration
  • System Maintenance
  • Domain Name Server

It appears that the objectives will be updated on August 1 2012, and I’ll look at that when the time  comes.

Topic 201: Linux Kernel

201.1 – Kernel Components

I suppose this is all about the kernel, options, compiling, boot configuration (choosing a kernel to boot), hardware drivers, and knowing your way around.

201.2 – Compiling a Kernel

This deals with compiling (obviously) the kernel and switching options/features on and off, plus some.

201.3 – Patching a Kernel

This covers updating the kernel for additional hardware support (presumably when changing or upgrading system hardware).

201.4 – Customize, Build, and Install a Custom Kernel and Kernel Modules

Kernel 2.6 building for specific requirements by changing various options and adding/removing patches.  This also covers assessing the requirements for compiling the kernel.

201.5 – Manage/Query Kernel and Kernel Modules at Runtime

Just what that says.  Manage and query a 2.6 kernel and its loadable modules.

Topic 202: System Startup

202.1 – Customizing System Startup and Boot Processes

Look at and change the system services behavior at startup and at various run levels.  This requires “a thorough understanding of the init structure and boot process.”

202.2 – System Recovery

This tests your ability to work with a Linux system during the boot process and during recovery mode.

Topic 203: Filesystem and Devices

203.1 – Operating the Linux Filesystem

This will also include configuring and mounting different types of filesystems.

203.2 – Maintaining a Linux Filesystem

Use system utilities to properly maintain a Linux filesystem. fsck, xfs_repair, tune2fs, etc…

203.3 – Creating and Configuring Filesystem Options

Use AutoFS to configure automount filesystems.

203.4 – udev Device Management

Understand device detection and management under udev.  Troubleshooting udev rules.

Topic 204: Advanced Storage Device Administration

204.1 – Configuring RAID

Configure and implement software RAID.  Levels 0, 1, and 5.

204.2 – Adjusting Storage Device Access

Configure kernel options to support various drives.

204.3 – Logical Volume Manager

Create and remove LVs, VGs, and PVs.  Includes snapshots and resizing LVs.

Topic 205: Networking Configuration

 205.1 – Basic Networking Configuration

Configure a network device, wireless, WAN.  Also communicate between various subnets within a single network.

205.2 – Advanced Network Configuration and Troubleshooting

Configure network authentication.  VPN, multi-homed devices, communication problems.

205.3 – Troubleshooting Network Issues

Identify and correct common setup issues, must know location of all network config files.

205.4 – Notify Users on System-Related Issues

Automate communication with users through logon messages and inform inactive users of maintenance.

Topic 206: System Maintenance

206.1 – Make and Install Programs from Source

Build and install software packages from source code, including the ability to unpack a file of sources.

206.2 – Backup Operations

Use system tools to back up and restore critical system and application data.

Topic 207: Domain Name Server

207.1 – Basic DNS Server Configuration

Configure BIND as caching-only, convert older BIND config files to newer format, and manage a server to include logging configuration.

207.2 – Create and Maintain DNS Zones

Create a zone file for forward and reverse zones or a root level server.  Know all about DNS records and zone delegation.

207.3 – Securing a DNS Server

Configure DNS to run as a non-root user and in a chroot jail.  Secure communication between DNS servers.

 

Well, that’ s a doozy.  I understand most of that, but it likely will be some time before I schedule the exam.  There’s also another exam just as long with different objectives you must pass in order to get the LPIC-2 credential.  Let me know in the comments whether you’re interested in any of this or not!

I’d love to write articles on each objective, and if you want to write one too I’ll publish it here with your permission.  There’s no reason that a community can’t be built to gain more knowledge.

 

Exam 1 (LX0-101) Objectives

This comes directly from the PDF available at CompTIA.org and is obviously subject to change there without notice.  As I have said before, there are 60 questions on the first test and you have 90 minutes to complete it.  You can read more about those exam details here. There are four domains covered in the first exam:

  1. System Architecture
  2. Linux Installation and Package Management
  3. GNU and UNIX commands, and
  4. Devices, Linux Filesystems, Filesystem Hierarchy Standard.

This will not be an exhaustive list of the items that could be covered in the exam.

101: System Architecture

  • 101.1: Determine and Configure Hardware Settings
    • Enable and disable integrated peripherals
    • Configure systems with or without external peripherals such as keyboards
    • Differentiate between the various types of mass storage devices
    • Set the correct hardware ID for different devices, especially the boot device
    • Know the differences between coldplug and hotplug devices
    • Determine hardware resources for devices
    • Tools and utilities to list various hardware information (e.g. lsusb, lspci, etc.)
    • Tools and utilities to manipulate USB devices
    • Conceptual understanding of sysfs, udev, hald, dbus
    • The following is a partial list of the used files, terms, and utilities:
      • /sys
      • /proc
      • /dev
      • modprobe
      • lsmod
      • lspci
      • lsusb
  • 101.2: Boot the System
    • Provide common commands to the boot loader and options to the kernel at boot time
    • Demonstrate knowledge of the boot sequence from BIOS to boot completion
    • Check boot events in the log file
    • The following is a partial list of the used files, terms, and utilities:
      • /var/log/messages
      • dmesg
      • BIOS
      • bootloader
      • kernel
      • init
  • 101.3: Change Runlevels and Shutdown or Reboot the System
    • Set the default runlevel
    • Change between runlevels including single user mode
    • Shutdown and reboot from the command line
    • Alert users before switching runlevels or other major system events
    • Properly terminate processes
    • The following is a partial list of the used files, terms, and utilities:
      • /etc/inittab
      • shutdown
      • init
      • /etc/init.d
      • telinit

102: Linux Installation and Package Management

  • 102.1: Design Hard Disk Layout
    • Allocate filesystems and swap space to separate partitions or disks
    • Tailor the design to the intended use of the system
    • Ensure the /boot partition conforms to the hardware architecture requirements for booting
    • The following is a partial list of the used files, terms, and utilities:
      • / (root) filesystem
      • /var filesystem
      • /home filesystem
      • swap space
      • mount points
      • partitions
  • 102.2: Install a Boot Manager
    • Provide alternative boot locations and backup boot options
    • Install and configure a boot loader such as GRUB
    • Interact with the boot loader
    • The following is a partial list of the used files, terms, and utilities:
      • /boot/grub/menu.lst
      • grub-install
      • MBR
      • superblock
      • /etc/lilo.conf
      • lilo
  • 102.3: Managed Shared Libraries
    • Identify shared libraries
    • Identify the typical locations of system libraries
    • Load shared libraries
    • The following is a partial list of the used files, terms, and utilities:
      • ldd
      • ldconfig
      • /etc/ld.so.conf
      • LD_LIBRARY_PATH
  • 102.4: Use Debian Package Management
    • Install, upgrade, and uninstall Debian binary packages
    • Find packages containing specific files or libraries which may or may not be installed
    • Obtain package information like version, content, dependencies, package integrity, and installation status (whether or not the package is installed)
    • The following is a partial list of the used files, terms, and utilities:
      • /etc/apt/sources.list
      • dpkg
      • dpkg-reconfigure
      • apt-get
      • apt-cache
      • aptitude
  • 102.5: Use RPM and YUM Package Management
    • Install, re-install, upgrade, and remove packages using RPM and YUM
    • Obtain information on RPM packages such as version, status, dependencies, integrity, and signatures
    • Determine what files a package provides, as well as find which package a specific file comes from
    • The following is a partial list of the used files, terms, and utilities:
      • rpm
      • rpm2cpio
      • /etc/yum.conf
      • /etc/yum.repos.d
      • yum
      • yumdownloader

103: GNU and UNIX Commands

  • 103.1: Work on the Command Line
    • Use single shell commands and one line command sequences to perform basic tasks on the command line
    • Use and modify the shell environment including defining, referencing, and exporting environment variables
    • Use and edit command history
    • Invoke commands inside and outside the defined path
    • The following is a partial list of the used files, terms, and utilities:
      • .
      • bash
      • echo
      • env
      • exec
      • export
      • pwd
      • set
      • unset
      • man
      • uname
      • history
  • 103.2: Process Text Streams Using Filters
    • Send text files and output streams through text utility filters to modify the output using standard UNIX commands found in the GNU textutils package
    • The following is a partial list of the used files, terms, and utilities:
      • cat
      • cut
      • expand
      • fmt
      • head
      • od
      • join
      • nl
      • paste
      • pr
      • sed
      • sort
      • split
      • tail
      • tr
      • unexpand
      • uniq
      • wc
  • 103.3: Perform Basic File Management
    • Copy, move, and remove files and directories individually
    • Copy multiple files and directories recursively
    • Remove files and directories recursively
    • Use simple and advanced wildcard specifications in commands
    • Use find to locate and act on files based on type, size, or time
    • Usage of tar, cpio, and dd
    • The following is a partial list of the used files, terms, and utilities:
      • cp
      • find
      • mkdir
      • mv
      • ls
      • rm
      • rmdir
      • touch
      • tar
      • cpio
      • dd
      • file
      • gzip
      • gunzip
      • bzip2
      • file globbing
  • 103.4: Use Streams, Pipes, and Redirects
    • Redirect standard input, standard output, and standard error
    • Pipe the output of one command to the input of another command
    • Use the output of one command as arguments to another command
    • Send output to both stdout and a file
    • The following is a partial list of the used files, terms, and utilities:
      • tee
      • xargs
  • 103.5: Create, Monitor, and Kill Processes
    • Run jobs in the foreground and the background
    • Signal a program to continue running after logout
    • Monitor active processes
    • Select and sort processes for display
    • Send signals to processes
    • The following is a partial list of the used files, terms, and utilities:
      • &
      • bg
      • fg
      • jobs
      • kill
      • nohup
      • ps
      • top
      • free
      • uptime
      • killall
  • 103.6: Modify Process Execution Priorities
    • Know the default priority of a job that is created
    • Run a program with higher or lower priority than the default
    • Change the priority of a running process
    • The following is a partial list of the used files, terms, and utilities:
      • nice
      • ps
      • renice
      • top
  • 103.7: Search Text Files Using Regular Expressions
    • Create simple regular expressions containing several notational elements
    • Use regular expression tools to perform searches through a filesystem or file content
    • The following is a partial list of the used files, terms, and utilities:
      • grep
      • egrep
      • fgrep
      • sed
      • regex(7)
  • 103.8: Perform Basic File Editing Operations Using vi
    • Navigate a document using vi
    • Use basic vi modes
    • Insert, edit, delete, copy, and find text
    • The following is a partial list of the used files, terms, and utilities:
      • vi
      • /, ?
      • h,j,k,l
      • i,o,a
      • c,d,p,y,dd,yy
      • ZZ, :w!, :q!, :e!

104: Devices, Linux Filesystems, Filesystem Hierarchy Standard

  • 104.1: Create Partitions and Filesystems
    • Use various mkfs commands to set up partitions and create various fileystems such as:
      • ext2
      • ext3
      • xfs
      • reiserfs v3
      • vfat
    • The following is a partial list of the used files, terms, and utilities:
      • fdisk
      • mkfs
      • mkswap
  • 104.2: Maintain the Integrity of Filesystems
    • Verify the integrity of filesystems
    • Monitor free space and inodes
    • Repair simple filesystem problems
    • The following is a partial list of the used files, terms, and utilities:
      • du
      • df
      • fsck
      • e2fsck
      • mke2fs
      • debugfs
      • dumpe2fs
      • tune2fs
      • xfs tools such as xfs_metadump and xfs_info
  • 104.3: Control Mounting and Unmounting of Filesystems
    • Manually mount and unmount filesystems
    • Configure filesystem mounting at boot
    • Configure user-mountable removable filesystems
    • The following is a partial list of the used files, terms, and utilities:
      • /etc/fstab
      • /media
      • mount
      • umount
  • 104.4: Manage Disk Quotas
    • Set up a disk quota for a filesystem
    • Edit, check, and generate user quota reports
    • The following is a partial list of the used files, terms, and utilities:
      • quota
      • edquota
      • repquota
      • quotaon
  • 104.5: Manage File Permissions and Ownership
    • Manage access permissions on regular and special files as well as directories
    • Use access modes such as suid, sgid, and the sticky bit to maintain security
    • Know how to change the file creation mask
    • Use the group field to grant file access to group members
    • The following is a partial list of the used files, terms, and utilities:
      • chmod
      • umask
      • chown
      • chgrp
  • 104.6: Create and Change Hard and Symbolic Links
    • Create links
    • Identify hard and/or softlinks
    • Copying versus linking files
    • Use links to support system administration tasks
    • The following is a partial list of the used files, terms, and utilities:
      • ln
  • 104.7: Find System Files and Place Files in the Correct Location
    • Understand the correct locations of files under the FHS (File Hierarchy Standard)
    • Find files and commands on a Linux system
    • Know the location and purpose of important file and directories as defined in the FHS
    • The following is a partial list of the used files, terms, and utilities:
      • find
      • locate
      • updatedb
      • whereis
      • which
      • type
      • /etc/updatedb.conf

Using the find Command

When I was introduced to UNIX and Linux, finding files on at least the Linux machine involved a program called ‘locate’ that was really easy to use and was very fast. It still is, but it’s not available on UNIX. For that you’ll have to fall back and use find. Find is very useful if you utilize the options. However, I am often unable to remember these options, so I’ll put a few command strings here so I can remember them so that you may be able to find through Googling.

To find regular files in /var/core older than 30 days,

find /var/core -mtime +30 -type f

That will only show each file and its full path (very useful in scripts). If you wish to show long output of those files,

find /var/core -mtime +30 -type f -exec ls -l {} /;

And you only need to change the ‘exec’ arguments in order to remove the files in question:

find /var/core -mtime +30 -type f -exec rm -f {} /;

I must note here that in the exec option, the trailing semicolon must be escaped and there must be a space between the argument ‘{}‘ and the escape sequence ‘\;
I think it’s worth explaining what the time arguments are (there are three *time options: atime, mtime, and ctime). The man page explains the time argument for atime like this:

…n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.

The same calculations are performed for the arguments to mtime and ctime. n can be expressed as
+n for greater than n,
-n for less than n,
n for exactly n.
Say we have a file that was modified at noon on January 8 and the current date and time is January 9 at 10am. The command
find /dir -mtime +1
will not find this file since the file is precisely 22 hours old. The time specified in the command is (+1 = 24+ hours) and so the file is not captured by the filter. I suppose I could bring more to the table with a live example…
Study the following:

[ben@carbondale example]$ ls -l
total 0
[ben@carbondale example]$ touch file1
[ben@carbondale example]$ ls -l
total 0
-rw-rw-r--. 1 ben ben 0 Feb 29 16:31 file1
[ben@carbondale example]$ touch -mt 201202282200 file1
[ben@carbondale example]$ ls -l
total 0
-rw-rw-r--. 1 ben ben 0 Feb 28 22:00 file1
[ben@carbondale example]$ find /home/ben/example -mtime +1 -type f
[ben@carbondale example]$ find /home/ben/example -mtime 1 -type f
[ben@carbondale example]$ find /home/ben/example -mtime -1 -type f
/home/ben/example/file1
[ben@carbondale example]$ find /home/ben/example -mtime -30 -type f
/home/ben/example/file1
[ben@carbondale example]$ touch -mt 201201022200 file2
[ben@carbondale example]$ ls -l
total 0
-rw-rw-r--. 1 ben ben 0 Feb 28 22:00 file1
-rw-rw-r--. 1 ben ben 0 Jan  2 22:00 file2
[ben@carbondale example]$ find /home/ben/example -mtime -30 -type f
/home/ben/example/file1
[ben@carbondale example]$ find /home/ben/example -mtime +30 -type f
/home/ben/example/file2
[ben@carbondale example]$ find /home/ben/example -mtime +30 -type f -exec ls -l {} \;
-rw-rw-r--. 1 ben ben 0 Jan  2 22:00 /home/ben/example/file2
[ben@carbondale example]$ find /home/ben/example -mtime -30 -type f -exec ls -l {} \;
-rw-rw-r--. 1 ben ben 0 Feb 28 22:00 /home/ben/example/file1
[ben@carbondale example]$ find /home/ben/example -mtime -1 -type f -exec ls -l {} \;
-rw-rw-r--. 1 ben ben 0 Feb 28 22:00 /home/ben/example/file1

And as always, feel free to post in the comments if you have questions or anything to add.

Installing and Using phpMyAdmin through YUM

Today is Stephen Hawking’s birthday. He turns 70.

I got PHPMyAdmin installed through YUM after enabling the EPEL (Extra Packages for Enterprise Linux) repository. Once I enabled EPEL, it was a simple

yum install phpMyAdmin

It installs to /usr/share/phpMyAdmin, so from there you just create a symbolic link in the web root to that directory, or change the httpd config to serve out that directory for a virtual host. Your choice. It’s just easier to run this and be done:

ln -s /usr/share/phpMyAdmin/ /var/www/html/mysql

So then http://mywebserver/mysql goes to my phpMyAdmin installation. However, if you’ve just set up MySQL, you will need to set the root user password by bringing up mysqld and running the following command as root:

mysqladmin -u root password P@55w0rd

You should, of course, replace ‘P@55w0rd’ with the password of your choice. At that time you can visit your phpMyAdmin installation through the web interface and log in with those credentials. You are encouraged to then create a user for yourself that does not have root privileges and use it instead, but I don’t see that practiced very often.

So there it is – phpMyAdmin installed through YUM.

I had another problem when I tried to get to phpMyAdmin on that server – none of the PHP code was run. It just showed the raw PHP files as if I’d asked for copies of them. PHP was installed, but I had never encountered an installation that wasn’t configured in apache.

Turns out it was a simple inclusion needed in httpd.conf of the PHP configurations. In /etc/httpd/conf.d/ there are some files that end in .conf that need to be included. So at the end of httpd.conf I put a line that says

Include conf.d/*.conf

I restarted Apache with that configuration and it worked. I can’t say if that’s the best way to do it, but for my test VM that’s fine with me.

Fedora 15 Firstboot Problems

I had some trouble after installing Fedora Linux 15 tonight (on two separate occasions) and thought I’d post here since I didn’t find a thread on the tubes about my specific issue.

I installed FC15 on a desktop at work tonight and it went well.  However, at the first boot where it asks for the first user’s details, license agreement, etc., it would not progress past the time zone settings.  Pressing “Forward” did not go forward as expected.  There was no way to skip the setting, and I was frozen there.

I sat for a few minutes and decided that the machine was set up; I’d already entered my user details and the thing was ready to go except for the time zone and whether or not I’d like to send my system configuration to the Fedora team (I usually do).  But how to get past this screen that doesn’t let me through?  A trick I remembered from way back when…

If you were on FC3 or so, with root logged in to the desktop but with the screen locked, you could just hit CTRL+ALT+BKSP and it would kill the Gnome session and return you to a text console.  Bad security hole.  Nowadays it just restarts Gnome and you are presented with the logon screen.

So that’s what I did.  CTRL+ALT+BKSP skipped that first boot session and gave me a login prompt.  I continued to set up my environment and had to reboot after disabling SELinux.  Upon reboot, I was taken to the first boot sequence again, and it stuck at the time zone setting again.  Damn.

On to searching for a solution.

Found one.  /etc/init.d/firstboot runs at every startup and checks for a file at /etc/sysconfig/firstboot.  If it exists and contains “RUN_FIRSTBOOT=NO” it will not run the firstboot sequence.  There’s your solution to it.  Create a file, /etc/sysconfig/firstboot.  It should contain one line – RUN_FIRSTBOOT=NO

Reboot.  Be happy.

I’m not entirely sure what the issue is/was, but unless it’s an isolated event with the image I have or the disc quality I used when burning, I am very surprised I didn’t find a solution at the Fedora forums.