Shell programming: Automatically format the hard drive and mount it

Source: Internet
Author: User

This script is not a complete script, has not implemented automatic mount partition, each disk is divided into 2, 1 partition for the 1g,2 partition of 2G.

#!/bin/bash

Count= ' fdisk-l|grep/dev/sd.*|grep-v '/dev/sda.* ' |wc-l '

I=1

While [$i-le $count]

Do

J= ' echo $i |awk ' begin{printf ("%c\n", 98+ $i)} '//Note/DEV/SDA is a system partition and cannot be formatted

Fdisk/dev/sd$j <<format

N

P

1


+1g

N

P

2


+2g

W

Wait

FORMAT

Mkfs.ext3 "/DEV/SD" $j "1"

Mkfs.ext3 "/DEV/SD" $j "2"

Sleep 2

echo "****************************************************************"


echo "/dev/sd$j fomate is done"


echo "****************************************************************"

Aaa= ' echo '/sd$j "' 1

Bbb= ' echo '/sd$j "' 2

mkdir $AAA

mkdir $BBB

mount/dev/$aaa $AAA

mount/dev/$bbb $BBB



i=$[$i +1]

Done

Sleep 2

echo "****************************************************************"


Fdisk-l |grep "/dev/sd.*" |grep-v "/dev/sda.*"


echo "****************************************************************"


Df-h


echo "****************************************************************"


Shell programming: Automatically format the hard drive and mount it

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.