Note that there are some explanatory texts on larger screens.

plurals
  1. POBASH SCRIPT : Code works from terminal but not from rc.local
    primarykey
    data
    text
    <p>I've written a small script that ping's an address and then mounts the device at that address if the ping returned successful. The file is located in rc.local on a Ubuntu Linux System.</p> <p>It works great if run from a terminal (as root), but won't run from rc.local at boot. I know it's being executed because /tmp/buffalo_mount.log contains "Executing Network Device Detect Script From rc.local". Anyone got any ideas?</p> <p>NOTE: <strong>Now working!</strong> Please read notes below :-)</p> <pre><code>#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. ADDRESS=192.168.1.101 DATETIME="$(date)" LOGFILE="/tmp/buffalo_mount.log" sleep 30s echo "Executing Network Device Detect Script From rc.local" &gt;&gt; $LOGFILE if /bin/ping -c 1 -t 1 $ADDRESS &gt; /tmp/ping 2&gt;&amp;1 ;then # check the exit code echo "$ADDRESS is LIVE "+$DATETIME &gt;&gt; $LOGFILE # display the output # Ping reply was good, so run the mount command. echo "Slept, now mounting device" &gt;&gt; $LOGFILE /bin/mount /media/Buffalo/Acer-laptop-back_in_time else echo "$ADDRESS is DEAD "+$DATETIME &gt;&gt; $LOGFILE fi </code></pre> <p>Then I had to edit the '/etc/fstab' file so the fstab knows about the mount, but doesn't mount until told to by my script above, using the '<strong>noauto</strong>' parameter. My example in fstab is:-</p> <pre><code>//192.168.1.101/back-in-time/ /media/Buffalo/Acer-laptop-back_in_time cifs **noauto**,guest,uid=1000,iocharset=utf8,codepage=unicode,unicode,_netdev 0 0 </code></pre> <p>Really hope this help someone because it was driving me nuts. Thanks to all those that helped.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload