-1

I tried with systemctl and with crontab without success.

here is the script:

#!/bin/bash
cyberghostvpn --country-code AU --city Brisbane --connect

rights :

-rwxr-xr-x 1 pat pat 71 nov 28 13:04 ghoststart.sh

my crontab that i have run this way : sudo crontab -e

@reboot sleep 120; /home/pat/Documents/cyberghost/ghoststart.sh

i can run the script in terminal no problem : sudo sh ghoststart.sh

syslog cron :

Nov 28 13:17:57 mrpotato cron[679]: (CRON) INFO (pidfile fd = 3)
Nov 28 13:17:57 mrpotato cron[679]: (CRON) INFO (Running @reboot jobs)
Nov 28 13:17:59 mrpotato CRON[726]: (root) CMD (sh /home/pat/Documents/cyberghost/ghoststart.sh)
Nov 28 13:24:04 mrpotato cron[658]: (CRON) INFO (pidfile fd = 3)
Nov 28 13:24:04 mrpotato cron[658]: (CRON) INFO (Running @reboot jobs)

seems like cron stopped working after 13:24:04, beacause ive done attempt after that

edit 2: based on this i have tried

root@mrpotato:/var/spool/cron/crontabs# /bin/sh -c "(export PATH=/usr/bin:/bin; /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)"
Prepare OpenVPN connection ...
Please Install "openvpn" first!

it gives me the same error if i wasnt root, obviouly openvpn is installed

3rd edit:

if i do this i get no error .

pat@mrpotato:~$ sudo /bin/sh -c "(export PATH=/usr/bin:/bin; /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)"

but if i do this i get one:

root@mrpotato:~# /bin/sh -c "(export PATH=/usr/bin:/bin; /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)"

the error is :

Traceback (most recent call last):
  File "cyberghostvpn.py", line 580, in <module>
  File "cyberghostvpn.py", line 346, in main
  File "libs/config.py", line 45, in __init__
  File "libs/config.py", line 112, in readConfigFile
Exception: The config file "/home/root/.cyberghost/config.ini" does not exist!
[3845] Failed to execute script cyberghostvpn

config.ini exist in /home/pat/.cyberghost/

cron must be running the script as root and not with sudo... or something like that, the script gets the file from the running user... if that make sense.

i have no idea how to solve that !

1
  • Could you look up in the journal/syslog if there are any error messages from your previous attempts which might help to track down the reason for the failure? Commented Nov 28, 2019 at 9:37

2 Answers 2

2

Your ghoststart.sh script (or the cyberghostvpn thing within it) is trying to start OpenVPN by calling the openvpn executable. This executable is not found in the $PATH within the script. Use command -v openvpn in a terminal to locate the path of the executable.

If your openvpn executable is located in /usr/sbin, you may write your crontab schedule as

@reboot sleep 120 && PATH="$PATH:/usr/sbin" /home/pat/Documents/cyberghost/ghoststart.sh

Your "3rd edit" also indicates that the tool is looking for a configuration file in the home directory of the user starting the tool. You say you have this file in the home directory of pat and not in the home directory of root.

You have two options here:

  1. Move the configuration file to where the tool expects to find it, or
  2. Tell the tool where HOME is.

The second option could be done by modifying the cron job to say

@reboot sleep 120 && HOME=/home/pat PATH="$PATH:/usr/sbin" /home/pat/Documents/cyberghost/ghoststart.sh
16
  • /bin/sh -c "(export PATH=/usr/bin:/bin; /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)" that is working now but not with cron, logs are not helpful : Nov 29 13:25:01 mrpotato CRON[2378]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1) Commented Nov 29, 2019 at 3:35
  • cyberghostvpn is written in python should i add that path too Commented Nov 29, 2019 at 4:07
  • @Patcmpro 1) I'm not surprised that your command does not work from cron, this is why I gave you the suggestion in my answer. 2) I have removed the second suggestion as it was confusing. Commented Nov 29, 2019 at 6:52
  • i did that and its still not working... ill try again Commented Nov 30, 2019 at 10:49
  • @Patcmpro Do you still get the same error message about not finding openvpn? Do you know where the openvpn executable file is located? Commented Nov 30, 2019 at 10:51
0

root@mrpotato:/var/spool/cron/crontabs# /bin/sh -c "(export PATH=/usr/bin:/bin;/home/pat/Documents/cyberghost/ghoststart.sh

Where is located your openvpn binary ? On my Debian, it is in /usr/sbin which isn't part of the PATH variable you passed to your script... which explain the error you met.

3
  • yes its located at /usr/sbin Commented Nov 28, 2019 at 11:05
  • root@mrpotato:/var/spool/cron/crontabs# /bin/sh -c "(export PATH=/usr/bin:/bin;/usr/sbin/ /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)" /bin/sh: 1: /usr/sbin/: Permission denied Commented Nov 28, 2019 at 11:39
  • 1
    You have a ; in the PATH (should be :). Commented Nov 28, 2019 at 16:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.