| SATSHELL Example |
|
| Home | SATGUI | SATSHELL | SATFORM | SATFILTER | SATREPORT | SATMYSQL | License | Download | Examples | Contact |
A utility to display the contents of a Linux "/etc/passwd" file.
| User Guide |
The following example assumes that the directories for both satshell and viewpasswd are included in the PATH environment variable.
To start the application enter:
satshell viewpasswd
When the application has started a screen similar to the following is displayed:
The toolbar has two buttons, each of which will display its function using "balloon help" when the mouse pointer is held over the button.
| Button | Action |
![]() | Refresh screen. Updates screen to reflect current contents of "/etc/passwd" |
![]() | Exit the application. |
To display all details held in the "/etc/passwd" file for a particular user, double-click anywhere on the line for the required user. A screen similar to the following is displayed:
The toolbar has two buttons, each of which will display its function using "balloon help" when the mouse pointer is held over the button.
| Button | Action |
![]() | Back to the list of all users. |
![]() | Exit the application. |
| Source Code |
#===========================================================#
# SCRIPT : viewpasswd #
# PURPOSE : Display contents of "/etc/passwd". #
#===========================================================#
#-------------------------------------------------------#
# Display main screen: List of "users" and "user names" #
#-------------------------------------------------------#
main() {
cat << !
newScreen {{"User Viewer"} 48x17}
addToolbar {raised {reload help(Refresh) main} {stop help(Exit) exit}}
addMultiList {users 1,3 11 {User,10 Name,30} outline yscroll {detail users(0)}}
!
gawk -F: '
BEGIN {print "setItem {users "}
{print "{" $1 "\t" $5 "} "}
END {print "};unlock"}
' /etc/passwd
}
#------------------------------------------------------#
# Display detail screen: All details for selected user #
#------------------------------------------------------#
detail() {
cat << !
newScreen {{"User Viewer - $1"} 64x10}
addToolbar {raised {back help(Back) main} {stop help(Exit) exit}}
addEntries {1,3
{ 8,10 -User -User_ID -Group_ID}
{ 6,30 -Name -Home -Shell}
}
!
gawk -F: '
/^'$1':/ {
print "setItems {{user \"" $1 "\"} {user_id \"" $3 "\"} {group_id \"" $4 "\"} \
{name \"" $5 "\"} {home \"" $6 "\"} {shell \"" $7 "\"}};unlock"
}' /etc/passwd
}
#------------#
# Initialise #
#------------#
main
#-----------#
# Main Loop #
#-----------#
while true
do
read Command
[ -z "$Command" ] && exit
eval "$Command"
done
#---------------#
# End of script #
#---------------#
| Comments |
This aplication consists of four sections:
main - Displays a list of all users in a scrollable multi-column list.
main() {
Define the main function.
cat << !
A shell script "here" document is used to write SAT/DL commands to Standard Output.
This will be read and interpreted by SATSHELL.
Clear the screen/message line, set the application screen size to 48 characters by 17 rows,
and set the window title to "User Viewer".
Add a toolbar with a raised style at the top of the application window (row 0).
The toolbar has two buttons: "Refresh" " (With reload icon, "Refresh"
balloon help, runs the main function). "Exit" (With stop icon,
"Exit" balloon help. exit the application).
Add a multi-column list box called users with its top left corner at column 1,
row 3 which is 11 lines deep. The list box has two columns: "User"
(10 characters) and "Name" (30 characters). When a user is selected
by double-click, the detailfunction is run with the first column (users(0))
of the selected users line being passed as a parameter. The list box has an
outline and a vertical scrollbar (yscroll).
End the "here" document.
The gawk command is used to extract the user (field 1) and user name/comment (field 5)
from each line of the "/etc/passwd" file. This information is also formatted into a
setItem command. An unlock command is appended to the setItem,
separated by ";". The unlock is required because SATSHELL "locks" the
application window when an Action is triggered to prevent new Actions while the
current is being processed.
End the function definition.
detail - Display all "/etc/passwd" information for selected user.
NOTE: This function requires one parameter ($1): The selected user.
detail() {
Define the detail function.
cat << !
A shell script "here" document is used to write SAT/DL commands to Standard Output.
This will be read and interpreted by SATSHELL.
Clear the screen/message line, set the application screen size to 64 characters by 10 rows,
and set the window title to "User Viewer - $1" (Where $1 will be replaced by the
"User" field of the selected user).
Add a toolbar with a raised style at the top of the application window (row 0).
The toolbar has two buttons: "Back" (With back icon, "Back"
balloon help, runs the main function). "Exit" (With stop icon,
"Exit" balloon help. exit the application).
Add two columns of entry fields with its top left corner at column 1, row 3.
The first column has a label text width of 8 characters and a default entry width of
10 characters. The second column has a label text width of 6 characters and
a default entry width of 30 characters.
The names of all the entries in the first column are prefixed with "-".
This causes the entries to be disabled (read only).
End the "here" document.
The gawk command is used to extract details for the specified user from the
"/etc/passwd" file. This information is also formatted into a setItems command.
An unlock command is appended to the setItems, separated by ";".
The unlock is required because SATSHELL "locks" the application window when an
Action is triggered to prevent new Actions while the current is being processed.
End the function definition.
"Initialise" - Display "main" screen.
main
Run the main function to display the list of all users in
the "/etc/passwd" file.
"Main Loop" - Read and run Action commands.
Start a "Do forever" loop.
Read an Action command from standard input.
If the "Command" is null then the application window has closed, so exit the script.
This check is important as the script will not otherwise terminate when the window is
closed. Although the quotes around the $Command variable are not always required, it
is suggested thay are used in all applications (just in case).
Run the Action command.
End of the "Do forever" loop.
newScreen {{"User Viewer"} 48x17}
addToolbar {raised {reload help(Refresh) main} {stop help(Exit) exit}}
addMultiList {users 1,3 11 {User,10 Name,30} outline yscroll {detail users(0)}}
!
gawk -F: '
BEGIN {print "setItem {users "}
{print "{" $1 "\t" $5 "} "}
END {print "};unlock"}
' /etc/passwd
}
newScreen {{"User Viewer - $1"} 64x10}
addToolbar {raised {back help(Back) main} {stop help(Exit) exit}}
addEntries {1,3
{ 8,10 -User -User_ID -Group_ID}
{ 6,30 -Name -Home -Shell}
}
!
gawk -F: '
/^'$1':/ {
print "setItems {{user \"" $1 "\"} {user_id \"" $3 "\"} {group_id \"" $4 "\"} \
{name \"" $5 "\"} {home \"" $6 "\"} {shell \"" $7 "\"}};unlock"
}' /etc/passwd
}
while true
do
read Command
[ -z "$Command" ] && exit
eval "$Command"
done
Copyright © 2003 Adrian Davis.