Last active
June 23, 2021 13:10
-
-
Save INDIAN2020/c1898324af3752e18c77e99a3936d68c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for project in $(gcloud projects list --format="value(projectId)") | |
do | |
echo "============================ Project: $project ============================" | |
mkdir $(pwd)/users/${project} | |
for instance in $(gcloud compute instances list --project $project --filter="STATUS=RUNNING" --format="csv[no-heading](name,zone)") | |
do | |
zone=(${instance//,/ }) | |
read -p "You need ${zone[0]} ?" yn | |
case $yn in | |
[yY] | [yY][Ee][Ss] ) | |
echo "gcloud compute ssh ${zone[0]} --zone=${zone[1]} --project $project --command=\"sudo sed -n '/^\([^:]\+\):[^:]\+:[1-9][0-9]\{3\}/ { s/:.*//; p }' /etc/passwd\" >> \$(pwd)/users/${zone[0]}.xls" | |
gcloud compute ssh ${zone[0]} --zone=${zone[1]} --project $project --command="sudo sed -n '/^\([^:]\+\):[^:]\+:[1-9][0-9]\{3\}/ { s/:.*//; p }' /etc/passwd" >> $(pwd)/users/$project/${zone[0]}.xls | |
;; | |
[nN] | [nN][Oo] ) ;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment