エイリアスで実行されないコマンドを使用するSSH

エイリアスで実行されないコマンドを使用するSSH

tail -f私のローカルサーバーと私が持っているアプリケーションの最新のログファイルにリモートでアクセスするには、次のコマンドを使用します。

このコマンドはコマンドラインで完全に機能します。

ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'

問題は、エイリアス(または関数)にするときにls -1rローカルコンピュータで完了を評価し、それをリモートコンピュータに渡そうとすることです。

alias latestbotlogs="ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'"

function latestbotlogs {
    ssh user@hostname 'tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'
}

SSH経由でアクセスできるリモートシステムでコマンド全体を評価するには、どの構文を使用する必要がありますか?

よろしくお願いします!

ベストアンサー1

エイリアスの場合、いくつかのエスケープが必要です。

alias latestbotlogs="ssh user@hostname 'tail -f \\\$\\(ls -1r \\~/Development/python/twitter-bot/logs/*.log \\| head -1\\)'"

または

alias latestbotlogs='ssh user@hostname '\''tail -f $(ls -1r ~/Development/python/twitter-bot/logs/*.log | head -1)'\'

2番目のバージョンは簡単です。引用すべきすべての演算子について考える必要はありません。

機能はそのまま機能する必要があります。

おすすめ記事