Automatically Move Files From One Dir To Another

Here is a lame script that you can run in the background to automatically pick up files in one user’s home directory and place them on your desktop. Just run this as root and it will check to see if the user is no longer logged in first and if so, it takes ownership of any file found and moves it to your desktop.

#!/bin/bash

if [ "$2" == "" ]
then
	echo "Usage: $0 <source username> <destination username>"
	exit 1
fi

while true
do
	testoutp=`who | grep -i "$1"`
	if [ "$testoutp" == "" ]
	then
		find /home/$1 -type f -exec chown "$2:$2" "{}" \;
		find /home/$1 -type f -exec mv "{}" "/home/$2/Desktop/tmp/" \;
	fi
	sleep 5
done

One thought on “Automatically Move Files From One Dir To Another

Leave a comment