The shell program mounts the iso image file and configures the local yum source,

Source: Internet
Author: User

The shell program mounts the iso image file and configures the local yum source,

</Pre> <p> write a script, mainly do 1. Mount the local iso image file 2. boot the local iso image and mount it automatically 3. Use the iso image to configure the local yum source </p> <pre>
#! /Bin/bash # author: wjf # date: 2015/04/22 # desc: establish a yum on local rhel6.4echo "Enter the full iso image path" read v_iso_pathecho ". Enter the directory to which the image is attached" read v_mount_dirv_curr_date = 'date + % Y % m % d % H % m'mount-t iso9660-o loop $ {v_iso_path }$ {v_mount_dir} v_is_mount = 'df-h | grep $ {v_iso_path} 'if [-z "$ {v_is_mount }"] then echo "mounting failed, check whether the mounting process "else echo" is successfully mounted to the iso image and configure yum ...... "Echo" Configure disk mounting and boot auto-start "echo" back up the/etc/fstab file to/etc/fstab. $ {v_curr_date }. bak "cp/etc/fstab. $ {v_curr_date }. bak echo "$ {v_iso_path }$ {v_mount_dir} iso9660 loop 0 0">/etc/fstab mount-a echo-ne "[base] \ nname = base \ nbaseurl = file: // $ {v_mount_dir} \ nenabled = 1 \ ngpgcheck = 0 \ n [Server] \ nname = Server \ nbaseurl = file: // $ {v_mount_dir}/Server \ nenabled = 1 \ ngpgcheck = 0 \ n ">/etc/yum. repos. d/local. repo yum clear all yum updatefi


Output result

[Root @ localhost wjf_scripts] # configure the local yum source in bash iso. sh please enter the full path of the iso image/mnt/rhel-server-6.4-x86_64-dvd.iso please enter the directory of the image to be mounted/mnt/yumiso mounting iso image successful, start configuring yum ...... Configure the boot backup/etc/fstab file to/etc/fstab.2015042320.5.bakloaded plugins: product-id, refresh-packagekit, security, sub‑managerthis system is not registered to Red Hat sub‑management. you can use sub‑manager to register. no such command: clear. please use/usr/bin/yum -- helpLoaded plugins: product-id, refresh-packagekit, security, sub‑managerthis system is not registered to Red Hat sub‑management. you can use sub‑manager to register. server | 3.9 kB... base | 3.9 kB... setting up Update ProcessNo Packages marked for Update [root @ localhost wjf_scripts] #


Summarize the knowledge points

1. if []

Then

Elif []

Else

Fi

Standard if statement syntax

There must be spaces between "if" and the judgment statement.

It must end with "fi", or an error will be reported.

2. iso image mounting statement

Mount-t iso9660-o loop/mnt/rhel6.4.iso/mnt/yumiso

The statement for mounting the optical drive is

Mount-t iso9660/dev/cdrom/mnt/testiso

It can be seen that an additional loop parameter is required to mount the image.

Similarly, the configuration file involved in file system mounting is/etc/fstab.

Iso image configuration Behaviors Based on its syntax format

/Mnt/rhel6.4.iso/mnt/yumiso iso9660 loop 0 0

3. yum source configuration

The yum source automatically loads all configuration files ending with. repo in the/etc/yum. repos. d directory.

Format in the repo configuration file.

No space or other characters are allowed at the beginning of the line in the configuration file. Otherwise, a parsing error occurs. At the beginning, a space is added to each line to make the script look beautiful, and an error is returned.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.