Operating systems 1 -- 2008-2009 -- info.uvt.ro/Laboratory 5

From Wikiversity
Jump to navigation Jump to search

Quick links: front; laboratories agenda, 1, 2, 3, 4, 5, 6, projects, evaluation, tools, references.


Command substitution[edit]

  • syntax:
`<command> [argument] ...`
$( <command> [argument] ... )
  • catching the current working directory in a variable:
WORKING=`pwd`
  • or:
WORKING=$( pwd )
  • or (better with quoting):
WORKING="$( pwd )"
  • catching the current date in a variable:
DATE=`date`
  • or:
DATE=$( date )
  • or:
DATE="$( date )"
  • catching the whole content of a file in a variable:
PASSWD="$( cat /etc/passwd )"
echo "${PASSWD}"

Regular expressions and globbing[edit]

Mini projects[edit]

System users and groups querying[edit]

  • write a simple bash script that allows us to query the (UNIX/Linux) system users and groups database;
  • note: all the needed information is inside /etc/passwd and /etc/group files;
  • it will list all users:
$ ./query.sh show-users
root
bin
fetchmail
ciprian
...
  • it will list all users that are allowed to login (they have the shell set to /bin/bash, /bin/sh):
$ ./query.sh show-valid-users
root
ciprian
  • it will list all groups:
$ ./query.sh show-groups
root
daemon
audio
...
  • it will list all users that are in a group:
$ ./query.sh show-users-in-group audio
root
ciprian
  • it will list all groups a user is in:
$ ./query.sh show-groups-for-user ciprian
ciprian
audio
cdrom
...
  • it will print the home-dir of a given user:
$ ./query.sh show-home-for-user ciprian
/home/ciprian
  • note: try to use only grep, sed, cat, head/tail, don't use existing commands that do the required operations;
  • links:

Syslog querying[edit]

  • write a script that allows us to query through the syslog messages (a file located at /var/log/syslog);
  • to view all messages from a given host:
$ ./query.sh show-from-host router
May 10 20:20:08 router kernel: Enabling...
May 10 20:20:08 router sshd: Starting...
...
  • to view all messages from a given component:
$ ./query.sh show-from-component kernel
May 10 20:20:08 router kernel: Enabling...
...
  • to view all messages from a given host and component:
$ ./query.sh show-from-host-and-component router kernel
May 10 20:20:08 router sshd: Starting...
...
  • to view only those entries containing a given string:
$ ./query.sh search ACPI
May 10 20:20:08 router kernel: Enabling ACPI...
...

Simple file versioning system[edit]