[SOLVED] (LINUX) Crontab solution for "insync start" needed

Hi

I am using Linux Lubuntu 16.04.1 LTS, xenial
I am using insync package insync_1.3.12.36116-trusty_i386, 32-bit computer.

Everything works just fine except I wish to automate syncing for the evening so insync does not use up all my bandwidth during the day when I am working.

From the terminal command line I can use the following to start and stop the process. Both lines work as expected
Start: bash -c 'insync start;sleep 5;insync resume_syncing', and
Stop: bash -c 'insync pause_syncing;sleep 5;insync quit'

So I open crontab with crontab -e and place the following at the end of the crontab file for an every other minute test between 3pm and 4pm. Start on odd minutes and stop on even minutes:

1-59/2 15 * * * bash -c ‘insync start;sleep 5;insync resume_syncing’
2-58/2 15 * * * bash -c ‘insync pause_syncing;sleep 5;insync quit’

The line that pauses and quits insync from within crontab works.
The line that starts and resumes insync from within crontab does not work, although if the insync process is already started (from the command line) and was in a paused state then the command

1-59/2 15 * * * bash -c ‘insync resume_syncing’

does works.

The problem is specifically with the 'insync start' command.

I have tried many variants of the above using ’ ’ and " " and no quotes and no double quotes.

I have tried linking to a shell script placed within my home directory start_insync.sh from within crontab. The shell script works when executed from the terminal command line but not when executed by crontab.

I thought it might be to do with paths but since 'insync quit' works I can’t see why it should be. Does anyone know if 'insync quit' and 'insync start' are in the same path. Why would they work in the terminal but not in crontab.

Can anyone shed any light on this.

Thank you

tagging our engineer @lpugoy and he will get back to you.

1 Like

If anyone uses Keyboard Shortcuts in Lubuntu the following may be useful for starting and stopping insync

I should add that although I as yet have no answer to the above issue, if anyone is using Lubuntu and makes significant use of keyboard shortcuts, which makes using a computer much easier, then you can very quickly start insync (start & resume_syncing) and stop insync (pause_syncing then quit) by placing the following in your
lubuntu-rc.xml file
which is typically located at
/home/user/.config/openbox/lubuntu-rc.xml

Below for insertion in lubuntu-rc.xml

  <keybind key="w-c-a-i">
    <action name="Execute"><command>bash -c "insync start; sleep 5;insync resume_syncing"</command></action>
  </keybind>
  <keybind key="w-c-a-o">
     <action name="Execute"><command>bash -c "insync pause_syncing; sleep 5; insync quit"</command></action>
  </keybind>

Now open a terminal and sudo openbox --reconfigure to reinitialise the file and update the keyboard shortcuts.

If, at any time, you press WIN+CTRL+ALT+i (all together at the same time) it starts insync and resumes syncing.
If, at any time, you press WIN+CTRL+ALT+o (all together at the same time) it pauses syncing and quits insync.

It works perfectly and is very useful, for on the fly syncing, and even the insync start part works, although why this works when called from lubuntu-rc.xml and not when called from crontab is unknown.

Thanks

@Kes: I looked at this and found that the cause is because there is no X environment when insync start is called from the crontab. As a workaround you can try adding the --headless flag when starting Insync, e.g., insync start --headless.

1 Like

@lpugoy I can confirm the process is running with top.

It is nice to see the tray icon as confirmation; is there any workaround to get it going without --headless.

Is there a way to make the X environment start with crontab.

Thank you

Here are the lines needed to get insync going in crontab using either
- headless, you will not see the insync graphical icon in the tray interface, or
- with the graphical icon in the tray.

This particular solution gets insync going at 1am and stops it at 7am every day, so it does not use your bandwidth while you’re working

Firstly crontab -e to open crontab. Remember to save changes in crontab with CTRL+o before exiting with CTRL+x.

- with headless

# Start & resume insync syncing at 1am every evening
00 01 * * * bash -c 'insync start --headless;sleep 5;insync resume_syncing'
#--------------------^^^^^^^^^^^^^^^^^^^^^^^

# Pause syncing and quit insync at 7am every day
00 07 * * * bash -c 'insync pause_syncing;sleep 5;insync quit'

- with regular tray icon (not headless)

# Start & resume insync syncing at 1am every evening
00 01 * * * bash -c 'DISPLAY=:0 xterm -e insync start;sleep 5;insync resume_syncing'

Notice the above use of DISPLAY=:0 We have to specifically call the correct display, in the X environment, usually this is 0, and also use xterm with the -e option.

# Pause syncing and quit insync at 7am every day
00 07 * * * bash -c 'insync pause_syncing;sleep 5;insync quit'

Thanks

Thanks team insync @lpugoy, @jaduenas for the pointers and the help.