Yes, the primary problem here is the missing interpreter line.
If you add this via crontab, I would recommend adding a shell path to crontab to make sure it can find all the binary programs you are using too. Have a look at this link to see what I'm talking about.
I can help you out if you need me...just send me a PM.
EDIT: Here is the modified script:
/var/scripts/drivetoggle.sh
Code:
#!/bin/bash
#############################################
## Name : drivetoggle.sh
## Version : 1.1
## Date : 2012-10-02
## Author : MG2R
## Compatibility : Ubuntu Server 12.04.1 LTS
## Purpose : Toggle drives on/offline based on status of IP.
## Run Frequency : Continuous
## Exit Codes : None
## Forum : http://ubuntuforums.org/showthread.php?t=2065600
################ CHANGE LOG #################
## DATE WHO WHAT WAS CHANGED
## ---------- ---- ----------------------------
## 2012-10-02 MG2R Created script.
## 2012-10-02 LTH Minor updates to work via sudo or crontab.
#############################################
Logfile="/var/log/drivetoggle.log"
Machine="192.168.1.150"
Enabled=2
echo "`date +%Y-%m-%d_%H:%M:%S` [INFO] Script started." | tee -a ${Logfile}
while true
do
ping -c 1 ${Machine} > /dev/null 2>&1
if [ $? -eq 0 ]; then
## Machine is online.
if [ ${Enabled} -ne 0 ]; then
## Turn on the drives.
hdparm -S 0 /dev/sda /dev/sdb
echo "`date +%Y-%m-%d_%H:%M:%S` RAID stand-by disabled" | tee -a ${Logfile}
fi
Enabled=0
else
## Machine is offline.
if [ ${Enabled} -ne 1 ]; then
## Turn off the drives.
hdparm -S 2 /dev/sda /dev/sdb
echo "`date +%Y-%m-%d_%H:%M:%S` RAID stand-by enabled" | tee -a ${Logfile}
fi
Enabled=1
fi
sleep 1m
done
Login with your admin account and type "sudo su" to temporarily login as root user.
Type the following:
Code:
mkdir /var/data
touch /var/data/crontab.root
chown root:root /var/data/crontab.root
chmod 0600 /var/data/crontab.root
Edit /var/data/crontab.root and add this to the file:
NOTE: If you have anything in the crontab schedule now, add it to this file.
Code:
########################################
# Name: Crontab Schedule for root user
# Author: LHammonds
############# Update Log ###############
# 2012-10-02 - LTH - Created schedule
########################################
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Crontab SYNTAX:
# minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) command-to-execute
#
# Adjust the time clock
#
0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1
#
# Toggle drives on/offline based on status of IP
#
@reboot /var/scripts/drivetoggle.sh > /dev/null 2>&1
To enable the root schedule using this file, type the following:
Code:
crontab -u root /var/data/crontab.root
To disable the root schedule, type the following:
Code:
touch /tmp/deleteme
crontab -u root /tmp/deleteme
rm /tmp/deleteme
LHammonds
Bookmarks