3

I am working on a Linux server, I have access to a directory but I am not allowed to write anything to that directory. I can run commands from system prompt. Now I have to find values of specific field of some files in that dir and do some comparisons. I have a script on a test server can do that. But I can't install my script to the server, I am asking if there is anyway I type a specific command, then I can write and run a shell program without saving the program? Thank you!

4

2 に答える 2

7

別のホストにスクリプトがある場合は、次の方法で実行できます。

wget http://your.host.net/script -O- | sh -s

HTTP 経由でホストにアクセスできない場合は、必要な他のプロトコルを使用できます。

また、シェルで直接スクリプトを書くこともできます:

sh -s <<EOF
echo Hello
echo I am script
echo Nice to meet you
EOF
于 2013-03-21T18:52:06.207 に答える
1

backticsを使用して、別のコマンドの結果を実行できます。

`wget /path/to/your/script/stored/remotely -O-`

sftp代わりにスクリプトをフェッチするために使用する場合があります)

もう1つのオプションは、ttyを使用してsshセッションを制御するプログラムを作成することです。その後、スクリプトはsshクライアントに保存されますが、コマンドはサーバー上で実行されます。おそらく、expectツールはそれを助けるでしょう。

于 2013-03-21T18:49:46.360 に答える