
나는 systemctl과 crontab을 사용해 보았으나 성공하지 못했습니다.
스크립트는 다음과 같습니다.
#!/bin/bash
cyberghostvpn --country-code AU --city Brisbane --connect
권리:
-rwxr-xr-x 1 pat pat 71 nov 28 13:04 ghoststart.sh
내가 이런 식으로 실행한 내 crontab은 다음과 같습니다.sudo crontab -e
@reboot sleep 120; /home/pat/Documents/cyberghost/ghoststart.sh
문제 없이 터미널에서 스크립트를 실행할 수 있습니다.sudo sh ghoststart.sh
syslog 크론:
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)
cron이 13:24:04 이후에 작동을 멈춘 것 같습니다. 왜냐하면 그 이후에 시도를 완료했기 때문입니다.
편집 2: 기반이것나는 시도했다
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!
내가 루트가 아닌 경우에도 동일한 오류가 발생합니다. 분명히 openvpn이 설치되어 있습니다.
세 번째 편집:
이렇게 하면 오류가 발생하지 않습니다.
pat@mrpotato:~$ sudo /bin/sh -c "(export PATH=/usr/bin:/bin; /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)"
하지만 내가 이렇게 하면 다음 중 하나를 얻게 됩니다.
root@mrpotato:~# /bin/sh -c "(export PATH=/usr/bin:/bin; /home/pat/Documents/cyberghost/ghoststart.sh </dev/null)"
오류는 다음과 같습니다
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가 존재합니다./home/pat/.cyberghost/
cron은 sudo가 아닌 루트로 스크립트를 실행해야 합니다... 또는 이와 유사한 스크립트는 실행 중인 사용자로부터 파일을 가져옵니다... 그것이 의미가 있다면.
나는 그것을 어떻게 해결해야할지 모르겠어요!
답변1
귀하의 ghoststart.sh
스크립트(또는 cyberghostvpn
그 안에 있는 것)가 실행 파일을 호출하여 OpenVPN을 시작하려고 합니다 openvpn
. 이 실행 파일은 $PATH
스크립트 내의 에서 찾을 수 없습니다 . command -v openvpn
터미널에서 실행 파일의 경로를 찾는 데 사용됩니다 .
실행 openvpn
파일이 에 있으면 /usr/sbin
crontab 일정을 다음과 같이 작성할 수 있습니다.
@reboot sleep 120 && PATH="$PATH:/usr/sbin" /home/pat/Documents/cyberghost/ghoststart.sh
"세 번째 편집"은 또한 도구가 도구를 시작하는 사용자의 홈 디렉터리에서 구성 파일을 찾고 있음을 나타냅니다. 이 파일이 의 홈 디렉터리 pat
가 아니라 의 홈 디렉터리에 있다고 가정합니다 root
.
여기에는 두 가지 옵션이 있습니다.
- 도구가 찾을 것으로 예상되는 위치로 구성 파일을 이동하거나
- 도구가 어디에
HOME
있는지 알려주세요.
두 번째 옵션은 다음과 같이 cron 작업을 수정하여 수행할 수 있습니다.
@reboot sleep 120 && HOME=/home/pat PATH="$PATH:/usr/sbin" /home/pat/Documents/cyberghost/ghoststart.sh
답변2
root@mrpotato:/var/spool/cron/crontabs# /bin/sh -c "(내보내기 PATH=/usr/bin:/bin;/home/pat/Documents/cyberghost/ghoststart.sh
openvpn 바이너리는 어디에 있습니까? 내 데비안에서는 /usr/sbin
발생한 오류를 설명하는 스크립트에 전달한 PATH 변수의 일부가 아닙니다.