Skip to content

Instantly share code, notes, and snippets.

@metalefty
Last active April 8, 2019 03:29
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save metalefty/2672c26ae0cb36f7a4bc100650c83a15 to your computer and use it in GitHub Desktop.
Clean up remained xrdp socket files
#!/bin/sh
SOCKDIR=/tmp/.xrdp
SESSIONS=$(cd ${SOCKDIR} ; ls -1 xrdp_* | sed -e 's|[^0-9]||g' | sort -u)
for i in ${SESSIONS}
do
if [ ! -S ${SOCKDIR}/xrdp_display_${i} ]
then
(
cd ${SOCKDIR}
rm -f xrdp_chansrv_audio_in_socket_${i} \
xrdp_chansrv_audio_out_socket_${i} \
xrdp_chansrv_socket_${i} \
xrdpapi_${i}
)
fi
done
@DS455
Copy link

DS455 commented Sep 10, 2017

:-(

sh xrdp_clean_sockets.sh
xrdp_clean_sockets.sh: 19: xrdp_clean_sockets.sh: Syntax error: Missing '))'

then your code works https://www.tutorialspoint.com/execute_bash_online.php (bash v4.4)
On my PC the Bash v4.3 and there is an error: Syntax error: Missing '))'

@DS455
Copy link

DS455 commented Sep 10, 2017

#!/bin/sh
 
SOCKDIR=/tmp/.xrdp
SESSIONS=$cd ${SOCKDIR} ; ls -1 xrdp_* | sed -e 's|[^0-9]||g' | sort -u
 
for i in ${SESSIONS}
do
        if [ ! -S ${SOCKDIR}/xrdp_display_${i} ]
        then
                (
                cd ${SOCKDIR}
                rm -f xrdp_chansrv_audio_in_socket_${i} \
                        xrdp_chansrv_audio_out_socket_${i} \
                        xrdp_chansrv_socket_${i} \
                        xrdpapi_${i}
                )
        fi
done

In this version of the error, "Missing" does not occur. There is another error - "Permission denied". Run the script like this: sudo sh xrdp_clean_sockets.sh

@metalefty
Copy link
Author

The script doesn't do bashisms. It should work with /bin/sh.

@metalefty
Copy link
Author

The SESSIONS line can be written like this.

# space after first "("
SESSIONS=$( (cd ${SOCKDIR} ; ls -1 xrdp_*) | sed -e 's|[^0-9]||g' | sort -u)
# actually "( )" surrounding ls and cd is not necessary 
SESSIONS=$(cd ${SOCKDIR} ; ls -1 xrdp_* | sed -e 's|[^0-9]||g' | sort -u)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment