Announcement

Collapse
No announcement yet.

Problem with running script at startup

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Problem with running script at startup

    I want to run a script to backup curtain files at startup using rsync.
    My script works fine when run out of Dolphin /'Run In Console'.
    The script also write date-time to a file before and after backing up.
    When the script runs at start-up the before and after times are identical.
    I used System Settings/Autostart/script file to run the file at start up.
    Here is the script file:-
    Code:
    #!/bin/bash         
    
    # sleep for 30 seconds
    sleep 30
    
    # start time
    d=$(date '+%d/%m/%Y %H:%M:%S')
    echo "Start $d" >> /home/bill/startup.txt
    echo "$d"
    
    rsync -av --delete /home/bill{/Documents,/GambasFolder} /media/bill/MUSIC/new
    
    # end time
    d=$(date '+%d/%m/%Y %H:%M:%S')
    echo "End $d" >> /home/bill/startup.txt
    echo "$d"
    Any ideas welcome.

    #2
    You could try logging the rsync command to see what is happening:

    rsync -av --delete --log-file="/home/bill/startup.log" /home/bill{/Documents,/GambasFolder} /media/bill/MUSIC/new

    Please Read Me

    Comment


      #3
      How have you arranged for "/media/bill/MUSIC/new" to be mounted at startup?

      If it's a plug in device, your script could check whether it's present and fail gracefully if not.
      Regards, John Little

      Comment


        #4
        Thanks for the ideas.
        oshunluvr, --log-file="/home/bill/startup.log" was a good idea,
        Code:
        2020/08/03 07:56:45 [1533] building file list
        2020/08/03 07:56:45 [1533] rsync: mkdir "/media/bill/MUSIC/new" failed: No such file or directory (2)
        2020/08/03 07:56:45 [1533] rsync error: error in file IO (code 11) at main.c(682) [Receiver=3.1.3]
        Shows that the USD drive isn't ready.
        Just as jlittle guessed!

        As far as I can see, the usb stick is automatically mounted at start up

        Comment


          #5
          Some points that may be relevant:
          • "startup"? Do you mean at boot time, or KDE startup? Those are different if you have a login screen. The Autostart scripts in system settings are KDE things, I think, and they can run "before session start-up" or "Startup".
          • There's lots of ways to run scripts at boot time. systemd does several out of the box, and you can add further services for systemd.
          • I'm not sure when the "automounts" set up in system settings, removable devices happens. I presume you've got "MUSIC" set to automount at login.
          • Scripts can trigger the mounts that dolphin does using the udisksctl command. Rather than relying on KDE to automount "MUSIC", it could use udisksctl to mount it, and avoid timing issues.
          • I would worry about the consistency of the data on a removable device. Linux can be silly with this it's copying a large amount (say, GB) of data, and say it's finished when it's still got minutes to go before everything is flushed. In theory the ancient "sync" command should sort this, but I'd still be inclined to unmount after the rsync; then maybe mount it again.
          Regards, John Little

          Comment


            #6
            Should be easy enough to have the script wait for the USB stick or mount it directly:

            Something like:
            Code:
            if ! mountpoint -q /media/bill/MUSIC/new ; then 
                mount /media/bill/MUSIC/new
            fi
            done

            Please Read Me

            Comment


              #7
              Thanks oshunluvr & jlittle.
              Tried the code to mount the usb but rsync still couldn't find the drive.
              I looked through John Little's ideas and in System Settings/removable storage found that I needed to specify that the usb be mounted at start up.
              The script now works just fine.

              Thanks also for the caution about the reliability of memory sticks. I have been struggling to auto mount Mycloud (local network storage device) so thought that in the mean time it would be simple to auto backup to the memory stick, without your help I don't think I could have done it.

              So back to the challenge of auto mounting the network drive!

              Thanks again.

              Comment

              Working...
              X