OPS435 Test1 Practice - Bash
You need to be able to write a short script using constructs and utilities we've discussed in the course so far. These exercises should be helpful to you as practice to reinforce what you already learned during the semester.
Conditions
Test PATH
Write a script that will check whether the current user's path variable contains /sbin. If it does - the script will print "Your current user (#) is likely an administrator". If it doesn't - it will print "Your current user (#) is likely not an administrator". The # should be replaced with the user's UID which you can obtain with the id -a command.
Get subnet mask
The following is a sample output of the ip address command:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether fc:aa:14:c7:86:11 brd ff:ff:ff:ff:ff:ff inet 10.0.0.4/24 brd 10.0.0.255 scope global eth2 valid_lft forever preferred_lft forever inet6 fe80::feaa:14ff:fec7:8611/64 scope link valid_lft forever preferred_lft forever
Write a script that will check whether any interface has the IP address 10.0.0.4 and if it does - it will print the subnet mask used with that interface (subnet mask or bit length, whatever you prefer). If it doesn't - it will print a message saying so.
Loops
Move all files
Write a script that will move all the files from the current directory to /data/backup/. If the script encouters an error for any reason (e.g. permission denied) it should stop and print the message "Failed to move the file ABC, move stopped!" where ABC should be the name of the file that failed to move.
Fancy ls
Write a script that will list the contents of the present working directory. Every directory in the PWD should be printed like this (with the <> signs): <dirctoryname> and every file in the PWD should be printed like this (with the double quotes): "filename" Note that the "test -d" command will return true when applied to a directory and false otherwise.