LinuxQuestions.org
Help answer threads with 0 replies.
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 01-18-2012, 04:10 PM   #1
mlmmilkyway
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Rep: Reputation: Disabled
crontab script issue


hi,

This script works from the command line but not as a crontab entry


#!/bin/bash

/usr/bin/killall -9 pppd
/bin/sleep 5
/usr/sbin/pptpsetup --delete pptp0
/bin/sleep 5
/bin/ping -c 5 test.com

/usr/sbin/pptpsetup --create pptp0 --server test.com --username user --password **** --start

/bin/sleep 5
/sbin/route add -host 192.168.2.9 gw 192.168.2.1 dev ppp0

When crontab entry runs this is all the error I get

SIOCADDRT: No such process

Any clues on what I am doing wrong?

Mark
 
Old 01-18-2012, 04:34 PM   #2
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ Reply

Hi mlmmilkyway,

Did you try increasing the sleep timer before you try to add the default gw? Another thing we need to check if you are able to ping 192.168.2.1 before adding it as gateway.

Make a copy of your script and edit it as follows:

Code:
#!/bin/bash

/usr/bin/killall -9 pppd
/bin/sleep 5
/usr/sbin/pptpsetup --delete pptp0
/bin/sleep 5
/bin/ping -c 5 test.com

/usr/sbin/pptpsetup --create pptp0 --server test.com --username user --password **** --start

/bin/sleep 5
/bin/ping -c 5 192.168.2.1
      if [ $? = 0 ]
      then
           /sbin/route add -host 192.168.2.9 gw 192.168.2.1 dev ppp0
      else
           echo "Cannot ping gateway unable to add route"
      fi
This will let us know where the script is failing when running via cron. One more thing that I would like to know as to how you have setup your cron for executing this script.
 
Old 01-18-2012, 04:54 PM   #3
mlmmilkyway
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
crontab script issue

hi,

Thanks for help adding the check gateway ping helps point out the issue.

It fails in the cron reporting that 192.168.2.1 does not respond.

command line still works though I will increase the sleep time before adding the gateway


crontab entry

*/5 * * * * /usr/sbin/BringUpRochesterLink > /tmp/ppp.log

Will be adding a check to make sure the link is down before trying to add it back.

Mark
 
Old 01-19-2012, 08:25 AM   #4
mlmmilkyway
LQ Newbie
 
Registered: Jan 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
crontab script does not work

hi,

Updated the script


/usr/bin/killall -9 pppd
/bin/sleep 5
/usr/sbin/pptpsetup --delete pptp0
/bin/sleep 5
/bin/ping -c 5 test.com
if [ $? = 0 ]
then
/usr/sbin/pptpsetup --create pptp0 --server test.com --username username
--password **** --start
else
echo "pptp0 not ready"
fi
/bin/sleep 12
/bin/ping -c 5 192.168.2.1
if [ $? = 0 ]
then
/sbin/route add -host 192.168.2.9 gw 192.168.2.1 dev ppp0
else
echo "Cannot ping gateway unable to add route"


When the script is run from the crontab the /usr/sbin/pptpsetup line never runs or at least nothing gets logged in the log file.

When run from the command line the output is this from that line:


Using interface ppp0
Connect: ppp0 <--> /dev/pts/2
CHAP authentication succeeded
local IP address 192.168.2.201
remote IP address 192.168.2.1


Do I need to add a redirect so that output goes to a file instead of trying to write to standard output?


Mark
 
Old 01-19-2012, 08:51 AM   #5
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ Reply

Yes, edit the script to redirect the output of pptpsetup command to a log file. It appears to me that when we are running this script via cron it is failing at the time of authentication.

Put it as follows:
Code:
/usr/sbin/pptpsetup --createpptp0 --server test.com --username username --password **** --start > /pptpsetup.log
Make sure you take a backup of existing script.
 
  


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
crontab issue,need help aditya_moon Linux - Newbie 2 02-07-2011 11:54 PM
create a crontab job by bash script issue xiutuo Linux - Server 4 06-07-2010 11:54 PM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 07:19 PM
[SOLVED] Crontab Issue shii_va Linux - Server 2 09-15-2009 12:30 PM
crontab issue adnanm Linux - Newbie 1 03-16-2007 03:28 AM


All times are GMT -5. The time now is 08:58 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration