Tüm sunucularım için kullandığım standart bir banner'ım var ve bunları genellikle el ile girdim, ancak sunucu filomuz büyüdükçe, bunu otomatik hale getirme zamanı.Sabit genişlikli bir dizede bir metin satırı nasıl ortalanır?
Tipik olarak, benim afiş gibi görünmelidir:
*****************************************************************
* .:Welcome to hostname.internal.mynet.net:. *
* *
* This is a private server maintained by and exclusively for *
* use by me. No authorization is given or granted to any party *
* unless explicit permission is given. Attempts to circumvent, *
* disable, or otherwise interfere with normal operation will be *
* prosecuted to the fullest extent of applicable laws. *
* *
* UNAUTHORIZED ACCESS PROHIBITED *
*****************************************************************
Bu istenen etki, ama benim ana bilgisayar adları karakterleri değişen, bu yüzden bazen, örneğin doğru biçimlendirmek değildir:
*****************************************************************
* .:Welcome to somelongrandomhostname.internal.mynet.net:. *
* *
* This is a private server maintained by and exclusively for *
* use by me. No authorization is given or granted to any party *
* unless explicit permission is given. Attempts to circumvent, *
* disable, or otherwise interfere with normal operation will be *
* prosecuted to the fullest extent of applicable laws. *
* *
* UNAUTHORIZED ACCESS PROHIBITED *
*****************************************************************
ve daha kısa hostname ise:
*****************************************************************
* .:Welcome to abc.internal.mynet.net:. *
* *
* This is a private server maintained by and exclusively for *
* use by me. No authorization is given or granted to any party *
* unless explicit permission is given. Attempts to circumvent, *
* disable, or otherwise interfere with normal operation will be *
* prosecuted to the fullest extent of applicable laws. *
* *
* UNAUTHORIZED ACCESS PROHIBITED *
*****************************************************************
Senaryomun kullanmak alakalı kodu oluşturmak için bu geçerli: I veya ana makine adının uzunluğu ne olursa olsun, ilk örnekte verildiyse aynen afiş oluşturmak için en iyi araç olarak ne nasıl kullanılacağını emin değilim
# banner
echo "
*****************************************************************
* .:Welcome to $hostname.internal.mynet.net:. *
* *
* This is a private server maintained by and exclusively for *
* use by me. No authorization is given or granted to any party *
* unless explicit permission is given. Attempts to circumvent, *
* disable, or otherwise interfere with normal operation will be *
* prosecuted to the fullest extent of applicable laws. *
* *
* UNAUTHORIZED ACCESS PROHIBITED *
***************************************************************** " > banner
? Fikirler için, "çerçeve" (yıldız karakterleriyle gösterildiği gibi) sabit bir değer olmalıdır.
'$ {# hostname}' ile başlamak istediğiniz alanı hesaplayabilirsiniz. –