1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-11 20:26:30 -07:00
vesta/bin/v-list-sys-users

78 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

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
# JSON list function
json_list() {
objects=$(grep @ /etc/passwd |wc -l)
2013-01-19 23:07:26 +02:00
i=1
echo '['
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))
done < <(grep @ /etc/passwd |cut -f 1 -d :)
2013-01-19 23:07:26 +02:00
echo "]"
}
# SHELL list function
shell_list() {
echo "USER"
echo "----"
while read user; do
2013-01-19 23:07:26 +02:00
echo "$user"
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 #
#----------------------------------------------------------#
# Listing data
2013-01-19 23:07:26 +02:00
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list ;;
2013-01-19 23:07:26 +02:00
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit