1月 292014
 

変数を引き継いで実行したい場合、

[#!/bin/bash/except]ファイルでは、シェルからの変数がうまく引き継げなかった。

シェル内で、実行したい場合、expect -c 以下を””でくくって、実行できる。

また、初回接続の「Are you sure you want to continue connecting」を聞かれたくない場合は、

{}を使用して、その文言が出てきた場合のみ、send ”yes”を渡すこともできる

ユーザー:user
パスワード:pass$word
ホスト:xxx.co.jp

#!/bin/bash -sh

DIR=/home/directory/
FILE=file.txt
expect -c "
spawn sftp -oPort=22 user@xxx.co.jp
expect { \"\(Are you sure you want to continue connecting \(yes\/no\)\?
{ send \"yes\r\" }
}
expect \"user@xxx.co.jp's password:\"
send \"pass\\\$word\r\"
expect \"sftp>\"
send \"put $DIR/$FILE\r\"
expect \"sftp>\"
send \"bye\r\"
"

パスワードなどで、$が混ざってたりする場合は、それもエスケープ。
\\\$ (文字として$をつかう場合。変数で使うならエスケープしなくていい。)
ex)pass$wordという文字列がパスワードなら
send \”pass\\\$word\r\”

変数を{}で囲む必要がある時は以下のような感じで。
send \”put $dir/${month}_monthly.tsv\r\”

このエントリーをはてなブックマークに追加
はてなブックマーク - シェルスクリプト内でexpectを使ってSFTP接続
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

4月 142013
 

virtualboxの右下にある、下矢印の隣に書かれたキーを押せば切り替えられます。

仮想サーバーにログインしたときにダイアログで出てくる、
「ホストキー」というのが、ホストOSに切り替えるボタンというわけです。

ホストOSとは、
たとえばwindowsのPCに、仮想サーバを入れたとすると、
ホストOSはwindows
ゲストOSは仮想サーバーとなる。

このエントリーをはてなブックマークに追加
はてなブックマーク - virtualboxからホストOSに切り替える。
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

1月 152009
 

■置き換えた文字列を\1などに格納して表示させる
sed -e “s/条件/\1・・・・/g” ファイル名
* \1とかは自動的に振られるので、\1\2\3というかんじ。
\1,\2,というかんじに表示させることもできる。
(例)
sed -e “s/\(.\+\?\)\([a-z]*\)\(.\+\?\)/\1\2\3/g” sample2.txt
(結果)
abcd14
(sample2.txtの中身)
あいうえおabcdあ14だ
-----------------------------------—-
◎エスケープ
-----------------------------------—-
(スラッシュとかは文字列扱いの場合は\でエスケープする)
メタ文字扱いしたいのにエスケープする。。
( → \(
+ → \+
? → \?
のようにエスケープする
「*」はなぜかやらなくていい。

このエントリーをはてなブックマークに追加
はてなブックマーク - 置き換えた文字列を\1などに格納して表示させる linuxコマンド
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

1月 152009
 

----------------------------------------------
linuxコマンドの正規表現
----------------------------------------------
■grepコマンド
検索にはgrepを使う。
「grep」コマンド
意味:指定されたパターンの文字列をファイル内から検索する。
書式:grep [オプション] 検索パターン [ファイル名]
オプション:
-c・・・マッチした行数だけを出力する
-i・・・大文字と小文字を区別しない
-n・・・マッチした行を行番号付きで出力する
-v・・・マッチしない行を出力する
複数組み合わせることもできる。-ciとか
*grepコマンドにメタキャラクタを用いた例。
textfileはファイル名。
行頭が「th」という文字列を含んだ行を除いて出力します。ちなみにメタキャラクタを指定する時には「’that’」のように引用符「’」で囲みます。
(例)
$ grep -v ‘^th’ textfile
(結果)
I am john
basket ball

このエントリーをはてなブックマークに追加
はてなブックマーク - grep 文字列検索 linuxコマンドの正規表現
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]