Here are some scripts that I wrote to mount and search bulk windows machines.
echo “Username please”
echo “Password please”
read -s password
for machine in `cat machinelist.txt`
echo “Attempting to mount $machine…”
mount.cifs //$machine/c$ ./remote$machine -o username=$username,password=$password
This next script searches the machines for NTUSER.DAT files to find users that were logged in during a specific time frame.
echo “Enter number of days for oldest file. (4 for no older than 4 days)”
echo “Enter number of days for newest file. (2 for at least 2 days old)”
find ./ -name NTUSER.DAT -mtime $new -mtime -$old -daystart
So you just kicked your roommate out and you need to change the username and password on 250 switches.
You can do it with a quick bash loop and pipe it into telnet. (ssh is way better, but isn’t enabled by default on most network devices)
Make a new file named credentials.txt and put the username on the first line and the password on the second.
Then make a new file named devicelist.txt and place the IP address or hostname of all of the switches in this file. (each on it’s own line)
username=`head -n 1 credentials.txt`
password=`tail -n 1 credentials.txt`
for device in `cat devicelist.txt`
echo open $device
echo ” “ (only required for devices with a banner before username prompt)
echo “command to execute on device”
echo “another command to execute on device”
) | telnet
If some of the devices have longer delays between prompts you can adjust the sleep values. (telnet isn’t smart enough to know when the device is ready for a command)
This script will obviously need to be modified depending on the device you’re connecting to. It will get all of those passwords changed automatically for you. You should be using a RADIUS or TACACS+ server for authentication with that many switches. 🙂
It does work well to invoke backups to tftp servers, etc.