LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2019, 08:10 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,021

Rep: Reputation: 165Reputation: 165
A simple cron job will not start


Perhaps it is because it is Sunday morning but this should not be difficult

I have setup a script to monitor the state of my VPN connection. Yes, it is marked executable. The script, when run as root, works fine. The system is a Raspberry Pi 3B+ running Ubuntu Mate 18.04. This is the script
Code:
#!/bin/bash
# this job will be run every so often as set in cron
# it will write a timestamp and the status of the ProtonVPN connection to a log

echo `date` >> /var/log/getmyip.log
pvpn --status | tee -a /var/log/getmyip.log
echo >>  /var/log/getmyip.log

exit
The crontab entry is as follows (set at every 2 minutes just for testing)
Quote:
# m h dom mon dow command
*/2 * * * * root /usr/local/sbin/getmyip.sh
systemctl shows cron is running
Quote:
root@t25-magic:~# systemctl status cron
● cron.service - Regular background program processing daemon
Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-10-13 06:04:51 EDT; 2h 37min ago
Docs: man:cron(8)
Main PID: 604 (cron)
Tasks: 1 (limit: 2152)
CGroup: /system.slice/cron.service
└─604 /usr/sbin/cron -f
The only thing I have observed which is a little strange is the color coding in crontab -e. I am editing with vim. The minute (*/2) is colored purple. The hour, dom and dow are teal blue. However, the mon - which is * - is also colored purple. I have no idea if this is significant. I have retyped the line in case I made some strange typo of the monthly * but the coloration is the same.

For my next trick it occurred to me that Ubuntu does not enable the root account in the way that CentOS for example does. I use sudo su - to access root. I set a password for root to see if that would help. I logged out as sudo su and logged in as root with a plain su. I restarted cron. Still no success. I even rebooted the computer

It can't be this hard. What am I overlooking???

TIA,

Ken
 
Old 10-13-2019, 08:21 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,528

Rep: Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591Reputation: 3591
A users cronjob does not require a user name but a system cronjob (/etc/crontab) does. You switched to root but it is still a users cronjob so get rid of root.

Code:
# m h dom mon dow command
*/2 *  *    *   *  /usr/local/sbin/getmyip.sh
In addition because of the limited cron path environment you might want to include the full path to pvpn.
 
1 members found this post helpful.
Old 10-13-2019, 08:52 AM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,021

Original Poster
Rep: Reputation: 165Reputation: 165
Thank you michaelk !

That did the trick (at least as far as cron is concerned.) The ProtonVPN Linux "client" script is a bit screwball. It stores a bunch of configuration data under the account which "installs" it. If I do "sudo pvpn -init" it puts the configuration under my home .protonvpn-cli. If I do sudo su - first and then pvpn -init it puts the files under /root/.protonvpn-cli. This makes it a bit of a pain to automate the thing. My cron job will now stat but the script is not finding the configuration files. I did add the full path to the pvpn executable but I still have to create enough of a root environment to get the thing to run. Let me work on that.

Thanks again,

Ken
 
Old 10-13-2019, 09:43 AM   #4
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,021

Original Poster
Rep: Reputation: 165Reputation: 165
SUCCESS!
Quote:
In addition because of the limited cron path environment you might want to include the full path to pvpn.
The lack of the correct environment was the issue, not the ProtonVPN supplied script (well it was not completely innocent.) By actually reading the error messages which were duly recorded to my log I determined that the ProtonVPN provided script was being started by my script but openvpn was being called by the ProtonVPN script without the full path. openvpn is found in /usr/sbin/.

I added a step to my script to "echo $PATH" to my log. This confirmed that /usr/sbin and /sbin were missing from root's path as invoked by cron. I added a line to my to my script to add these to the path
Code:
PATH=$PATH:/usr/sbin:/sbin
The script can now execute the pvpn command (from the ProtonVPN script) an find the necessary programs which the ProtonVPN scrip calls.

Thank you again michaelk. I am in business. Now to figure out why my vpn systemd service, which has been running reliably for a LONG time, has started to allow the VPN connection to drop without restarting it.

Ken
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job Not Running - Looks Like Cron Tried Noble User Linux - Newbie 7 10-26-2014 10:26 AM
how to abort cron if the previous cron job not yet finished? Winanjaya Linux - Newbie 2 05-22-2012 06:44 PM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 08:52 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration