Deleting .serverauth.xxxx

There a numerous .serverauth.xxxx files in my home directory which apparently stay around when startx exits ungracefully. How do I get daily periodic cleanup to remove these files?
 
You would have to write something yourself. As far as I know none of the 'standard' periodic(8) scripts will do this for you.

Note that the numerous .serverauth.* files are a symptom. What you're basically try to do is to get rid of the symptoms when you really should try to solve the reason why those files are left over in the first place. Fix the problem not the symptoms.
 
As I understand it the .serverauth.* are holdovers from when startx exits ungracefully, such as when the system crashes/reboots unexpectedly... Maybe I should try to delete them as a step in .xinitrc...
 
I thought they were from xorg requiring authentication? There is a line in startx about "xauth" (I think) which is set to true, but commenting this out only masks the issue as SirDice pointed out. I have had this issue before but now my system is working fine and I only have one .serverauth.* file. I am not sure what causes multiple instances of these files.
 
You would have to write something yourself.
I did so, right now.

Code:
#!/bin/csh

if ( "$1" == "-y" ) then
    set forceYes = True
endif

# Get date to look out for the .serverauth dotfile not to be deleted
set date = `date +'%b %d'`
if ( "$status" != 0 ) then
    echo "Couldn't get date."
    exit 1
endif

# Get current directory to check
set cwd = `pwd`
if ( "$status" != 0 ) then
    echo "Couldn't get current working directory."
    exit 1
endif

# Check if one is in $HOME as Xorg .serverauth dotfiles are located in $HOME.
if ! ( "$cwd" == "$HOME" || "$cwd" == "/usr$HOME" ) then
    echo "Oh no, you aren't in your home."
    exit 1
endif

# Find .serverauth dotfiles.
set dotfiles = ( `find . -type f -name ".serverauth*"` )
if ( "$status" != 0 ) then
    echo "Couldn't check for dotfiles."
    exit 1
else
    foreach file ( $dotfiles:q )
        set dateOfFile = `ls -l "$file:q" | awk '{print $6,$7}'`
        if ( "$status" != 0 ) then
            echo "Couldn't get date of $file:q"
            exit 1
        endif
        if ( "$dateOfFile" == "" ) then
            echo "Couldn't get date of .serverauth file."
            exit 1
        endif
        if ( "$dateOfFile" != "$date" ) then
                echo "$file:q is not from today but $dateOfFile."
        else
            if ( -f "$file:q" ) then
                set ignorefile = `echo $file:q | cut -c 3-`
            endif
        endif
    end
endif

# Find .serverauth files and delete except ignored one which is current today's serverauth file.
if ( "$?ignorefile" ) then
    if ( "$?forceYes" ) then
        set rmfile = `find . -type f -name ".serverauth*" -not -name "$ignorefile" -exec rm -fv {} \;`
    else
        set rmfile = `find . -type f -name ".serverauth*" -not -name "$ignorefile" -exec rm -iv {} \;`
    endif
else
    if ( "$?forceYes" ) then
        set rmfile = `find . -type f -name ".serverauth*" -exec rm -fv {} \;`
    else
        set rmfile = `find . -type f -name ".serverauth*" -exec rm -iv {} \;`
    endif
endif
if ( "$status" != 0 ) then
    echo "Couldn't delete .serverauth files."
    exit 1
endif

Code:
freebsd:~
% touch -d "2024-05-21T16:31:52" .serverauth.1238
freebsd:~
% touch -d "2024-05-22T16:31:52" .serverauth.1239
freebsd:~
% touch -d "2024-05-20T16:31:52" .serverauth.1237
freebsd:~
% clear-serverauth
./.serverauth.1238 is not from today but May 21, can delete it.
./.serverauth.1239 is not from today but May 22, can delete it.
./.serverauth.1237 is not from today but May 20, can delete it.
remove ./.serverauth.1238? n
remove ./.serverauth.1239? n
remove ./.serverauth.1237? n
freebsd:~
% clear-serverauth -y
./.serverauth.1238 is not from today but May 21, deleted.
./.serverauth.1239 is not from today but May 22, deleted.
./.serverauth.1237 is not from today but May 20, deleted.
freebsd:~
% ls -lah .serverauth*
-rw-------  1 yusuf yusuf  156B Jun 22 00:17 .serverauth.43065

I've just added if ( -x "$HOME/doc/scripts/clear-serverauth" ) $HOME/doc/scripts/clear-serverauth -y to ~/.login and it works!

I don't know how to quit Xorg (but i do know how to exit vim/vi:D) properly, i use Suckless' dwm and a patch that lets me quit it with prompts (yes, no or restart).

Somehow it seems that now when closing Xorg session, .serverauth file gets deleted. :confused:
 
Back
Top