user2239837
user2239837

Reputation: 1

crontab sends net rpc shutdown but nothing happens

I've created two scripts to automate turning on and off computers in my classroom.

Both scripts get a list of MAC ID's and use them to 1)wake up computers (wake command) and 2)shut down computers (net rpc shutdown).

Server is FREEBSD and workstations are win7.

Both scripts look alike except for the part "wake" and "net rpc shutdown". Both scripts work perfectly when runned manually (via shell).

Only WOL script runs with crontab, shutdown script run as-well, but nothing happens to computers.

Cron logs just show, that the script is processed, but computers won't react.

Shutdown script:

#!/usr/local/bin/bash
#[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; } #muutujad sätitud?
list="/usr/local/etc/isc-dhcp_192.168.4"
erand="/root/skriptid/WOL/erand.txt"
# kontrollime, kas erandid ja list olemas
[ ! -f $list ] && { echo "EXIT! List puudu asukohas: $list"; exit 1; }
[ ! -f $erand ] && { echo "EXIT! Erandid puudu asukohas: $erand"; exit 1; }
#jätkame
while read line
do
        IFS=' ' read -a array <<< "$line"
        mac=`echo ${array[5]}|sed 's/;//'`
        ip=`echo ${array[7]}|sed 's/;//'`
        host=`echo ${array[1]}`
        if grep -Fq "$ip" $erand
        then
                echo -e "Jatan vahele: HOST: $host IP: $ip MAC: $mac \n----" #exceptions
                sleep 1
        else
                echo -e "Lülitan välja: HOST: $host IP: $ip MAC: $mac \n----"
                net rpc SHUTDOWN -t 15 -f -C "Arvuti lulitub valja. Serveripoolne kask."     -W luunja -U $host\\xx%xx -S $ip
                sleep 1
        fi
done < $list

Cron job:

40      19      *       *       *     root    /root/skriptid/WOL/shutdown.sh

Both script are run by root and have 666 rights.

Is there a way to see cronjob's output besides log? Is there a known conflict between cronjob and net rpc?

Any help would be appreaciated!' thanks

Upvotes: 0

Views: 739

Answers (3)

nir
nir

Reputation: 1

You have to enable file sharing on windows computers in order for your script to work.

Upvotes: 0

Haroon Shakeel
Haroon Shakeel

Reputation: 1

Add paths to your crontab

PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin

Upvotes: 0

fedorqui
fedorqui

Reputation: 290225

You need to indicate the binary executing the script.

From

40 19 * * * root /root/skriptid/WOL/shutdown.sh

to

40 19 * * * root /bin/sh /root/skriptid/WOL/shutdown.sh

or whatever comes from which sh.

(I think I answer this question once a day)

Upvotes: 1

Related Questions