Hello!

If anybody need sorting web servers by name in admin gui, use my script. Not perfect but working :)

--
Regards
Donka Péter

#!/bin/bash

echo -n "Cherokee config file: "
read cherokee_conf
echo -n "vservers new start uid: "
read newuid_start
echo -n "vservers uid increment rate: "
read vrate
echo -e '\n'
echo "Please wait."
echo -e '\n'

cp $cherokee_conf $cherokee_conf.orig # backup original config file

# use an array to store vserver id and nick, replace space to _ because the 
array.
vservernum=(`cat $cherokee_conf | grep vserver | grep nick | grep -v default | 
awk 'BEGIN {FS="!"} {print $2}' | tr '\n' ' '`)
vservernick=(`cat $cherokee_conf | grep vserver | grep nick | grep -v default | 
awk 'BEGIN {FS="="} {print $2}' | cut -b 1 --complement | tr ' ' '_' | tr '\n' 
' '`)
# count vserver array, the array begins with zero so minus one from the total 
number
let vservercount=("${#vservernum[*]}-1")

# write the original id and the nick one line seperated by tab.
for a in `seq 0 $vservercount`; do
    echo -en "${vservernum[$a]}"'\t' >> list_temp;
    echo "${vservernick[$a]}" >> list_temp;
done

# use this file to sorted by nick, and the results write to the new file
sort -r +1 -1 list_temp >> list_sorted
rm -f list_temp

# insert new uid to all line and seperate with tab from old uid, the results 
write to the new file 
let vservercount2=("${#vservernum[*]}")
for a in `seq 1 $vservercount2`; do
    sed -n ""$a"s/^/$newuid_start\t/p" list_sorted >> list;
    let newuid_start=$newuid_start+$vrate;
done

rm -f list_sorted

# count the sorted, new uid inserted file rows
linenum=`cat list | wc -l`

# filter old uid and new uid from this file and stored an array
for a in `seq 1 $linenum`; do
     newnum[$a]=`head -$a list | tail -1 | awk 'BEGIN {FS="\t"} {print $1}'`;
     oldnum[$a]=`head -$a list | tail -1 | awk 'BEGIN {FS="\t"} {print $2}'`;
done

echo "#!/bin/sh" >> replace.sh

# use newnum and oldnum array with sed command, and write to the final shell 
script
for b in `seq 1 $linenum`; do
    old[$b]=`echo -n "vserver!""${oldnum[$b]}""!"`;
    new[$b]=`echo -n "vserver!""${newnum[$b]}""!"`;
    echo "sed -i 's/"${old[$b]}"/"${new[$b]}"/g' $cherokee_conf" >> replace.sh;
done

chmod +x replace.sh
rm -f list

echo "Your cherokee conf vserver sorter is complete. (replace.sh)"
echo -e '\n'
read -p "Press enter to continue."
_______________________________________________
Cherokee mailing list
[email protected]
http://lists.octality.com/listinfo/cherokee

Reply via email to