无法对 SSH 命令使用通配符 [英] Unable to use wildcard for SSH command

查看:57
本文介绍了无法对 SSH 命令使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须检查许多文件是否存在于目录中.除了文件扩展名之外,它们遵循标准命名约定,因此我想使用通配符,例如:

There are a number of files that I have to check if they exist in a directory. They follow a standard naming convention aside from the file extension so I want to use a wild card e.g:

YYYYMM=201403
FILE_LIST=`cat config.txt`
for file in $FILE_LIST
do
    FILE=`echo $file | cut -f1 -d"~"`
    SEARCH_NAME=$FILE$YYYYMM
    ANSWER=`ssh -q userID@servername 'ls /home/to/some/directory/$SEARCH_NAME* | wc -l'`
    returnStatus=$?
    if [ $ANSWER=1 ]; then
        echo "FILE FOUND"
    else
        echo "FILE NOT FOUND"
    fi
done

通配符不起作用,有没有关于如何使其对 shell 可见的想法?

The wildcard is not working, any ideas for how to make it visible to the shell?

推荐答案

我刚才有很多相同的问题.绝望中,我只是放弃并使用带有 grep 和 xargs 的管道来获得类似通配符的功能.

I had much the same question just now. In despair, I just gave up and used pipes with grep and xargs to get wildcard-like functionality.

是(这些都不起作用 - 并尝试了其他):

Was (none of these worked - and tried others):

ssh -t r@host "rm /path/to/folder/alpha*"    
ssh -t r@host "rm \"/path/to/folder/alpha*\" "
ssh -t r@host "rm \"/path/to/folder/alpha\*\" "

是:

ssh -t r@host "cd /path/to/folder/ && ls | grep alpha | xargs rm"

注意:我使用 ls 而不是 rm 进行了大部分故障排除,以防万一我自己感到惊讶.

Note: I did much of my troubleshooting with ls instead of rm, just in case I surprised myself.

这篇关于无法对 SSH 命令使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆