39 lines
днес написах първия си bash (bourne again shell) script. той мести accountи от един сървър, на друг сървър, ако accounta който си му дал да провери е по-голям от 1GB и имаш генериран ssh rsa ключ за другия сървър, съответно. след като премести accounta те пита желаеш ли да го затриеш от сървъра и записва всичко в movement.log лог file. И всичко това:
root@gandalf:/home/brand/bash# cat my.sh |wc -wl ; du -sh my.sh
39 реда 209 символа и 4кб
но пък не е просто:
#!/bin/bash
printf `ls -al /home`
printf “%sn” “Gimme user, baby”
read username
result=`du -sh /home/$username | awk ‘{ print $1 }’`
hiddendu=`du -s /home/$username | awk ‘{ print $1 }’`
gb=’1048576′
echo “The size of the account of $username is $result”
if [ "$hiddendu" -gt "$gb" ]
then
echo “Account $username is over the limit, so we will have it moved to another server”;
printf “%sn” “Which server you wanna have the acc $username moved to?”;
read servermove
echo “Relax, we are going on with the movement of $username to $servermove” ;
rsync -e ssh -aHz /home/$username $servermove:/home/$username ;
echo “Account $username successfully moved to $servermove” ;
echo “on `date` account $username was moved to $servermove” > movements.log ;
printf “All right, log written. Delete the account [y/N]?”;
read answer
if [ "$answer" = "y" ]
then
echo “All right, master, removing $username from the server” ;
rm -rf /home/$username ;
echo “$username @ localhost is no longer present, $result are now free” ;
exit
else
echo “Note that the acc of $username is $result big.. delete it soon”;
exit
fi
else
echo “Account $username is NOT over the limit”
fi
exit
а, и настроението ми се оправи. затова вече няма черна тема.
1 коментар »
* RSS за коментарите към този постинг.



Good info!
Thank.