Problem with Udev Rule for making backups

Forum rules
Before you post please read this

Problem with Udev Rule for making backups

Postby emil_pavlov on Sat Jul 23, 2011 7:02 pm

I have created a udev to make backups on my external hdd, whenever it is inserted.

Code: Select all
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{serial}=="5743415A4131323437343733", RUN+="/home/emil/.exhddbakcup.sh"


The backup script is quite simple:

Code: Select all
#!/bin/bash
{
touch /home/emil/thisworks.txt
su emil alt-notify-send "Backup message" "USB Backup device detected"
sleep 150
R=$(cat /home/emil/.backupperform)
if [ "$R" = "1" ]; then
   su emil alt-notify-send "Backup Message" "It has been a while since the last backup, beginning backup."
   nice -n 17 ionice -c2 -n6 /usr/bin/backintime  --backup-job >/dev/null 2>&1
   echo '0' > /home/emil/.backupperfom
   su emil alt-notify-send "Backup Message" "Your backup has completed"
fi
} &


alt-notify-send is a script which i found on the internet, and it basically allows to send message to other users through notify, here is the code:

Code: Select all
#!/bin/sh
user=`whoami`
pids=`pgrep -u $user gnome-panel`
title=$1
text=$2
timeout=$3
 
if [ -z "$title" ]; then
        echo You need to give me a title >&2
        exit 1
fi
if [ -z "$text" ]; then
        text=$title
fi
if [ -z "$timeout" ]; then
        timeout=60000
fi
 
for pid in $pids; do
        # find DBUS session bus for this session
        DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
                /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
        # use it
        DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
        notify-send "$title" "$text"
done


After a few hours of debugging I couldn´t get this to work. If I execute the script from terminal everything is fine. When I look at udevadm it show that the script has been execute, but I neither see any message nor the file thisworks.txt is created.

Do you have some ideas?
emil_pavlov
Level 2
Level 2
 
Posts: 62
Joined: Sun Feb 03, 2008 11:06 am

Linux Mint is funded by ads and donations.
 

Re: Problem with Udev Rule for making backups

Postby Pilosopong Tasyo on Sun Jul 24, 2011 3:49 am

Replace:
Code: Select all
su emil alt-notify-send "..." "..."


With:
Code: Select all
su emil DISPLAY=:0 alt-notify-send "..." "..."


See if that will work.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 5
Level 5
 
Posts: 995
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Problem with Udev Rule for making backups

Postby emil_pavlov on Sun Jul 24, 2011 3:07 pm

No still nothing; and the file 'thisworks.txt' is not created, which means that the problem lays somewhere else.
emil_pavlov
Level 2
Level 2
 
Posts: 62
Joined: Sun Feb 03, 2008 11:06 am

Re: Problem with Udev Rule for making backups

Postby Pilosopong Tasyo on Mon Jul 25, 2011 10:52 pm

Unfortunately, I'm not familiar with using udev rules. But if I were to implement this, I'll just write a script to monitor the /media folder for the presence of the designated removable media, and execute the backup script once the media is attached to the computer. Then use cron to schedule the monitoring script to run at regular intervals. Is this approach more practical?
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 5
Level 5
 
Posts: 995
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Problem with Udev Rule for making backups

Postby emil_pavlov on Wed Jul 27, 2011 1:02 pm

Yes, I guess it is. Thank you anyway.
emil_pavlov
Level 2
Level 2
 
Posts: 62
Joined: Sun Feb 03, 2008 11:06 am


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests