LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-22-2021, 01:37 AM   #1
roffeboffe
LQ Newbie
 
Registered: Nov 2020
Location: Fredrikstad, Norway
Distribution: Ubuntu/Debian/CentOS/RedHat
Posts: 13

Rep: Reputation: Disabled
Shell script fails when running in cron


Hi

This scripts works fine when ran from command line:

Quote:
#!/bin/sh
export PASSWD=duhmmy-password
killall -9 openconnect
sleep 3
nohup echo $PASSWD | openconnect --protocol=gp --user rosc vpngateway.mycomp.com &
As stated, this works perfectly when running from command line, but it doesn't work when putting it into this cron job:

Quote:
0 */12 * * * /root/vpn-up.sh
Any tips?

Running on an old rasperry pi. Purpose is to have an always on network monotoring screen at home, but our firewall drops the vpn connection after 24 hours.

Last edited by roffeboffe; 09-22-2021 at 01:51 AM.
 
Old 09-22-2021, 02:36 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,335
Blog Entries: 3

Rep: Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731Reputation: 3731
Make sure you set the $PATH variable. It is different in the cron environment from the one in the interactive shell.

Code:
#!/bin/sh

PATH=/usr/local/bin:/usr/bin:/bin

...
Add in the paths for the location of openconnect and the other parts you are using.
 
Old 09-22-2021, 02:41 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
the usual way to diagnose an issue like this is to catch the error. Either by checking the log of cron or:
Code:
0 */12 * * * /root/vpn-up.sh > /path/to/logfile 2>&1
And you will see the real problem. From the other hand cron has its own environment and need to be adjusted (see post #2). I would suggest you to use full path with your commands in that script (and probably do not need to export PASSWORD)
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 08:57 PM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
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
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:24 AM.

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