Skip to content

Instantly share code, notes, and snippets.

@shingonoide
Last active August 30, 2023 14:27
Show Gist options
  • Save shingonoide/1947a97e3c00168372e950a6788ce9ad to your computer and use it in GitHub Desktop.
Save shingonoide/1947a97e3c00168372e950a6788ce9ad to your computer and use it in GitHub Desktop.
Simple script to clean up Odoo session files
#!/bin/sh
# example
# add this to crontab -e of odoo user
# curl -sL https://gist.github.com/shingonoide/1947a97e3c00168372e950a6788ce9ad/raw/cleanup_odoo_session.sh > /tmp/cleanup_sessions.sh && sh /tmp/cleanup_sessions.sh 4
HOW_OLDER=${1:-6}
VERBOSE=${2:-0}
SESSION_FOLDER="$HOME/.local/share/Odoo/sessions"
TOTALFILES=$(find $SESSION_FOLDER -name '*.sess' | wc -l)
FILES2REMOVE=$(find $SESSION_FOLDER -name '*.sess' -mtime +"$HOW_OLDER")
COUNT2REMOVE=$(echo "$FILES2REMOVE" | wc -l)
for file in $FILES2REMOVE
do
if [ "$VERBOSE" == "0" ]
then
rm $file
else
rm -v $file
fi
done
echo "Total $TOTALFILES files, was removed $COUNT2REMOVE files, still left $(($TOTALFILES - $COUNT2REMOVE)) files"
@jhickman
Copy link

jhickman commented Aug 9, 2018

May want to add a -n to the COUNT2REMOVE, otherwise it's counting a blank line (showing 1 when there are zero files to remove)

COUNT2REMOVE=$(echo -n "$FILES2REMOVE" | wc -l)

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