SPR720 Lab

SPR720 Bash Scripting Lab



2. Display the longest and shortest usernames on the system (usernames are in the first field in /etc/passwd).
Answer:

#!/bin/bash

MAX_LEN=0
MIN_LEN=100

for USER_NAME in $(cut -f1 -d: /etc/passwd)
do
   if [[ ${#USER_NAME} -gt MAX_LEN ]]
   then
     MAX_LEN=${#USER_NAME}
     MAX_LEN_USERNAME=$USER_NAME
   elif [[ ${#USER_NAME} -lt MIN_LEN ]]
   then
     MIN_LEN=${#USER_NAME}
     MIN_LEN_USERNAME=$USER_NAME
   fi
done

echo “The longest user name is $MAX_LEN_USERNAME”
echo “The shortest user name is $MIN_LEN_USERNAME”

 

3. Count the number of users with user IDs between 500 and 10000 on the system (user IDs are the third field in /etc/passwd).
Answer:

#!/bin/bash

NUM_USER=0

for USER_ID in $(cut -f3 -d: /etc/passwd)
do
   if [ “$USER_ID” -ge 500  -a “$USER_ID” -le 10000 ]
   then
      echo $USER_ID
      ((NUM_USER++))
   fi
done

echo “The number of  user IDS between 500 and 10000 is $NUM_USER”

6. Count the number of files in the user’s home directory which are not readable.
Answer:

#!/bin/bash

NUM_FILE=0

for FILE_NAME in ~/*
do
   if [ ! -r “$FILE_NAME” -a -f “$FILE_NAME” ]
   then
   echo $FILE_NAME
     ((NUM_FILE++))
   fi
done

echo “The number of files in $HOME which are not readable is $NUM_FILE”

 

 

SPR720 Command Lab



Task 1 — Examine the /bin, /usr/bin/, /sbin, and /usr/sbin directories. For each directory, examine the number and type of commands

 

$ ls /bin|wc -l

107

 

$ ls /usr/bin|wc -l

1961

 

$ ls /sbin|wc -l

296

 

$ ls /usr/sbin|wc -l

346

 

 

Task2 — Go through the files in /usr/bin and for each file, note whether it’s a command you have used. Select 25 of the commands you haven’t used and research what they do

 

1.a2p

A2p takes an awk script specified on the command line (or from standard input) and produces a comparable perl script on the standard output.

 

2.ab

ab  is  a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current  Apache  installation  performs.  This especially shows you how many requests per second your Apache installation is capable of  serving.

 

3.ac

ac  prints  out  a  report  of connect time (in hours) based on the logins/logouts in the current wtmp file.  A total is also printed out.

 

4.aconnect

aconnect  is  a utility to connect and disconnect two existing ports on ALSA sequencer system.  The ports with the arbitrary subscription permission, such as created by aseqview(1), can be connected to any (MIDI) device ports using aconnect.

 

5.afs5log

The afs5log command uses Kerberos to obtain AFS tokens for the named cells.  If no cell is named, tokens are obtained for the local cell. If the principal name of the afs service for the cell is known, the cell name may also be given in the form cell=principal_name.   Attempts are made to obtain Kerberos IV credentials first, and if that fails, afs5log will create Kerberos 5 (2b-style) tokens.

 

6.baobab

baobab is able to scan either specific folders or the whole filesystem (local and remote), in order to give the user a graphical tree representation including each directory size or percentage in the branch. It also auto-detects in real-time any change made to your home directory as far as any mounted/unmounted device. A graphical treemap window is also provided for any selected folder.

 

7.base64

Base64 encode or decode FILE, or standard input, to standard output.

 

8.bdftopcf

Bdftopcf is a font compiler for the X server and font server.  Fonts in Portable Compiled Format can be read by any architecture, although the file  is  structured  to allow one particular architecture to read them directly without reformatting.  This allows fast reading on the appropriate machine, but the files are still portable (but read more slowly) on other machines.

 

9.bmp2tiff

bmp2tiff converts a Microsoft Windows Device Independent  Bitmap  image file  to TIFF.  If several input BMP files are being specified the multipage TIFF output file will be created. By default, the TIFF image is created with data samples packed (PlanarConfiguration=1), compressed with the PackBits algorithm (Compression=32773), and with each strip no more than 8 kilobytes. These characteristics can overridden, or explicitly specified with the options described below.

 

10.bzip2

bzip2  compresses  files  using  the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. Compression is generally considerably   better   than   that achieved by more conventional LZ77/LZ78-based compressors, and approaches the performance of the PPM family of statistical compressors.

 

11.capiinfo

The capiinfo program checks how many controllers are installed and calls CAPI_GET_PROFILE for each of them. Also it sends a FACILITY_REQ capi message to get the information for the facilities supported by each controller. The information is shown on STDOUT.

 

12.card

Print a reference card of the PROGRAMs thanks to their inline help.

 

13.certmgr

This tool allow to list, add, remove or extract certificates, certificate revocation lists (CRL) or certificate trust lists (CTL) to/from a certificate store. Certificate stores are used to build and validate certificate chains for Authenticode(r) code signing validation and SSL server certificates.

 

14.cksum

Print CRC checksum and byte counts of each FILE.

 

15.chvt

The command chvt N makes /dev/ttyN the foreground terminal.  (The corresponding screen is created if it did not exist yet.  To get rid of unused VTs, use deallocvt(1).)  The key combination (Ctrl-)LeftAlt-FN(with N in the range 1-12) usually has a similar effect.

 

 

16.dasher

dasher is an information-efficient text-entry interface, driven by natural continuous pointing gestures. Dasher is a competitive text-entry system wherever a full-size keyboard cannot be used.

 

17.dirname

Print  NAME  with  its trailing /component removed; if NAME contains no /’s, output ‘.’ (meaning the current directory).

 

18.djpeg

djpeg  decompresses  the  named  JPEG file, or the standard input if no file is named, and produces an image file on the standard output.  PBM-PLUS (PPM/PGM),  BMP,  GIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected.

 

19.dvcont

dvcont  is a command line tool to send control commands via an IEEE1394 link to a device that implements the AV/C specifications by the 1394 Trade Association.  Or for the non-techies: dvcont lets you remote control your DV camera via a Firewire cable.

 

20.dvitomp

dvitomp  translates  the  given  dvifile  to  a  MetaPost MPXFILE.  The default mpxfile is the basename of dvifile extended with “.mpx”.

 

21.e2pall

e2pall  searches  through TEXFILE for \includegraphics commands to find the base names  of  image  files.   When  it  finds  one,  e2pall  runs epstopdf(1) to create a PDF file from the EPS file.

 

22.enchant

Enchant is an ispell-compatible spellchecker.

 

23.evince

Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.

 

24.expand

Convert tabs in each FILE to spaces, writing to standard output.  With no FILE, or when FILE is -, read standard input.

 

25.fold

Wrap  input  lines in each FILE (standard input by default), writing to standard output.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: