Sync Google Drive from terminal using gdrive and crontab

First of all

  • Install crontab module!
  • Have a Google Account (Any will do it)
  • Have terminal (root) access to your NethServer, i tested it on NethServer 7.9.2009, it may work fine in others too or other administrator credentials!
  • Have nano installed yum install nano or your fav terminal text editor.


Install Go

Download it:


Extract it:

sudo tar -C /usr/local -xf go1.13.5.linux-amd64.tar.gz

Set Go Path

sudo nano ~/.bash_profile


export GOPATH=$HOME/golang
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin


source ~/.bash_profile


go version

Create Google Credentials
Go to:

Create a new Project:

Give any name you want.

Click here and enable GDrive API:

Configure Conset Screen:

Check “External” and click “Create”

Fill this:

You should leave the rest blank. Click in “Save and Continue”. DO NOT ADD LOGO it will give you some trouble later on…

Add one Developer contact information.

No need to add Scopes or Test Users, just click “save and continue” and “back to dasboard”.

After that click on “Credentials” and “+Create Credentials”.:

Select “Desktop App” or “Others” and click “Create”:

Save this data:

Install GDrive:

go get

After that type:

cd /$GOPATH/src/

and then:

nano handlers_drive.go

Go to line 17& 18 and add your google Credentials (use your credentials):

const ClientId = "367116221053-7n0v**"
const ClientSecret = "1qsNodXN*****jUjmvhoO"

Control+O to save changes
Hit Enter and then Control+X

Lets Build our project


go build

Move Gdrive to sbin:

sudo mv gdrive /usr/sbin/gdrive

Set Permissions:

sudo chmod 700 /usr/sbin/gdrive

Publish your APP click “OAuth conset Screen” then “PUBLISH APP”:


gdrive list

One URL should appear, follow it and authorize it. With the correct Google Account
Something like this should show in Browser, click in “advanced”:

The click in the “unsafe” option.

Click in “Allow”

And Again, click “allow”

And paste it to your terminal.

Should look something like this:

Now to start “Sync” Folders you need to create folders using Gdrive:
Do as many folders you need to sync and keep organized. I did 3 folders!

gdrive mkdir foldername

It will look something like this:

Keep those gdrive Directory names, only with those you will be able to sync a folder within your linux.
If for any reason you lost them just type:

gdrive list

Something like this should:

In my case i want to sync 3 “file shares” therefore i created a file named inside /usr/local/bin/

that means:

nano /usr/local/bin/

Inside that file.

cd /
gdrive --config root/.gdrive sync upload /var/lib/nethserver/ibay/operacional/ 1xLTs8N7L8BBWAUKdoQCO0zt2mbYd2sUN
gdrive --config root/.gdrive sync upload /var/lib/nethserver/ibay/patrimonio/ 1omMEYSMmqxqm1waXVqEREZT-7zxfjEl1
gdrive --config root/.gdrive sync upload /var/lib/nethserver/ibay/vendas/ 1k1t3ZZY_qqJLryPdIesZoNObnUqwoHCU

that --config root/.gdrive indicates where the token auth is.
The wierd letters and numbers after the ibay folder is where gdrive should sync, in my case i just need to upload, but here you can see your options.

give your execute permissions.

chmod +x /usr/local/bin/

Test it out.

Now just add it to your crotab schedule like this: