drive icon indicating copy to clipboard operation
drive copied to clipboard

Using drive in unattended script (eg: crontab)

Open badzz opened this issue 8 years ago • 7 comments

Hi, Thanks a lot for maintaining this great package.

I am struggling to find a combination of option that works for me. The idea is to pull all my data to my local disk once a day and have a log of modified files to check that everything went well I tried drive pull --no-prompt /mypath >> /tmp/sync.log 2>&1 but all I get is "resolving", the spinner seems to be bugging the stdout using -quiet is killing all logs but errors which is not good for me

then I tried drive pull --piped --no-prompt /mypath >> /tmp/sync.log 2>&1 I get and html output (anyway to get txt ?) but only a depth 1

Then I tried drive pull --piped --depth -1 --no-prompt /mypath >> /tmp/sync.log 2>&1 but no luck, still depth 1 seems to be updated.

any idea ?

badzz avatar Mar 15 '16 17:03 badzz

Hello @badzz, thank you for the report and welcome to drive.

Unfortunately, I personally run drive only manually. However @Sadi58 has made a nice package https://github.com/Sadi58/indicator-drive that was mentioned originally in https://github.com/odeke-em/drive/issues/601. Also there have been a couple of contributors who have mentioned using drive in cron jobs in issues https://github.com/odeke-em/drive/search?q=cron&type=Issues&utf8=%E2%9C%93.

As for the html output, using --piped actually cat's your file so basically you are outputting the content of the file to your sync.log which is not what you want.

What you could do to test it out is try pulling from a smaller set of files and then if that works right for you, you can expand to other directories. You can also pull from multiple paths btw.

odeke-em avatar Mar 18 '16 22:03 odeke-em

Ping!

odeke-em avatar Apr 29 '16 08:04 odeke-em

Hi Good Job odeke-em, this is the better software for google drive, it works perfectly thank you for contribute and share...

I want to contribute for the cronjob to help other people that can read this post,

this work for me in a cronjob (crontab -e)

      # Method one
 $GOPATH/bin/drive push -quiet  /your_mountpoint_here/
 $GOPATH/bin/drive pull -quiet  /your_mountpoint_here/

     # Method two - find your $GOPATH
 $ cd $GOPATH
 $ pwd
 /var/go/example_folder/

 /path_GOPATH/bin/drive push -quiet /your_mountpoint_here/    
 /path_GOPATH/bin/drive emptytrash -quiet /your_mountpoint_here/

     # EXAMPLE gopath in /var/go/

  /var/go/bin/drive push -quiet /your_mountpoint_here/
  /var/go/bin/drive emptytrash -quiet /your_mountpoint_here/



      # example in script with log
 ________________________________________
 #!/bin/bash
 {
 export DATE=\`date +%Y-%m-%d_%H_%M\`
 tar -cvzf /mnt/drive/path of your drive/backup_example_$DATE.tar.gz --exclude=FOLDERTexample   /home/example/

 /your_$GOPATH /bin/drive push -quiet /your_mountpoint_here/
 /your_$GOPATH/bin/drive emptytrash -quiet /your_mountpoint_here/



 } 2>&1 | tee /var/log/cron/backup.log
 _________________________________________
     # and put in your cronjob with  
 $ crontab -e

     # add the line

0   23   *    *    1-6       bash  /path your script/job_drive.sh   

~

Edtigoza avatar Jul 09 '16 21:07 Edtigoza

Thank you @Edtigoza! Sounds like a plan, you could also put the scripts on the wiki https://github.com/odeke-em/drive/wiki under a section say "Crontab scripts" and there people will easily find them.

odeke-em avatar Jul 09 '16 21:07 odeke-em

i found there is already a script https://gist.github.com/RickCogley/bfdbe717753dd989a813 only need edith and can work

Edtigoza avatar Jul 09 '16 22:07 Edtigoza

I'm getting the same problem. I would like to send the stdout output to a notify-send notification.

I only get Resolving... in the output.

05:20:39 [sw@workstation]:[~/Documents/GOOGLE_DRIVE] $ drive-google push -no-prompt
Resolving...
- /test
M /log.txt
Deletion count 1
Modification count 1 dest: 13.00B
05:21:18 [sw@workstation]:[~/Documents/GOOGLE_DRIVE] $ drive-google push -no-prompt >> log.txt
05:21:30 [sw@workstation]:[~/Documents/GOOGLE_DRIVE] $ cat log.txt 
Resolving...

When running with strace I see Resolving... sent to stdout through a write syscall, while the rest of the output sent through a futex syscall, not counting as actual stdout output.

write(1, "Resolving...\n", 13Resolving...
)          = 13
futex(0xc420040d48, FUTEX_WAKE, 1)      = 1
rt_sigprocmask(SIG_SETMASK, ~[HUP INT QUIT ILL TRAP ABRT BUS FPE SEGV TERM STKFLT CHLD PROF SYS RTMIN RT_1], NULL, 8) = 0
rt_sigprocmask(SIG_SETMASK, ~[HUP INT QUIT ILL TRAP ABRT BUS FPE SEGV TERM STKFLT CHLD PROF SYS RTMIN RT_1], NULL, 8) = 0
futex(0xbb1ac8, FUTEX_WAIT, 0, NULL)    = 0
futex(0xbb1ac8, FUTEX_WAIT, 0, NULL- /log.txt
- /swa
Deletion count 2 dest: 13.00B
 13 / 13 [=========================================================================================================================================] 100.00% 0s
)    = ?
+++ exited with 0 +++

sebw avatar Oct 14 '18 03:10 sebw

I am having the same problem. Did anyone find a fix for this?

hightowe avatar Aug 30 '20 15:08 hightowe