Sponsored Content
Top Forums Shell Programming and Scripting Bash script acting funny when run from Crontab Post 302913418 by mkoster on Saturday 16th of August 2014 01:46:16 PM
Old 08-16-2014
Bash script acting funny when run from Crontab

Hello, first time here. I have a script that seems to ignore the if statement when run from the cron. I am using Ubuntu 12.10

Code:
#!/bin/bash

DOWN=/usr/sbin/dcon
UP="pon dsl-provider"
LOG=/var/log/dsl-reconnect.log

RECV=`ifconfig 2>&1|grep ppp0|cut -d , -f 5|cut -d " " -f 1`

if [[ $RECV != *ppp* ]]
then
echo "connecting..."
echo ----- >>$LOG
date>>$LOG
$DOWN >>$LOG 2>&1
wait for kill
sleep 3
echo "hopefully killed"
$UP >>$LOG 2>&1
fi

When run from console, the script works the way it should, I even tested by echoing $RECV before the if statement and it shows hat it holds the value ppp0, however when run from cron, it doesn't seem to work right, it does everything within the if statement, killing the connection and reconnecting it, regardless if its already connected.

BTW, This is a modified script from this site - www dot khattam dot info/howto-auto-re-connect-to-dsl-pppoe-in-linux-2010-03-07.html which didn't work at all for me. I tried using the pppoe settings but Ubuntu seems to ignore the settings.

---------- Post updated at 01:46 PM ---------- Previous update was at 12:59 PM ----------

Ok, fixed it, seems when you place something in the cron using crontab -e the environment ignores /sbin/ so I made it do the command /sbin/ifconfig and it works fine.

Last edited by rbatte1; 08-16-2014 at 05:21 PM.. Reason: Spelling and ICODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

recurring run of sh script in crontab

Hello gurus. I have a problem: my crontab -e is looks like this: ORACLE_SID=bla-bla * 21 * * * (sqlplus hotback/hotback @/oracle/backups/bla-bla/scripts/hotback/daily_hotback.sql) 0 19 * * * /oracle/backups/dev10g/scripts/exports/daily_exports.sh 0 1 * * *... (4 Replies)
Discussion started by: MarGur
4 Replies

2. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

3. Shell Programming and Scripting

How do i run a shell script without crontab.

Hi Folks, Could you please suggest me how to run a shell script on a solaris env without using crontab. I am actually trying to write a shell script which will grep "WORD" in the logfile andd sends a email.Thanks in advance. Thanks Sandeep. (3 Replies)
Discussion started by: sandeep anand
3 Replies

4. Shell Programming and Scripting

bash-function with array acting bizarre, bug?

Hello, basically what this script is supposed to do is showing a list of hosts that is given a number, that you will be able to choose from a list. A check is made to verify that the chosen number is within the array and this is where things go bad and I don't know why, bizarre. I've spent... (5 Replies)
Discussion started by: gand
5 Replies

5. Shell Programming and Scripting

crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command: /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessagesFrom a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it? /usr/bin/syslogMailer... (4 Replies)
Discussion started by: jelloir
4 Replies

6. Shell Programming and Scripting

run script through crontab using ksh

hi i have a script called test.sh. the content is ls >> crontest.txt. if i run manually it's giving output.but if i scheduled in crontab it's not giving output. crontab entry: 02 * * * * /sms5/SMSHOME/eds_sh/test.sh >> /sms5/SMSHOME/eds_sh/testfile/logfile 2>&1 I am using ksh.is there... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

7. Shell Programming and Scripting

BASH weird acting: unquoted parameter accepted as quoted one !

In one session I have strange behavior of the bash-shell: SDX-Q> echo ">$ss<" #this is just to present the $ss var: > lll kkk < SDX-Q> # more obviose: SDX-Q> od -cb <<<"$ss" 0000000 l l l k k k \n 040 040 040 154 154 154 040... (3 Replies)
Discussion started by: alex_5161
3 Replies

8. Shell Programming and Scripting

Cannot get this bash/expect script to run under a crontab

#!/bin/bash # # RAP configuration script # # Usage: ./rap.sh # # Requires: expect, tcl # # Script expects to find a file called rap.csv located in the same directory as the script. If the file is placed # in a different directory, modify the custom entries section to specify the absolute... (8 Replies)
Discussion started by: mrkool
8 Replies

9. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

10. Shell Programming and Scripting

Script containing Curl doesn't run with crontab

Hello I have a problem with the crontab command when I run a code containing Curl on the command line it runs without fail but as soon as I program it with crontab it executes everything except the curl returns fail thank you for helping me to resolve this problem because since Monday I look... (14 Replies)
Discussion started by: beautymind
14 Replies
PPPOECONF(8)						      System Manager's Manual						      PPPOECONF(8)

NAME
pppoeconf -- configures a PPPoE (ADSL) connection SYNOPSIS
pppoeconf [-nox] [iface] DESCRIPTION
The pppoeconf program is user-friendly dialog based setup tool for pppd (and pppoe if needed). It will look for existing ethernet cards and look for ADSL hardware connected to one of them. You can add an interface name iface to force pppoeconf to use it. Then it will get some login info and do some minor modifications to make working settings. Note that you can use ESC key to exit program when you wan. OPTIONS
-nox Force ncurses use. FILES
/etc/ppp/peers/dsl-provider is pppd options file for your dsl provider. /etc/ppp/pap-secrets and /etc/ppp/chap-secrets are described in pppd documentation. pppoeconf may add lines to theses files. /etc/ppp/ip-up.d/0clampmss and /etc/ppp/ip-down.d/0clampmss are used to clamp MSS if needed. /etc/network/interfaces is network interface file for your system. SEE ALSO
pppd(8), interfaces(5), pon(1) and pppoe(8). AUTHOR
This manual page was originally written by Eduard Bloch (blade@debian.org) and now maintained by Gregory Colpart (reg@evolix.fr) for the Debian GNU/Linux system (but may be used by others). This document is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. PPPOECONF(8)
All times are GMT -4. The time now is 02:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy