最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shell - How can I check if FreeRDP connected successfully in bash? - Stack Overflow

programmeradmin1浏览0评论

I'm trying to write a bash script that will run through all the .rdp files in a folder and try to connect with each of them in turn using FreeRDP, but once it successfully connects to one, I need it to stop. What's the best way to test whether FreeRDP successfully connected to a remote desktop?

This was my first thought:

for file in filepath/*.rdp;
do
        echo "attempting connection to $file"
        if xfreerdp "$file" /u:"$username" /p:"$password";
        then
                echo "Connection to $file succeeded."
                break
        else
                echo "Connection to $file failed."
        fi
done

but this will basically never trigger the break, because when you disconnect from the remote desktop by logging out, etc, FreeRDP will return a non-zero exit code.

I found a list of the FreeRDP exit codes here, but I'm not sure it's comprehensive. Logging out of the desktop, for example, returns exit code 12, which isn't on the list.

But even if I understood what all the possible codes are and what they're for, I'd still have to just arbitrarily decide which ones to consider success and which ones to consider failure, which doesn't seem like a great solution.

The simplest option I can think of is to use if [[ $? -le 15 ]], which I'm pretty sure would work 99% of the time for my purposes, but clearly isn't robust.

Is there a cleaner way to do this? If there's a way to do the test at the time the connection is made instead of waiting for the program to exit, that would be even better, but I'm not sure that's possible since the shell runs one command at a time.

发布评论

评论列表(0)

  1. 暂无评论