IT Study/script

서버 스크립트 자동 배포

겸겸사 2014. 10. 21. 17:24

#!/bin/bash


### global variables ###


date=`date +%Y%m%d`

file="$2"

file_str=`echo "$2" | wc -c`

dir_input=`find /root/shell/ -name "$file" |grep $1 | awk '{print substr($1, 1, length($1) - '$file_str')}'`


echo "$dir_input"


### start funcion ### 


notice () {


clear


cat << __EOF__


[2014-09-26 TH] Server sctipts Update shell 


Notice : $0 [ api | en | upload | -> coming soon ...add server] updata_file


Not Exec scritps


__EOF__


}


api='/root/shell/admin/serverlist/api_server_list'

en='/root/shell/admin/serverlist/en_server_list'

upload='/root/shell/admin/serverlist/upload_server_list'


server_file="$1"


file_update () {


while read server_ip server_dir ;

do


# scripts update

        rsync -a -e ssh $dir_input/$file root@$server_ip:$server_dir

        echo "$server_ip $server_dir update ok"


done < /root/shell/admin/serverlist/$server_file\_server_list


}



### Main ###


file_input=`ls -l $dir_input | grep $file | awk '{print $9}'`


echo "$0 $1 $2"


if [ "$file" == "$file_input" ]; then

# start update shell scripts 

        case "$1" in

                api)

                        file_update

                        ;;

                en)

                        file_update

                        ;;

                upload)

                        file_update

                        ;;

                *)

                        notice

                        exit

        esac

else

        echo "File is not Found, Checking update file"

        notice

fi