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

Advertisements
Automatically Move Files From One Dir To Another

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s