Unix / Linuxコンソールのシュードグラフィック。 あなたが余裕があるよりも少しユーザーフレンドリー。

こんにちは 時々、私は「退屈な」コンソールを忘れて、特に同じ操作を頻繁に行わなければならない場合、そして運命を容易にするためのスクリプトを書く場合は特に、インタラクティブな操作で希釈します。 だから、疑似グラフィック。 読者は私をフォローしている、私はあなたにそのようなコンソールを紹介します!



確かに、多くの人がそれについて考え、FreeBSDでmake && make installを実行するか、たとえばDebianでapt-get installを実行すると、そのような設定ダイアログを使用するのがどれほど良いかを考えました。 それらは不当に忘れられ、ユーザースクリプトではほとんど使用されません。 とても無駄です。



すばらしいユーティリティダイアログでこれを修正できます。

FreeBSDの7番目と8番目のブランチにあり、たとえばDebianでは、apt-getインストールダイアログを実行できます。 実際、これらは異なるプログラムです。

FreeBSDのバージョンは少し単純です:

$ dialog



dialog version 0.3, by Savio Lam (lam836@cs.cuhk.hk).

patched to version 0.4 by Stuart Herbert (S.Herbert@shef.ac.uk)

Changes Copyright (C) 1995 by Andrey A. Chernov, Moscow, Russia

patched by Anatoly A. Orehovsky (tolik@mpeks.tomsk.su)



* Display dialog boxes from shell scripts *



Usage: dialog --clear

dialog --create-rc <file>

dialog [--title <title>] [--clear] [--hline <line>] [--hfile <file>]\

<Box options>



Box options:



--yesno <text> <height> <width> [yes|no]

--msgbox <text> <height> <width>

--prgbox "<command line>" <height> <width>

--infobox <text> <height> <width>

--inputbox <text> <height> <width> [<init string>]

--textbox <file> <height> <width>

--menu <text> <height> <width> <menu height> <tag1> <item1>...

--checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...

--radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...

--ftree <file> <FS> <text> <height> <width> <menu height>

--tree <FS> <text> <height> <width> <menu height> <item1>...







Linuxバージョンにはさらに多くの機能があります。

$ dialog

cdialog (ComeOn Dialog!) version 1.1-20080316

Copyright 2000-2006,2007 Thomas E. Dickey

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



* Display dialog boxes from shell scripts *



Usage: dialog <options> { --and-widget <options> }

where options are "common" options, followed by "box" options



Special options:

[--create-rc "file"]

Common options:

[--ascii-lines] [--aspect <ratio>] [--backtitle <backtitle>]

[--begin <y> <x>] [--cancel-label <str>] [--clear] [--colors]

[--cr-wrap] [--default-item <str>] [--defaultno] [--exit-label <str>]

[--extra-button] [--extra-label <str>] [--help-button]

[--help-label <str>] [--help-status] [--ignore] [--input-fd <fd>]

[--insecure] [--item-help] [--keep-tite] [--keep-window]

[--max-input <n>] [--no-cancel] [--no-collapse] [--no-kill]

[--no-label <str>] [--no-lines] [--no-ok] [--no-shadow] [--nook]

[--ok-label <str>] [--output-fd <fd>] [--print-maxsize] [--print-size]

[--print-version] [--separate-output] [--separate-widget <str>]

[--shadow] [--single-quoted] [--size-err] [--sleep <secs>] [--stderr]

[--stdout] [--tab-correct] [--tab-len <n>] [--timeout <secs>]

[--title <title>] [--trace <file>] [--trim] [--version] [--visit-items]

[--yes-label <str>]

Box options:

--calendar <text> <height> <width> <day> <month> <year>

--checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...

--dselect <directory> <height> <width>

--editbox <file> <height> <width>

--form <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>...

--fselect <filepath> <height> <width>

--gauge <text> <height> <width> [<percent>]

--infobox <text> <height> <width>

--inputbox <text> <height> <width> [<init>]

--inputmenu <text> <height> <width> <menu height> <tag1> <item1>...

--menu <text> <height> <width> <menu height> <tag1> <item1>...

--mixedform <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> <itype>...

--mixedgauge <text> <height> <width> <percent> <tag1> <item1>...

--msgbox <text> <height> <width>

--passwordbox <text> <height> <width> [<init>]

--passwordform <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>...

--pause <text> <height> <width> <seconds>

--progressbox <height> <width>

--radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...

--tailbox <file> <height> <width>

--tailboxbg <file> <height> <width>

--textbox <file> <height> <width>

--timebox <text> <height> <width> <hour> <minute> <second>

--yesno <text> <height> <width>









実際、オプションのリストから、このプログラムで何ができるかは明らかですが、わかりやすくするために例を示します。

選択したデータベース(またはすべて)MySQLのファイルバックアップと強制ダンプダンプ:

$ cat ./xbackup.sh

#!/bin/sh



SRC = "/usr/home/dev/"

SITE = "${SRC}_Web/"

PROJECT = "${SRC}_Project/"



#

DST = "/usr/home/share/BACKUP/"



# Mysql

SQLLOGIN = "root"

SQLPASS = "TopSecretPassword"

SQLHOST = "localhost"



/* --------------------------------------------------------------------------------------------------------- */

#

DATE = ` date "+%Y.%m.%d_%H-%M-%S"`

DSRC = ""

# ( )

backupType = 0



#

DIALOG = dialog

#

tempfile = ` mktemp /tmp/bkp.XXXXXX `

trap "rm -f $tempfile" 0 1 2 5 15



#

InfoDialog () {

${ DIALOG } --msgbox "$1" 5 70

}



#

BackupFiles () {

if [ ! -d ${ 2 } ] ; then

mkdir -p ${ 2 }

fi

tar -c --gzip -f "${2}${DATE}.tar.gz" "${1}"

InfoDialog "OK -> ${2}${DATE}.tar.gz"

}



#

BackupMySQL () {

case ${ 1 } in

"All_Database" )

mysqldump -R -E --triggers -u "${SQLLOGIN}" -p "${SQLPASS}" --all-databases > "${tempfile}"

;;

"" )

InfoDialog "Backup has been canceled"

exit

;;

* )

mysqldump -R -E --triggers -u "${SQLLOGIN}" -p "${SQLPASS}" ${ DBase } > "${tempfile}"

;;

esac

cp "${tempfile}" "${DST}${1}-${DATE}.sql"

# gzip, —

echo tar -c --gzip -f "${2}${DATE}.dump" "${tempfile}"

InfoDialog "OK -> ${2}${DATE}.dump"

}



#

ChooseDatabase () {

#

DBases = ` echo "SHOW DATABASES" | mysql -u "${SQLLOGIN}" -p "${SQLPASS}" `

# All_Database

List = "All_${DBases}"

#

$DIALOG --title "Please choose a Database " --tree "FS" "List of existing databases" 14 78 7 ${ List } 2> ${ tempfile }



case $? in

0 )

#

DBase = ` cat ${ tempfile } `

BackupMySQL ${ DBase }

;;

1|255 )

# ( )

InfoDialog "Backup has been canceled"

exit

;;

esac

}



# ( )

ChooseDomain () {

Paths = ` ls ${ 1 } `

List = ""

isEmpty = true

for dName in ${ Paths }

do

# www ( )

if [ -d "${1}${dName}/www" ] || [ -d "${1}${dName}/htdocs" ] ; then

List = "${List} ${dName}"

isEmpty = false

fi

done




# ,

if ${ isEmpty } ; then

Count = ` echo ${ SRC } | wc -c | tr -d ' '`

DSRC = ` echo ${ 1 } | awk "{ print substr($ 1, ${Count}) }"`

return 0;

fi



#

$DIALOG --title "Please choose a path " --tree "FS" "List of existing domains" 14 78 7 ${ List } 2> ${ tempfile }



case $? in

0 )

DName = ` cat ${ tempfile } `

ChooseDomain "${1}${DName}/"

;;

1|255 )

InfoDialog "Backup has been canceled"

exit

;;

esac



}



ProcessBackup () {

case $1 in

Site )

ChooseDomain ${ SITE }

BackupFiles "${SRC}${DSRC}" "${DST}${DSRC}"

;;

MySQL )

ChooseDatabase

;;

* )

;;

esac

}



TypeDialog () {

${ DIALOG } --title "Choose backup type:" --menu "This is backup types" 12 50 4 \

"Site" "backup web-site" \

"MySQL" "Mysql database" 2> ${ tempfile }



case $? in

0 )

ProcessBackup ` cat ${ tempfile } `

TypeDialog

;;

1|255 )

InfoDialog "Backup has been canceled"

exit

;;

esac



}



TypeDialog









次のようになります。

メインメニュー

バックパップ用のサイトを選択する

バックアップのベース選択

ベースは正常にダンプされました





以上です。 これで、スクリプトを使用して、インタラクティブな「ウィンドウ」を楽しむことができます。 同様に、コンソールコマンドの実行を実装するのは簡単で、これをキー認証を使用してコマンドラインからパテを配置することと組み合わせると、開発サーバーでApacheを再起動するための美しいコンソールインターフェイスを提供できます(もちろん、厳しい制限のあるsudoを介して)、すべての開発者にチームで、* nixシステムに不慣れであっても。

記載されている知識は、サーバーのコンソールを「よりユーザーフレンドリー」にするために、誰かにとって役立つと確信しています。



PS執筆の過程で、私は良い例http://www.oszone.net/2833/に出会い、すぐにそこから何かを紹介しました。



All Articles