Skip to content

Commit

Permalink
If user is not root, don't search to run su command
Browse files Browse the repository at this point in the history
* In some case (mainly) standard user doesn't act as root permission
* In this case we can't use su command
  • Loading branch information
camlafit committed Aug 27, 2024
1 parent 4da2e65 commit 1a68c41
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions screen-save-all-sessions
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ for screen_info in "${screen_sockets[@]#*S-}";
do
screen_user=$(dirname "${screen_info}")
screen_pid=$(basename "${screen_info%.pts*}")
command=""

if test "$1" = "-d"
then
savedir="~${screen_user}/.screen-save/$(date +%Y-%m-%d)/"
su - "${screen_user}" -c "mkdir -p ${savedir}"
command="mkdir -p ${savedir}"
if [ "$EUID" -ne 0 ]; then
eval "${command}"
else
su - "${screen_user}" -c "${command}"
fi
fi
command="${SCRIPTDIR}/screen-save ${screen_pid} ${savedir} </dev/null"
if [ "$EUID" -ne 0 ]; then
eval "${command}"
else
su - "${screen_user}" -c "${command}"
fi
su - "${screen_user}" -c "${SCRIPTDIR}/screen-save ${screen_pid} ${savedir} </dev/null"
done

0 comments on commit 1a68c41

Please sign in to comment.