Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    IFCONFIG command not found when using crontab


    Hi,
    I wrote a script to get IP and MAC address of local machine, the script works fine when executing it directly but when I add it to cron job im getting mail stated if config not found. Why? How can I fix it?

    Here is the error:
    To: root@localhost.localdomain
    Subject: Cron <root@localhost> bash /root/myscripts/server_status.sh >> /root/myscripts/cron.log
    X-Cron-Env: <SHELL=/bin/sh>
    X-Cron-Env: <HOME=/root>
    X-Cron-Env: <PATH=/usr/bin:/bin>
    X-Cron-Env: <LOGNAME=root>
    X-Cron-Env: <USER=root>

    /root/myscripts/server_status.sh: line 9: ifconfig: command not found
    /root/myscripts/server_status.sh: line 18: ifconfig: command not found

    And here is my script:
    Code:
    #!/bin/sh
    SHELL=/bin/bash
    
    
    # Shell script scripts to read ip address
    OS=`uname`
    IO="" # store IP
    case $OS in
       Linux) IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
       FreeBSD|OpenBSD) IP=`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
       SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
       *) IP="Unknown";;
    esac
    echo "Local IP: $IP"
    
    
    #Get MAC address
    MAC=`ifconfig  | grep 'Link encap:'| grep -v 'Local' | awk '{ print $5}'`;
    echo "Local MAC: $MAC"
    
    URL="http://localhost/test.php?mac=$MAC&lan_ip=$IP"
    echo "Requesting URL: $URL"
    
    wget --spider -q $URL

  2. #2
    Trusted Penguin Dapper Dan's Avatar
    Join Date
    Oct 2004
    Location
    The Sovereign State of South Carolina
    Posts
    4,634
    All I can think of is to maybe try /sbin/ifconfig.
    Linux Mint + IceWM Registered: #371367 New Members: click here

  3. #3
    do you mean like do the declaration?
    ifconfig=/sbin/ifconfig?

    or actually to use the path instead of the command?

  4. $spacer_open
    $spacer_close
  5. #4
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,874
    As stated by Dapper Dan, try the full path in your script. I think either way might work.
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

    I'd rather be lost at the lake than found at home.

  6. #5
    This didnt work:
    ifconfig=/sbin/ifconfig

    but full path as the command name did work!
    THANKS!

    Another quick question:
    How can I run my script on 1) startup 2)reboot 3) shotdown and detecting what type of action is that?

    I know it has to do something with "rc" file but my windows guessing doesnt really help

  7. #6
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,874
    you can simply make use of the /etc/rc.d/rc.local file. This script file is run once, before all other scripts have run but before the logon prompt appears. By default it looks something like:

    #!/bin/bash
    #
    # /etc/rc.local - run once at boot time
    # Put any local setup commands in here:
    You can append your instructions onto the end of the file by defining another script to be run:

    /root/bin/start_bb

    Or you can modify rc.local by adding the commands themselves:

    modprobe -r uhci
    modprobe usb-uhci
    eciadsl-start
    netdate time.nist.gov
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

    I'd rather be lost at the lake than found at home.

  8. #7
    ok, i think i did get the first part on how to execute script on startup, but have no idea what the second part is about?

    Also im reading this page:
    http://www.comptechdoc.org/os/linux/...runlevels.html

    is it posible to have one script that detects what is going on reboot|poweroff|startup and then opens another script and passing a variable lets say action that has type of operation in it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •