Skip to content

Instantly share code, notes, and snippets.

@INDIAN2020
Last active June 23, 2021 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save INDIAN2020/c1898324af3752e18c77e99a3936d68c to your computer and use it in GitHub Desktop.
Save INDIAN2020/c1898324af3752e18c77e99a3936d68c to your computer and use it in GitHub Desktop.
#!/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