sisco311
July 26th, 2011, 12:36 AM
The rules are simple:
post a working shell code;
you can use whatever shell you like (bash, csh, zsh, dash, ...). bash is the de facto standard shell on most modern Linux and Unix systems;
this is a shell scripting exercise, so try to avoid using external commands like cut, sed, awk...
comment your code and use proper indentation and
QUOTE YOUR VARIABLES, otherwise I will yell at you. :evil: :)
Exercise 0:
Write a script which prints:
the total number of (local) users on the system;
the number and list of normal users (with an UID greater that or equal to 1000);
the number and list of system users (with an UID less than 1000, but not 0) and
the shortest and the longest usernames
Sample output:
number of users - 35
4 normal users - nobody:sisco:fo:bar
30 system users - daemon:bin:sys:sync:games:man:lp:mail:news:uucp:pr oxy:www-data:backup:list:irc:gnats:libuuid:syslog:messageb us:avahi-autoipd:avahi:usbmux:gdm:speech-dispatcher:kernoops:pulse:rtkit:saned:hplip:couchd b:
shortest username(s) - lp:fo
longest username(s) - speech-dispatcher
PS:
Most of the things you have to know to solve this exercise are covered at BashFAQ (http://mywiki.wooledge.org/BashFAQ/) (you can use it as a reference even if you don't use bash).
post a working shell code;
you can use whatever shell you like (bash, csh, zsh, dash, ...). bash is the de facto standard shell on most modern Linux and Unix systems;
this is a shell scripting exercise, so try to avoid using external commands like cut, sed, awk...
comment your code and use proper indentation and
QUOTE YOUR VARIABLES, otherwise I will yell at you. :evil: :)
Exercise 0:
Write a script which prints:
the total number of (local) users on the system;
the number and list of normal users (with an UID greater that or equal to 1000);
the number and list of system users (with an UID less than 1000, but not 0) and
the shortest and the longest usernames
Sample output:
number of users - 35
4 normal users - nobody:sisco:fo:bar
30 system users - daemon:bin:sys:sync:games:man:lp:mail:news:uucp:pr oxy:www-data:backup:list:irc:gnats:libuuid:syslog:messageb us:avahi-autoipd:avahi:usbmux:gdm:speech-dispatcher:kernoops:pulse:rtkit:saned:hplip:couchd b:
shortest username(s) - lp:fo
longest username(s) - speech-dispatcher
PS:
Most of the things you have to know to solve this exercise are covered at BashFAQ (http://mywiki.wooledge.org/BashFAQ/) (you can use it as a reference even if you don't use bash).