开发者

test remote file if directory

HOSTNAME=$1

#missing files will be created by chk_dir
for i in `cat filesordirectorieslist_of_remoteserver`
do

isdir=remsh $HOSTNAME "if [ -d $i ]; then echo dir; else echo f开发者_开发技巧ile; fi"

if [ $isdir -eq "dir" ]
then

remsh $HOSTNAME "ls -d $i | cpio -o" | cpio -id
else

remsh $HOSTNAME "ls | cpio -o" | cpio -id
fi
done

i need simple solution for checking remote file is directory or file ? thanks


You need to add backticks around the first remsh:

isdir=`remsh $HOSTNAME "if [ -d $i ]; then echo dir; else echo file; fi"`


This has worked for me on bash (Fedora):

ssh $REMOTEHOST [ -d /path/to/some/directory ]

or

ssh $REMOTEHOST [ -f /path/to/some/file ]

The exit status of 0 or 1 will reflect the existent/not-existent status of the directory/file on the remote host.

I use key exchange to avoid needing to provide credentials every time, so this can easily be scripted. I use this in a loop before doing a multiple subversion repository synchronization, to know if a new repository needs to be initialized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜