ifdown in cron bash script fails to runnode.js app runs from command line but gives errors when run from cron job on reboot on ubuntu 14.04 LTSCannot run bash script from crontab when it works from command line bash@reboot works with command but not script - Cronscript does not write to file when executed from croncrontab scheduled script errorHow do I get cron to run my bash script which references node?mysqldump script doesn't work in cronScript not logging to file when run from cron, but works fine otherwise

Obtaining optimality gaps when using hybrid exact-heuristic approaches to vehicle routing problems

How to explain my complicated family background to people that I don't know very well?

Finishing pre-cooked prime rib, day-of?

What license do I use when I don't want stock image companies charging people money for photos?

Can a public school in the USA force a 14yr old to create a Twitter account for a passing grade?

Are these homebrew metallic/chromatic pseudodragons the same CR as RAW pseudodragons?

Is there a word/short phrase for "the most" of something (not necessarily the majority)?

Naval cannons vs ships made of magic wood

Sugar daddy wants me to apply for a credit card so he can link me to his company account. Suspicious or am I being paranoid?

Why this definition for Lebesgue measurable functions?

What's the advantage of importance sampling?

Pass on your radiation

Is Kirk’s comment about “LDS” intended to be a religious joke?

CodeReview question markdown downloader

Security implication if android app can be installed on emulator

Sometimes the updated rows are not locked within instead of update trigger

Allowing comments in interactive zsh commands

Why use an adjective after a noun?

What can Scotland legally do to get independence?

How is 懐く read in this case?

Who is the controller of an Aura when the creature it enchants is stolen?

Was I wrong to rebutt unjustified rewiewer comments in the review?

How to do a privileges escalation with ping?

Any reason not to use global lambdas?



ifdown in cron bash script fails to run


node.js app runs from command line but gives errors when run from cron job on reboot on ubuntu 14.04 LTSCannot run bash script from crontab when it works from command line bash@reboot works with command but not script - Cronscript does not write to file when executed from croncrontab scheduled script errorHow do I get cron to run my bash script which references node?mysqldump script doesn't work in cronScript not logging to file when run from cron, but works fine otherwise






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









2


















I have a script that is run when a server (Ubuntu 14.04) boots up using @reboot in crontab (Under the root user)



@reboot /bin/bash /root/init.sh >> /var/logs/vminit.log


The script runs a number of things, but when it reaches this line



ifdown eth1


The script exits, and ifdown does not run. (Running ifconfig still shows eth1 in the output) Enabling Verbose mode on ifdown returns nothing too.



If I manually run the script myself, it runs as expected.



I wrote a test script just to rule out any issues with init.sh



#!/bin/bash
echo 'one'
ifdown eth1
echo 'two'


If I run it manually, I get this output (which is expected)



one
<DHCP Client info>
two


If I place this test script into the crontab to be run with @reboot, I get the same results as init.sh, and the output is



one


I've tested by running the cron at an exact time (Example: 25 14 * * *) to see if it's something with `@reboot', but no luck.



I've also tried delaying the script from running after boot incase something was blocking ifdown from running



@reboot /bin/sleep 60; /bin/bash /root/init.sh >> /var/log/vminit.log


A few notes:
- Eth1 is an active interface, prior to running ifdown the script makes a call out of eth1 to grab a file successfully.
- The script is run as root
- Permissions with the script (and log) are fine.
- Running init.sh or the test script manually runs as expected.










share|improve this question



























  • 1. Does the script (and ifdown) hang or end prematurely? (Do you see it in ps -ef?) It should hang if your script does not continue. ------ 2. Try to use the verbose switch to get more information: ifdown -v eth1 ------ 3. Does it fail if you manually restart cron? Try sudo service cron stop && sudo service cron start ------ 4. What are the exported environment variables in the working and non-working case? Store the output of export. If the non-working case is missing some variables which could be important, try to set them in your script.

    – pabouk
    Apr 30 '15 at 16:23

















2


















I have a script that is run when a server (Ubuntu 14.04) boots up using @reboot in crontab (Under the root user)



@reboot /bin/bash /root/init.sh >> /var/logs/vminit.log


The script runs a number of things, but when it reaches this line



ifdown eth1


The script exits, and ifdown does not run. (Running ifconfig still shows eth1 in the output) Enabling Verbose mode on ifdown returns nothing too.



If I manually run the script myself, it runs as expected.



I wrote a test script just to rule out any issues with init.sh



#!/bin/bash
echo 'one'
ifdown eth1
echo 'two'


If I run it manually, I get this output (which is expected)



one
<DHCP Client info>
two


If I place this test script into the crontab to be run with @reboot, I get the same results as init.sh, and the output is



one


I've tested by running the cron at an exact time (Example: 25 14 * * *) to see if it's something with `@reboot', but no luck.



I've also tried delaying the script from running after boot incase something was blocking ifdown from running



@reboot /bin/sleep 60; /bin/bash /root/init.sh >> /var/log/vminit.log


A few notes:
- Eth1 is an active interface, prior to running ifdown the script makes a call out of eth1 to grab a file successfully.
- The script is run as root
- Permissions with the script (and log) are fine.
- Running init.sh or the test script manually runs as expected.










share|improve this question



























  • 1. Does the script (and ifdown) hang or end prematurely? (Do you see it in ps -ef?) It should hang if your script does not continue. ------ 2. Try to use the verbose switch to get more information: ifdown -v eth1 ------ 3. Does it fail if you manually restart cron? Try sudo service cron stop && sudo service cron start ------ 4. What are the exported environment variables in the working and non-working case? Store the output of export. If the non-working case is missing some variables which could be important, try to set them in your script.

    – pabouk
    Apr 30 '15 at 16:23













2













2









2


1






I have a script that is run when a server (Ubuntu 14.04) boots up using @reboot in crontab (Under the root user)



@reboot /bin/bash /root/init.sh >> /var/logs/vminit.log


The script runs a number of things, but when it reaches this line



ifdown eth1


The script exits, and ifdown does not run. (Running ifconfig still shows eth1 in the output) Enabling Verbose mode on ifdown returns nothing too.



If I manually run the script myself, it runs as expected.



I wrote a test script just to rule out any issues with init.sh



#!/bin/bash
echo 'one'
ifdown eth1
echo 'two'


If I run it manually, I get this output (which is expected)



one
<DHCP Client info>
two


If I place this test script into the crontab to be run with @reboot, I get the same results as init.sh, and the output is



one


I've tested by running the cron at an exact time (Example: 25 14 * * *) to see if it's something with `@reboot', but no luck.



I've also tried delaying the script from running after boot incase something was blocking ifdown from running



@reboot /bin/sleep 60; /bin/bash /root/init.sh >> /var/log/vminit.log


A few notes:
- Eth1 is an active interface, prior to running ifdown the script makes a call out of eth1 to grab a file successfully.
- The script is run as root
- Permissions with the script (and log) are fine.
- Running init.sh or the test script manually runs as expected.










share|improve this question
















I have a script that is run when a server (Ubuntu 14.04) boots up using @reboot in crontab (Under the root user)



@reboot /bin/bash /root/init.sh >> /var/logs/vminit.log


The script runs a number of things, but when it reaches this line



ifdown eth1


The script exits, and ifdown does not run. (Running ifconfig still shows eth1 in the output) Enabling Verbose mode on ifdown returns nothing too.



If I manually run the script myself, it runs as expected.



I wrote a test script just to rule out any issues with init.sh



#!/bin/bash
echo 'one'
ifdown eth1
echo 'two'


If I run it manually, I get this output (which is expected)



one
<DHCP Client info>
two


If I place this test script into the crontab to be run with @reboot, I get the same results as init.sh, and the output is



one


I've tested by running the cron at an exact time (Example: 25 14 * * *) to see if it's something with `@reboot', but no luck.



I've also tried delaying the script from running after boot incase something was blocking ifdown from running



@reboot /bin/sleep 60; /bin/bash /root/init.sh >> /var/log/vminit.log


A few notes:
- Eth1 is an active interface, prior to running ifdown the script makes a call out of eth1 to grab a file successfully.
- The script is run as root
- Permissions with the script (and log) are fine.
- Running init.sh or the test script manually runs as expected.







networking cron reboot interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 30 '15 at 14:09







adamstrawson

















asked Apr 30 '15 at 13:56









adamstrawsonadamstrawson

234 bronze badges




234 bronze badges















  • 1. Does the script (and ifdown) hang or end prematurely? (Do you see it in ps -ef?) It should hang if your script does not continue. ------ 2. Try to use the verbose switch to get more information: ifdown -v eth1 ------ 3. Does it fail if you manually restart cron? Try sudo service cron stop && sudo service cron start ------ 4. What are the exported environment variables in the working and non-working case? Store the output of export. If the non-working case is missing some variables which could be important, try to set them in your script.

    – pabouk
    Apr 30 '15 at 16:23

















  • 1. Does the script (and ifdown) hang or end prematurely? (Do you see it in ps -ef?) It should hang if your script does not continue. ------ 2. Try to use the verbose switch to get more information: ifdown -v eth1 ------ 3. Does it fail if you manually restart cron? Try sudo service cron stop && sudo service cron start ------ 4. What are the exported environment variables in the working and non-working case? Store the output of export. If the non-working case is missing some variables which could be important, try to set them in your script.

    – pabouk
    Apr 30 '15 at 16:23
















1. Does the script (and ifdown) hang or end prematurely? (Do you see it in ps -ef?) It should hang if your script does not continue. ------ 2. Try to use the verbose switch to get more information: ifdown -v eth1 ------ 3. Does it fail if you manually restart cron? Try sudo service cron stop && sudo service cron start ------ 4. What are the exported environment variables in the working and non-working case? Store the output of export. If the non-working case is missing some variables which could be important, try to set them in your script.

– pabouk
Apr 30 '15 at 16:23





1. Does the script (and ifdown) hang or end prematurely? (Do you see it in ps -ef?) It should hang if your script does not continue. ------ 2. Try to use the verbose switch to get more information: ifdown -v eth1 ------ 3. Does it fail if you manually restart cron? Try sudo service cron stop && sudo service cron start ------ 4. What are the exported environment variables in the working and non-working case? Store the output of export. If the non-working case is missing some variables which could be important, try to set them in your script.

– pabouk
Apr 30 '15 at 16:23










2 Answers
2






active

oldest

votes


















4



















Really I don't know why ifdown doesn't work with crontab.



Anyway, I faced the same situation a long time ago and have a workaround solution, hope this will help you.



Replace



ifdown eth1


with



/sbin/ifconfig eth1 down 1> /dev/null


This worked for me.






share|improve this answer

























  • I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

    – adamstrawson
    Apr 30 '15 at 21:03











  • @adam0345 That's good

    – Maythux
    May 1 '15 at 5:27


















0



















Even if you use wpa_cli as a cron job you need to provide the full path like so:



/sbin/wpa_cli -i eth1 reconfigure





share|improve this answer


























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f616406%2fifdown-in-cron-bash-script-fails-to-run%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4



















    Really I don't know why ifdown doesn't work with crontab.



    Anyway, I faced the same situation a long time ago and have a workaround solution, hope this will help you.



    Replace



    ifdown eth1


    with



    /sbin/ifconfig eth1 down 1> /dev/null


    This worked for me.






    share|improve this answer

























    • I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

      – adamstrawson
      Apr 30 '15 at 21:03











    • @adam0345 That's good

      – Maythux
      May 1 '15 at 5:27















    4



















    Really I don't know why ifdown doesn't work with crontab.



    Anyway, I faced the same situation a long time ago and have a workaround solution, hope this will help you.



    Replace



    ifdown eth1


    with



    /sbin/ifconfig eth1 down 1> /dev/null


    This worked for me.






    share|improve this answer

























    • I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

      – adamstrawson
      Apr 30 '15 at 21:03











    • @adam0345 That's good

      – Maythux
      May 1 '15 at 5:27













    4















    4











    4









    Really I don't know why ifdown doesn't work with crontab.



    Anyway, I faced the same situation a long time ago and have a workaround solution, hope this will help you.



    Replace



    ifdown eth1


    with



    /sbin/ifconfig eth1 down 1> /dev/null


    This worked for me.






    share|improve this answer














    Really I don't know why ifdown doesn't work with crontab.



    Anyway, I faced the same situation a long time ago and have a workaround solution, hope this will help you.



    Replace



    ifdown eth1


    with



    /sbin/ifconfig eth1 down 1> /dev/null


    This worked for me.







    share|improve this answer













    share|improve this answer




    share|improve this answer










    answered Apr 30 '15 at 16:07









    MaythuxMaythux

    62.7k36 gold badges190 silver badges236 bronze badges




    62.7k36 gold badges190 silver badges236 bronze badges















    • I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

      – adamstrawson
      Apr 30 '15 at 21:03











    • @adam0345 That's good

      – Maythux
      May 1 '15 at 5:27

















    • I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

      – adamstrawson
      Apr 30 '15 at 21:03











    • @adam0345 That's good

      – Maythux
      May 1 '15 at 5:27
















    I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

    – adamstrawson
    Apr 30 '15 at 21:03





    I logged in to post that I found the cause and you've answered it for me! Turns out that the default PATH variable is different for crons and a logged in user (for an out the box install). Setting the full path /sbin/ifconfig then worked. Strange that it didn't return any errors in the output/log though.

    – adamstrawson
    Apr 30 '15 at 21:03













    @adam0345 That's good

    – Maythux
    May 1 '15 at 5:27





    @adam0345 That's good

    – Maythux
    May 1 '15 at 5:27













    0



















    Even if you use wpa_cli as a cron job you need to provide the full path like so:



    /sbin/wpa_cli -i eth1 reconfigure





    share|improve this answer





























      0



















      Even if you use wpa_cli as a cron job you need to provide the full path like so:



      /sbin/wpa_cli -i eth1 reconfigure





      share|improve this answer



























        0















        0











        0









        Even if you use wpa_cli as a cron job you need to provide the full path like so:



        /sbin/wpa_cli -i eth1 reconfigure





        share|improve this answer














        Even if you use wpa_cli as a cron job you need to provide the full path like so:



        /sbin/wpa_cli -i eth1 reconfigure






        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered Oct 1 at 22:14









        OS2OS2

        314 bronze badges




        314 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f616406%2fifdown-in-cron-bash-script-fails-to-run%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Tamil (spriik) Luke uk diar | Nawigatjuun

            Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

            Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?