Showing posts with label Samba. Show all posts
Showing posts with label Samba. Show all posts

Wednesday, 13 July 2011

Shutdown a Windows machine from a Linux box

You can shutdown a windows box if you have samba installed.

Using:
net rpc SHUTDOWN -C "some comment here" -f -I x.x.x.x -U user_name%password
As long as the user you supplied has rights to shutdown the system it will work.

This bash script scans the network and turns off all systems that are left on over night.
#!/bin/bash
wks=(`nmap -sL --dns-servers 10.x.x.x,10.x.x.x 10.x.x.x/22, 10.x.x.x.x/23 grep FQDN|cut -d" " -f2 |grep -v -f serverlist`)
for (( i=0; i < "${#wks[@]}"; i++)); do
net rpc SHUTDOWN -C "This system was left on after hours and is being shutdown" -f -I "${wks[$i]}" -U user_name%password
done
Basically what the script does is scans the network(s) with nmap, pipes it though grep and cut to get the FQDN. Then "grep -v -f serverlist" is an exclude list of servers we don't want to shutdown. From there it puts the workstations into an array and turns off each system.

Possibly Related Posts