These two scripts, assigned as part of CMPSC 210 Mid-Term project, do these things:
1 #!/bin/bash
2 # mount_midterm1
3 # L. J. Jaeckel
4 # March 6, 2011
5 #
6 # Mount the data partition and activate
7 # the swap partition on disk 2.
8
9 # --------------------------------------------------------
10
11 # Define data partition and where it's mounted,
12 # and the swap partition:
13
14 data2dev=/dev/sdb2
15 data2mnt=/mnt/sdb2
16 swap2dev=/dev/sdb1
17
18 # Who am I? Only root can do all this:
19
20 myuid=`id -u`
21 if [ $myuid != 0 ]
22 then
23 echo Sorry, `whoami`, only root can do.
24 exit
25 fi
26
27 # See if the data partition is already mounted by
28 # looking for it in output from df:
29
30 df | grep ^$data2dev > /dev/null
31 d2mounted=$?
32
33 # See if the swap partition is already active by
34 # looking for it in output from swapon -s:
35
36 swapon -s | grep ^$swap2dev > /dev/null
37 s2active=$?
38
39 # --------------------------------------------------------
40
41 # Mount the data partition if it is not already:
42
43 if [ $d2mounted = 0 ]
44 then
45 echo "Data partition $data2dev is already mounted."
46 else
47 echo "Mounting data partition $data2dev on $data2mnt"
48 mount $data2dev $data2mnt
49 fi
50
51 # --------------------------------------------------------
52
53 # Activate the swap partition if it is not already:
54
55 if [ $s2active = 0 ]
56 then
57 echo "Swap partition $swap2dev is already active."
58 else
59 echo "Activating swap partition $swap2dev"
60 swapon $swap2dev
61 fi
62
63 # --------------------------------------------------------
64
umount_midterm1:
1 #!/bin/bash
2 # umount_midterm1
3 # L. J. Jaeckel
4 # March 6, 2011
5 #
6 # Un-mount the data partition and de-activate
7 # the swap partition on disk 2.
8
9 # --------------------------------------------------------
10
11 # Define data partition and where it's mounted,
12 # and the swap partition:
13
14 data2dev=/dev/sdb2
15 data2mnt=/mnt/sdb2
16 swap2dev=/dev/sdb1
17
18 # Who am I? Only root can do all this:
19
20 myuid=`id -u`
21 if [ $myuid != 0 ]
22 then
23 echo Sorry, `whoami`, only root can do.
24 exit
25 fi
26
27 # See if the data partition is already mounted by
28 # looking for it in output from df:
29
30 df | grep ^$data2dev > /dev/null
31 d2mounted=$?
32
33 # See if the swap partition is already active by
34 # looking for it in output from swapon -s:
35
36 swapon -s | grep ^$swap2dev > /dev/null
37 s2active=$?
38
39 # --------------------------------------------------------
40
41 # Un-mount the data partition if it is not already:
42
43 if [ $d2mounted = 0 ]
44 then
45 echo "Un-mounting data partition $data2dev"
46 umount $data2dev
47 else
48 echo "Data partition $data2dev is already not mounted."
49 fi
50
51 # --------------------------------------------------------
52
53 # De-activate the swap partition if it is not already:
54
55 if [ $s2active = 0 ]
56 then
57 echo "De-activating swap partition $swap2dev"
58 swapoff $swap2dev
59 else
60 echo "Swap partition $swap2dev is already not active."
61 fi
62
63 # --------------------------------------------------------
64