2013-01-19 23:07:26 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# info: list system users
|
|
|
|
# options: [FORMAT]
|
|
|
|
#
|
|
|
|
# The function for obtaining the list of system users without
|
|
|
|
# detailed information.
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Variable&Function #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
2015-11-06 17:38:58 +02:00
|
|
|
# Argument definition
|
2013-01-19 23:07:26 +02:00
|
|
|
format=${1-shell}
|
|
|
|
|
|
|
|
# Includes
|
|
|
|
source $VESTA/func/main.sh
|
|
|
|
|
2016-06-09 16:26:54 +03:00
|
|
|
# JSON list function
|
|
|
|
json_list() {
|
2016-06-24 16:31:43 +03:00
|
|
|
objects=$(grep @ /etc/passwd |wc -l)
|
2013-01-19 23:07:26 +02:00
|
|
|
i=1
|
|
|
|
echo '['
|
2016-06-09 16:26:54 +03:00
|
|
|
while read user; do
|
|
|
|
if [ "$i" -lt "$objects" ]; then
|
2013-01-19 23:07:26 +02:00
|
|
|
echo -e "\t\"$user\","
|
|
|
|
else
|
|
|
|
echo -e "\t\"$user\""
|
|
|
|
fi
|
|
|
|
(( ++i))
|
2016-06-09 16:26:54 +03:00
|
|
|
done < <(grep @ /etc/passwd |cut -f 1 -d :)
|
2013-01-19 23:07:26 +02:00
|
|
|
echo "]"
|
|
|
|
}
|
|
|
|
|
2016-06-09 16:26:54 +03:00
|
|
|
# SHELL list function
|
|
|
|
shell_list() {
|
|
|
|
echo "USER"
|
|
|
|
echo "----"
|
|
|
|
while read user; do
|
2013-01-19 23:07:26 +02:00
|
|
|
echo "$user"
|
2016-06-09 16:26:54 +03:00
|
|
|
done < <(grep @ /etc/passwd |cut -f 1 -d :)
|
|
|
|
}
|
|
|
|
|
|
|
|
# PLAIN list function
|
|
|
|
plain_list() {
|
|
|
|
while read user; do
|
|
|
|
echo "$user"
|
|
|
|
done < <(grep @ /etc/passwd |cut -f 1 -d :)
|
|
|
|
}
|
|
|
|
|
|
|
|
# CSV list function
|
|
|
|
csv_list() {
|
|
|
|
echo "USER"
|
|
|
|
while read user; do
|
|
|
|
echo "$user"
|
|
|
|
done < <(grep @ /etc/passwd |cut -f 1 -d :)
|
2013-01-19 23:07:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Action #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
2016-06-09 16:26:54 +03:00
|
|
|
# Listing data
|
2013-01-19 23:07:26 +02:00
|
|
|
case $format in
|
2016-06-09 16:26:54 +03:00
|
|
|
json) json_list ;;
|
|
|
|
plain) plain_list ;;
|
|
|
|
csv) csv_list ;;
|
|
|
|
shell) shell_list ;;
|
2013-01-19 23:07:26 +02:00
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Vesta #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
|
|
exit
|