Here is a quick command to disable your monitor in Linux.
xset dpms force off
You can bind this to a keyboard shortcut or throw it in a script to quickly send your monitors to power-save mode without waiting a timeout period.
Oct 20 2009
Turn off monitor in Linux
Aug 05 2009
Scripts to Mount and search windows machines
Here are some scripts that I wrote to mount and search bulk windows machines.
mountmachines.sh
#!/bin/bash
cd /searchmachines
echo “Username please”
read username
echo “Password please”
read -s password
for machine in `cat machinelist.txt`
do
mkdir remote$machine
echo “Attempting to mount $machine…”
mount.cifs //$machine/c$ ./remote$machine -o username=$username,password=$password
done
exit
This next script searches the machines for NTUSER.DAT files to find users that were logged in during a specific time frame.
search.sh
#!/bin/bash
cd /searchmachines
echo “Enter number of days for oldest file. (4 for no older than 4 days)”
read old
echo “Enter number of days for newest file. (2 for at least 2 days old)”
read new
echo “Searching…”
find ./ -name NTUSER.DAT -mtime $new -mtime -$old -daystart
Aug 02 2009
Script for a DHCP address renewal
Normally my Internet connection is pretty good; but, once every couple of months, the provider changes something and my current IP address no longer works. The lease doesn’t actually expire, which is set to last 48 hours. So, I lose internet connectivity until a new renewal. It’s easy to do this by hand, but that doesn’t work when I’m not at home.
This is a script that checks to see if I’m connected to the Internet, and if it fails three times in a row, it connects to the router (pfSense in this case) and performs a DHCP release and renew.
#!/bin/bash
#change to some writeable directory
cd /home/user
#check various sites
curl http://www.msn.com > internetchecksites
curl http://www.yahoo.com >> internetchecksites
curl http://www.google.com >> internetchecksites
curl http://www.cnn.com >> internetchecksites
curl http://www.cisco.com >> internetchecksites
curl http://www.hp.com >> internetchecksites
#count the number of lines received over http
#should be tons of crap from one of these alone
sizeofsites=`cat internetchecksites | wc -l`
#check to see if there are less than ten lines of HTML
if [ $sizeofsites -lt 10 ]; then
#mark a failure to the failure file
echo “strike” >> failedchecks
else
#reset the failure count
rm failedchecks
touch failedchecks
fi
#if check has failed 3 times run the dhcp renewal process
if [ `cat failedchecks | wc -l` -ge 3 ]; then
curl -su admin:somepassword http://192.168.x.x/status_interfaces.php -d interface=”wan” -d submit=”Release” >> pf
curl -su admin:somepassword http://192.168.x.x/status_interfaces.php -d interface=”wan” -d submit=”Renew” >> pf
rm pf
fi
exit
Now just stick this script in your crontab for every 5 minutes or so.
~$ crontab -e
Add this line
*/5 * * * * /home/user/checkinternetscript.sh
The */5 is for every five minutes.
Make sure the script is executable with a nice chmod +x
The hardest part is determining what commands need to be sent to the HTTP interface on your router for a renewal.
This can be done by viewing the source code on the web page. It can also be done using a packet capture as well.
Make sure other users aren’t adding to your failedchecks file or they can cause a DHCP release/renew.
Jul 19 2009
Nice way to kill your unresponsive linux system
Sometimes when a Linux system is unresponsive it seems like your only option is to hold down the power button.
Follow these key combos for a less risky reboot.
Hold Down Alt + SysRq and press R (raw keyboard mode) S (syncs disks) E (terminates all processes) I (kills the stragglers) U (read-only remount file-systems) B (reboots)
Give it lots of time to Sync the Disks and do it one more time after killing the processes to play it safe.
There she be. Careful, it’s a lot of fun.
Reboot System Even If Utterly Broken
Jul 13 2009
Public Key Authentication with Putty
Hello,
Windows = Still Exists
Administration from Windows of Linux = Putty
Key-based authentication from Putty = Puttygen
Launch the key generator included with Putty called PuTTYgen.
Click Generate. Move the mouse around for some good ol random numbers.
Stick a passphrase on it if you’re feeling insecure about yourself.
Save the public key somewhere and save the private key somewhere too. (Both are required for a good time.)
Before you close the program, copy the prepared public key to the clipboard from the box in PuTTYgen that has been prepared for the authorized_keys file.
Open an ssh session to the machine you’re administering.
~$ cat >> ~./ssh/authorized_keys
Then paste your key in there, hit enter, and press CTRL-C.
Now create a new session in PuTTY.
Go to Connection > Data and put in your Auto-login username that you just appended the public key to.
Then go to Connection > SSH > Auth and put the path of your private key in the box.
Then go back up to Session. Put the address or host name of your machine in the Host Name box, stick a name in Saved Sessions and hit Save.
Now you can double-click on it for instant satisfaction of authentication.
Jul 12 2009
Mount stuff over ssh quickly with sshfs
This little program allows you to mount a folder on a remote system to a local folder using ssh.
Install sshfs.
$ sudo apt-get install sshfs
Use the following command to mount a folder.
$ sshfs user@remotehostname:/path/to/remote/folder /path/to/local/folder
You don’t even have to be root to mount.
You can speed the process up with key-based access.
Jul 08 2009
Bash Guessing Game
Here is a game that is worth your time. You even get to code it yourself.
Lolz. Needs a bash interpreter.
~$ nano guessinggame.sh
Paste this in there.
#!/bin/bash
echo “Please pick an integer between 1 and 10.”
read guess
number=0
while [ "$number" -le 1 ]
do
number=$RANDOM
let “number %= 11 ”
done
if [ $guess -eq $number ]
then
echo “You win!”
else
echo “You suck. The number was $number.”
fi
exit
Then make it executable.
~$ chmod +x guessinggame.sh
Now you have yourself a dandy.
Run it like so.
~$ ./guessinggame.sh
This game does not have any input validation. If you try to guess a letter or special character, you will get an error. Guessing out of the bounds of 1 to 10 will also greatly reduce your odds of winning.
Next Page »
